2011-03-23 03:54:36 +08:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
2011-04-08 03:25:41 +08:00
|
|
|
module CC
|
2011-03-23 03:54:36 +08:00
|
|
|
module LearningOutcomes
|
2011-04-13 04:29:49 +08:00
|
|
|
def create_learning_outcomes(document=nil)
|
2011-03-23 03:54:36 +08:00
|
|
|
return nil unless LearningOutcome.active.find_all_by_context_id_and_context_type(@course.id, 'Course').count > 0
|
|
|
|
return nil unless @course.learning_outcome_groups.find_by_learning_outcome_group_id(nil)
|
|
|
|
|
|
|
|
root_group = @course.learning_outcome_groups.find_by_learning_outcome_group_id(nil)
|
2011-04-13 04:29:49 +08:00
|
|
|
|
|
|
|
if document
|
|
|
|
outcomes_file = nil
|
|
|
|
rel_path = nil
|
|
|
|
else
|
|
|
|
outcomes_file = File.new(File.join(@canvas_resource_dir, CCHelper::LEARNING_OUTCOMES), 'w')
|
|
|
|
rel_path = File.join(CCHelper::COURSE_SETTINGS_DIR, CCHelper::LEARNING_OUTCOMES)
|
|
|
|
document = Builder::XmlMarkup.new(:target=>outcomes_file, :indent=>2)
|
|
|
|
end
|
2011-03-23 03:54:36 +08:00
|
|
|
|
|
|
|
document.instruct!
|
|
|
|
document.learningOutcomes(
|
|
|
|
"xmlns" => CCHelper::CANVAS_NAMESPACE,
|
|
|
|
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
|
|
|
|
"xsi:schemaLocation"=> "#{CCHelper::CANVAS_NAMESPACE} #{CCHelper::XSD_URI}"
|
|
|
|
) do |outs_node|
|
|
|
|
process_outcome_group_content(outs_node, root_group)
|
|
|
|
end
|
|
|
|
|
2011-04-13 04:29:49 +08:00
|
|
|
outcomes_file.close if outcomes_file
|
2011-03-23 03:54:36 +08:00
|
|
|
rel_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_outcome_group(node, group)
|
|
|
|
migration_id = CCHelper.create_key(group)
|
|
|
|
node.learningOutcomeGroup(:identifier=>migration_id) do |group_node|
|
|
|
|
group_node.title group.title unless group.title.blank?
|
|
|
|
group_node.description CCHelper.html_content(group.description, @course, @manifest.exporter.user) unless group.description.blank?
|
|
|
|
group_node.learningOutcomes do |lo_node|
|
|
|
|
process_outcome_group_content(lo_node, group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_outcome_group_content(node, group)
|
|
|
|
group.sorted_content.each do |item|
|
|
|
|
if item.is_a? LearningOutcome
|
|
|
|
process_learning_outcome(node, item)
|
|
|
|
else
|
|
|
|
process_outcome_group(node, item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_learning_outcome(node, item)
|
|
|
|
migration_id = CCHelper.create_key(item)
|
|
|
|
node.learningOutcome(:identifier=>migration_id) do |out_node|
|
|
|
|
out_node.title item.short_description unless item.short_description.blank?
|
|
|
|
out_node.description CCHelper.html_content(item.description, @course, @manifest.exporter.user) unless item.description.blank?
|
|
|
|
criterion = item.data[:rubric_criterion]
|
|
|
|
if criterion
|
|
|
|
out_node.points_possible criterion[:points_possible] if criterion[:points_possible]
|
|
|
|
out_node.mastery_points criterion[:mastery_points] if criterion[:mastery_points]
|
|
|
|
if criterion[:ratings] && criterion[:ratings].length > 0
|
|
|
|
out_node.ratings do |ratings_node|
|
|
|
|
criterion[:ratings].each do |rating|
|
2011-03-23 07:02:12 +08:00
|
|
|
ratings_node.rating do |rating_node|
|
2011-03-23 03:54:36 +08:00
|
|
|
rating_node.description rating[:description]
|
|
|
|
rating_node.points rating[:points]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|