Class: Moodle2CC::Moodle2::Models::Quizzes::MultianswerQuestion

Inherits:
Question
  • Object
show all
Defined in:
lib/moodle2cc/moodle2/models/quizzes/multianswer_question.rb

Constant Summary

Constants inherited from Question

Question::STANDARD_TYPES

Instance Attribute Summary collapse

Attributes inherited from Question

#answers, #bank_entry_id, #default_mark, #general_feedback, #hidden, #id, #length, #max_mark, #name, #parent, #penalty, #qtype, #question_text, #question_text_format, #stamp, #type, #version

Instance Method Summary collapse

Methods inherited from Question

create, register_question_type

Constructor Details

#initializeMultianswerQuestion

Returns a new instance of MultianswerQuestion.



6
7
8
9
# File 'lib/moodle2cc/moodle2/models/quizzes/multianswer_question.rb', line 6

def initialize
  super
  @embedded_questions = []
end

Instance Attribute Details

#embedded_question_referencesObject

Returns the value of attribute embedded_question_references.



4
5
6
# File 'lib/moodle2cc/moodle2/models/quizzes/multianswer_question.rb', line 4

def embedded_question_references
  @embedded_question_references
end

#embedded_questionsObject

Returns the value of attribute embedded_questions.



4
5
6
# File 'lib/moodle2cc/moodle2/models/quizzes/multianswer_question.rb', line 4

def embedded_questions
  @embedded_questions
end

Instance Method Details

#resolve_embedded_question_references(question_categories) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/moodle2cc/moodle2/models/quizzes/multianswer_question.rb', line 11

def resolve_embedded_question_references(question_categories)
  return unless @embedded_question_references

  @embedded_questions ||= []
  @embedded_question_references.each do |ref|
    question = nil
    question_categories.each do |qc|
      if question = qc.questions.detect{|q| q.id.to_s == ref && q.parent.to_s == @id}
        qc.questions.delete(question)
        break
      end
    end

    @embedded_questions << question if question
  end
end