Class: Moodle2CC::Moodle2Converter::QuestionBankConverter

Inherits:
Object
  • Object
show all
Includes:
ConverterHelper
Defined in:
lib/moodle2cc/moodle2converter/question_bank_converter.rb

Constant Summary

Constants included from ConverterHelper

ConverterHelper::ACTIVITY_LOOKUP, ConverterHelper::ASSESSMENT_SUFFIX, ConverterHelper::ASSIGNMENT_SUFFIX, ConverterHelper::CHAPTER_SUFFIX, ConverterHelper::CHOICE_ASSESSMENT_SUFFIX, ConverterHelper::COURSE_SUFFIX, ConverterHelper::DISCUSSION_SUFFIX, ConverterHelper::EXTERNAL_URL_SUFFIX, ConverterHelper::FEEDBACK_ASSESSMENT_SUFFIX, ConverterHelper::FILE_SUFFIX, ConverterHelper::FOLDER_SUFFIX, ConverterHelper::GLOSSARY_SUFFIX, ConverterHelper::INTRO_SUFFIX, ConverterHelper::LTI_SUFFIX, ConverterHelper::MAX_TITLE_LENGTH, ConverterHelper::MODULE_SUFFIX, ConverterHelper::PAGE_SUFFIX, ConverterHelper::QUESTIONNAIRE_ASSESSMENT_SUFFIX, ConverterHelper::QUESTION_BANK_SUFFIX, ConverterHelper::SUMMARY_PAGE_SUFFIX

Instance Method Summary collapse

Methods included from ConverterHelper

#activity_content_type, #generate_unique_identifier, #generate_unique_identifier_for, #generate_unique_identifier_for_activity, #generate_unique_resource_path, #get_unique_identifier_for_activity, #truncate_text, #workflow_state

Instance Method Details

#convert(moodle_category) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/moodle2cc/moodle2converter/question_bank_converter.rb', line 5

def convert(moodle_category)
  canvas_bank = Moodle2CC::CanvasCC::Models::QuestionBank.new

  canvas_bank.identifier = generate_unique_identifier_for(moodle_category.id, QUESTION_BANK_SUFFIX)
  canvas_bank.title = truncate_text(moodle_category.name)

  canvas_bank.original_id = moodle_category.id
  canvas_bank.parent_id = moodle_category.parent

  question_converter = Moodle2CC::Moodle2Converter::QuestionConverters::QuestionConverter.new
  moodle_category.questions.each do |moodle_question|
    if moodle_question.type == 'random'
      # collect the question ids of random questions that belong to this bank
      canvas_bank.random_question_references << moodle_question.id
      next
    end

    item = question_converter.convert(moodle_question)
    case item
    when Moodle2CC::CanvasCC::Models::Question
      canvas_bank.questions << item
    when Moodle2CC::CanvasCC::Models::QuestionGroup
      canvas_bank.question_groups << item
    end
  end

  canvas_bank.question_groups.each do |question_group|
    if question_group.group_type == 'random_short_answer'
      question_group.questions = canvas_bank.questions.select{|q| q.question_type == 'short_answer_question'}
    end
  end

  canvas_bank
end