Class: Moodle2CC::Canvas::Assessment
Constant Summary
collapse
- META_ATTRIBUTES =
[:title, :description, :lock_at, :unlock_at, :allowed_attempts,
:scoring_policy, :access_code, :ip_filter, :shuffle_answers, :time_limit, :quiz_type]
Moodle2CC::CC::CCHelper::ASSESSMENT_CC_QTI, Moodle2CC::CC::CCHelper::ASSESSMENT_META, Moodle2CC::CC::CCHelper::ASSESSMENT_NON_CC_FOLDER, Moodle2CC::CC::CCHelper::ASSESSMENT_TYPE, Moodle2CC::CC::CCHelper::ASSIGNMENT_GROUPS, Moodle2CC::CC::CCHelper::ASSIGNMENT_SETTINGS, Moodle2CC::CC::CCHelper::BASIC_LTI, Moodle2CC::CC::CCHelper::BLTI_NAMESPACE, Moodle2CC::CC::CCHelper::CANVAS_NAMESPACE, Moodle2CC::CC::CCHelper::CANVAS_PLATFORM, Moodle2CC::CC::CCHelper::CC_ASSIGNMENT_FOLDER, Moodle2CC::CC::CCHelper::CC_EXTENSION, Moodle2CC::CC::CCHelper::CC_WIKI_FOLDER, Moodle2CC::CC::CCHelper::COURSE_SETTINGS, Moodle2CC::CC::CCHelper::COURSE_SETTINGS_DIR, Moodle2CC::CC::CCHelper::COURSE_TOKEN, Moodle2CC::CC::CCHelper::DISCUSSION_TOPIC, Moodle2CC::CC::CCHelper::EVENTS, Moodle2CC::CC::CCHelper::EXTERNAL_FEEDS, Moodle2CC::CC::CCHelper::EXTERNAL_TOOLS, Moodle2CC::CC::CCHelper::FILES_META, Moodle2CC::CC::CCHelper::GRADING_STANDARDS, Moodle2CC::CC::CCHelper::IMS_DATE, Moodle2CC::CC::CCHelper::IMS_DATETIME, Moodle2CC::CC::CCHelper::LEARNING_OUTCOMES, Moodle2CC::CC::CCHelper::LOR, Moodle2CC::CC::CCHelper::MANIFEST, Moodle2CC::CC::CCHelper::MEDIA_OBJECTS_FOLDER, Moodle2CC::CC::CCHelper::MODULE_META, Moodle2CC::CC::CCHelper::MOODLE_FILEBASE_TOKEN, Moodle2CC::CC::CCHelper::MOODLE_SLASH_TOKEN, Moodle2CC::CC::CCHelper::OBJECT_TOKEN, Moodle2CC::CC::CCHelper::QTI_ASSESSMENT_TYPE, Moodle2CC::CC::CCHelper::QTI_EXTENSION, Moodle2CC::CC::CCHelper::QUESTION_BANK, Moodle2CC::CC::CCHelper::RUBRICS, Moodle2CC::CC::CCHelper::SYLLABUS, Moodle2CC::CC::CCHelper::WEBCONTENT, Moodle2CC::CC::CCHelper::WEB_CONTENT_TOKEN, Moodle2CC::CC::CCHelper::WEB_LINK, Moodle2CC::CC::CCHelper::WEB_RESOURCES_FOLDER, Moodle2CC::CC::CCHelper::WIKI_FOLDER, Moodle2CC::CC::CCHelper::WIKI_TOKEN, Moodle2CC::CC::CCHelper::XSD_URI
Instance Method Summary
collapse
Methods included from Resource
#create_module_meta_item_node
#create_organization_item_node, included
#convert_file_path_tokens, convert_file_path_tokens, #create_key, create_key, create_mod_key, #create_mod_key, #create_resource_key, create_resource_key, file_query_string, #file_slug, file_slug, #get_html_title_and_body, #get_html_title_and_body_and_id, #get_html_title_and_body_and_meta_fields, ims_date, #ims_date, ims_datetime, #ims_datetime, media_object_info
Constructor Details
#initialize(mod, position = 0) ⇒ Assessment
Returns a new instance of Assessment.
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
39
40
41
42
43
|
# File 'lib/moodle2cc/canvas/assessment.rb', line 9
def initialize(mod, position=0)
super
description = [mod.intro, mod.content, mod.text, mod.summary].compact.reject { |d| d.length == 0 }.first || ''
@description = convert_file_path_tokens(description)
if mod.time_close.to_i > 0
@lock_at = ims_datetime(Time.at(mod.time_close))
end
if mod.time_open.to_i > 0
@unlock_at = ims_datetime(Time.at(mod.time_open))
end
@time_limit = mod.time_limit
@allowed_attempts = mod.attempts_number
@scoring_policy = mod.grade_method == 4 ? 'keep_latest' : 'keep_highest'
@access_code = mod.password
@ip_filter = mod.subnet
@shuffle_answers = mod.shuffle_answers
@quiz_type = 'survey' unless mod.mod_type == 'quiz'
@non_cc_assessments_identifier = create_key(@id, 'non_cc_assessments_')
@questions = []
mod.questions.each do |question|
if question.type == 'random'
question_bank = QuestionBank.new question.question_category
last = @questions.last
if last && last.is_a?(QuestionGroup) && last.points_per_item == question.grade && last.sourcebank_ref == question_bank.identifier
last.increment_selection_number
else
group = @questions.select { |q| q.is_a?(QuestionGroup) }.last
id = group ? group.id + 1 : 1
@questions << QuestionGroup.new(:id => id, :question_bank => question_bank, :points_per_item => question.grade)
end
else
@questions << Question.new(question, self)
end
end
end
|
Instance Method Details
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/moodle2cc/canvas/assessment.rb', line 68
def create_assessment_meta_xml(export_dir)
path = File.join(export_dir, identifier, ASSESSMENT_META)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') do |file|
node = Builder::XmlMarkup.new(:target => file, :indent => 2)
node.instruct!
node.quiz(
:identifier => identifier,
'xsi:schemaLocation' => "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd",
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
'xmlns' => "http://canvas.instructure.com/xsd/cccv1p0"
) do |quiz_node|
META_ATTRIBUTES.each do |attr|
quiz_node.tag!(attr, send(attr)) unless send(attr).nil?
end
end
end
end
|
#create_files(export_dir) ⇒ Object
63
64
65
66
|
# File 'lib/moodle2cc/canvas/assessment.rb', line 63
def create_files(export_dir)
create_assessment_meta_xml(export_dir)
create_non_cc_qti_xml(export_dir)
end
|
119
120
121
122
|
# File 'lib/moodle2cc/canvas/assessment.rb', line 119
def create_module_meta_item_elements(item_node)
item_node.content_type 'Quiz'
item_node.identifierref @identifier
end
|
#create_non_cc_qti_xml(export_dir) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/moodle2cc/canvas/assessment.rb', line 87
def create_non_cc_qti_xml(export_dir)
path = File.join(export_dir, ASSESSMENT_NON_CC_FOLDER, "#{identifier}.xml.qti")
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') do |file|
node = Builder::XmlMarkup.new(:target => file, :indent => 2)
node.instruct!
node.questestinterop(
'xsi:schemaLocation' => "http://www.imsglobal.org/xsd/ims_qtiasiv1p2 http://www.imsglobal.org/xsd/ims_qtiasiv1p2p1.xsd",
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
'xmlns' => "http://www.imsglobal.org/xsd/ims_qtiasiv1p2"
) do |root_node|
root_node.assessment(:title => title, :ident => identifier) do |assessment_node|
assessment_node.qtimetadata do |qtimetadata_node|
qtimetadata_node.qtimetadatafield do |qtimetadatafield_node|
qtimetadatafield_node.fieldlabel "qmd_timelimit"
qtimetadatafield_node.fieldentry time_limit
end
qtimetadata_node.qtimetadatafield do |qtimetadatafield_node|
qtimetadatafield_node.fieldlabel "cc_maxattempts"
qtimetadatafield_node.fieldentry allowed_attempts
end
end
assessment_node.section(:ident => 'root_section') do |section_node|
@questions.each do |question|
question.create_item_xml(section_node)
end
end
end
end
end
end
|
#create_resource_node(resources_node) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/moodle2cc/canvas/assessment.rb', line 45
def create_resource_node(resources_node)
super
href = File.join(identifier, ASSESSMENT_META)
resources_node.resource(
:href => href,
:type => LOR,
:identifier => non_cc_assessments_identifier
) do |resource_node|
resource_node.file(:href => href)
resource_node.file(:href => File.join(ASSESSMENT_NON_CC_FOLDER, "#{identifier}.xml.qti"))
end
end
|
#create_resource_sub_nodes(resource_node) ⇒ Object
59
60
61
|
# File 'lib/moodle2cc/canvas/assessment.rb', line 59
def create_resource_sub_nodes(resource_node)
resource_node.dependency :identifierref => non_cc_assessments_identifier
end
|