Module: Moodle2CC::Moodle2Converter::FeedbackConverter

Includes:
ConverterHelper
Included in:
AssessmentConverter
Defined in:
lib/moodle2cc/moodle2converter/feedback_converter.rb

Constant Summary collapse

QUESTION_TYPE_MAP =
{
  'label' => 'text_only_question',
  'textarea' => 'essay_question',
  'multichoice' => 'multiple_choice_question',
  'multichoicerated' => 'multiple_choice_question',
  'numeric' => 'numerical_question',
  'textfield' => 'short_answer_question'
}

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_feedback(moodle_feedback) ⇒ 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
# File 'lib/moodle2cc/moodle2converter/feedback_converter.rb', line 5

def convert_feedback(moodle_feedback)
  canvas_assessment = Moodle2CC::CanvasCC::Models::Assessment.new
  canvas_assessment.identifier = generate_unique_identifier_for_activity(moodle_feedback)
  canvas_assessment.title = truncate_text(moodle_feedback.name)
  canvas_assessment.description = moodle_feedback.intro
  canvas_assessment.workflow_state = workflow_state(moodle_feedback.visible)

  canvas_assessment.lock_at = Time.at(Integer(moodle_feedback.time_close)) if moodle_feedback.time_close
  canvas_assessment.unlock_at = Time.at(Integer(moodle_feedback.time_open)) if moodle_feedback.time_open

  canvas_assessment.scoring_policy = 'keep_latest'
  canvas_assessment.quiz_type = 'survey'

  canvas_assessment.allowed_attempts = -1 if moodle_feedback.multiple_submit

  canvas_assessment.items = []
  moodle_feedback.items.each do |item|
    if canvas_question = convert_feedback_question(item)
      canvas_assessment.items << canvas_question
    end
  end

  canvas_assessment
end

#convert_feedback_question(moodle_question) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/moodle2cc/moodle2converter/feedback_converter.rb', line 39

def convert_feedback_question(moodle_question)
  return unless canvas_type = QUESTION_TYPE_MAP[moodle_question.type]

  canvas_question = Moodle2CC::CanvasCC::Models::Question.create(canvas_type)
  canvas_question.identifier = generate_unique_identifier_for(moodle_question.id, "_feedback_question")
  if moodle_question.type == 'label'
    canvas_question.title = truncate_text(moodle_question.name)
    canvas_question.material = moodle_question.presentation
  else
    canvas_question.title = truncate_text(moodle_question.label)
    canvas_question.material = moodle_question.name
  end

  if ['multichoice', 'multichoicerated'].include?(moodle_question.type)
    choices = moodle_question.presentation.to_s.sub('r>>>>>', '').split("\\n").map do |c|
      c = c.strip
      c = c.sub('|', '') if c.start_with?('|')
      if moodle_question.type == 'multichoicerated' && c =~ /(\d+)\#\#\#\#(.*)/
        c = "[#{$1}] #{$2}"
      end
      c
    end

    choices.each_with_index do |choice, num|
      answer = Moodle2CC::CanvasCC::Models::Answer.new
      answer.id = generate_unique_identifier_for(moodle_question.id, "_answer#{num + 1}")
      answer.answer_text = choice
      canvas_question.answers << answer
    end
  end
  canvas_question
end