forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrubrics.rb
More file actions
117 lines (104 loc) · 4.43 KB
/
Copy pathrubrics.rb
File metadata and controls
117 lines (104 loc) · 4.43 KB
1
2
3
4
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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module CC
module Rubrics
def create_rubrics(document=nil)
return nil unless @course.rubric_associations.count > 0
# There can be multiple rubric associations to the same rubric, only export each rubric once
imported_rubrics = {}
if document
rubrics_file = nil
rel_path = nil
else
rubrics_file = File.new(File.join(@canvas_resource_dir, CCHelper::RUBRICS), 'w')
rel_path = File.join(CCHelper::COURSE_SETTINGS_DIR, CCHelper::RUBRICS)
document = Builder::XmlMarkup.new(:target=>rubrics_file, :indent=>2)
end
document.instruct!
document.rubrics(
"xmlns" => CCHelper::CANVAS_NAMESPACE,
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation"=> "#{CCHelper::CANVAS_NAMESPACE} #{CCHelper::XSD_URI}"
) do |rubrics_node|
@course.rubric_associations.each do |assoc|
rubric = assoc.rubric
next if rubric.nil? || !rubric.active? || imported_rubrics[rubric.id]
if !export_object?(rubric)
next if assoc.association_type != "Assignment"
assignment = assoc.association_object
next unless [assignment, assignment.quiz, assignment.discussion_topic, assignment.wiki_page].compact.any?{|o| export_object?(o)}
end
imported_rubrics[rubric.id] = true
rubric.learning_outcome_alignments.each do |align|
add_item_to_export(align.learning_outcome, 'learning_outcomes')
end
add_exported_asset(rubric)
migration_id = create_key(rubric)
rubrics_node.rubric(:identifier=>migration_id) do |r_node|
atts = [:read_only, :title, :reusable, :public, :points_possible,
:hide_score_total, :free_form_criterion_comments]
if rubric.context != @course
r_node.external_identifier rubric.id
end
atts.each do |att|
r_node.tag!(att, rubric.send(att)) if rubric.send(att) == false || !rubric.send(att).blank?
end
r_node.description rubric.description if rubric.description
r_node.criteria do |c_node|
if rubric.data && rubric.data.length > 0
rubric.data.each do |crit|
add_criterion(c_node, crit)
end
end
end
end
end
end
rubrics_file.close if rubrics_file
rel_path
end
def add_criterion(node, criterion)
node.criterion do |c_node|
c_node.criterion_id criterion[:id]
c_node.points criterion[:points]
c_node.mastery_points criterion[:mastery_points] if criterion[:mastery_points]
c_node.ignore_for_scoring criterion[:ignore_for_scoring] unless criterion[:ignore_for_scoring].nil?
c_node.description criterion[:description]
c_node.long_description criterion[:long_description] unless criterion[:long_description].blank?
if criterion[:learning_outcome_id].present?
if lo = @course.available_outcome(criterion[:learning_outcome_id])
c_node.learning_outcome_identifierref create_key(lo)
end
end
if criterion[:ratings] && criterion[:ratings].length > 0
c_node.ratings do |ratings_node|
criterion[:ratings].each do |rating|
ratings_node.rating do |rating_node|
rating_node.description rating[:description]
rating_node.points rating[:points]
rating_node.criterion_id rating[:criterion_id]
rating_node.long_description rating[:long_description] unless rating[:long_description].blank?
rating_node.tag! :id, rating[:id]
end
end
end
end
end
end
end
end