2020-10-27 00:50:13 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-04-16 10:48:44 +08:00
|
|
|
#
|
2017-04-28 04:01:09 +08:00
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
2011-04-16 10:48:44 +08:00
|
|
|
#
|
|
|
|
# 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-09-13 04:37:23 +08:00
|
|
|
module CC::Importer::Canvas
|
2011-04-16 10:48:44 +08:00
|
|
|
module TopicConverter
|
|
|
|
include CC::Importer
|
2016-07-11 21:20:44 +08:00
|
|
|
|
|
|
|
def convert_topics_and_announcements
|
2011-04-16 10:48:44 +08:00
|
|
|
topics = []
|
2016-07-11 21:20:44 +08:00
|
|
|
announcements = []
|
|
|
|
|
2011-04-16 10:48:44 +08:00
|
|
|
@manifest.css("resource[type=imsdt_xmlv1p1]").each do |res|
|
2017-11-10 05:33:32 +08:00
|
|
|
cc_path = @package_root.item_path res.at_css("file")["href"]
|
2012-06-05 03:16:26 +08:00
|
|
|
cc_id = res["identifier"]
|
|
|
|
canvas_id = get_node_att(res, "dependency", "identifierref")
|
2021-09-29 08:07:43 +08:00
|
|
|
if canvas_id && (meta_res = @manifest.at_css(%(resource[identifier="#{canvas_id}"])))
|
2017-11-10 05:33:32 +08:00
|
|
|
canvas_path = @package_root.item_path meta_res.at_css("file")["href"]
|
2012-06-05 03:16:26 +08:00
|
|
|
meta_node = open_file_xml(canvas_path)
|
|
|
|
else
|
|
|
|
meta_node = nil
|
|
|
|
end
|
2011-04-16 10:48:44 +08:00
|
|
|
cc_doc = open_file_xml(cc_path)
|
2012-06-05 03:16:26 +08:00
|
|
|
|
2016-07-11 21:20:44 +08:00
|
|
|
topic = convert_topic(cc_doc, meta_node, canvas_id || cc_id)
|
|
|
|
if topic["type"] == "announcement"
|
|
|
|
announcements << topic
|
|
|
|
else
|
|
|
|
topics << topic
|
|
|
|
end
|
2011-04-16 10:48:44 +08:00
|
|
|
end
|
2016-07-11 21:20:44 +08:00
|
|
|
|
|
|
|
[topics, announcements]
|
2011-04-16 10:48:44 +08:00
|
|
|
end
|
2016-07-11 21:20:44 +08:00
|
|
|
|
2012-06-05 03:16:26 +08:00
|
|
|
def convert_topic(cc_doc, meta_doc, mig_id = nil)
|
2011-04-16 10:48:44 +08:00
|
|
|
topic = {}
|
|
|
|
topic["description"] = get_node_val(cc_doc, "text")
|
2012-06-05 03:16:26 +08:00
|
|
|
topic["title"] = get_node_val(cc_doc, "title")
|
|
|
|
topic["migration_id"] = mig_id
|
|
|
|
if meta_doc
|
|
|
|
topic["migration_id"] = get_node_val(meta_doc, "topic_id")
|
|
|
|
topic["title"] = get_node_val(meta_doc, "title")
|
|
|
|
topic["type"] = get_node_val(meta_doc, "type")
|
2013-04-29 23:48:02 +08:00
|
|
|
topic["discussion_type"] = get_node_val(meta_doc, "discussion_type")
|
2013-07-20 12:01:08 +08:00
|
|
|
topic["pinned"] = get_bool_val(meta_doc, "pinned")
|
2013-08-24 05:08:00 +08:00
|
|
|
topic["require_initial_post"] = get_bool_val(meta_doc, "require_initial_post")
|
2012-06-05 03:16:26 +08:00
|
|
|
topic["external_feed_migration_id"] = get_node_val(meta_doc, "external_feed_identifierref")
|
|
|
|
topic["attachment_migration_id"] = get_node_val(meta_doc, "attachment_identifierref")
|
|
|
|
topic["posted_at"] = get_time_val(meta_doc, "posted_at")
|
|
|
|
topic["delayed_post_at"] = get_time_val(meta_doc, "delayed_post_at")
|
2015-03-05 22:59:14 +08:00
|
|
|
topic["lock_at"] = get_time_val(meta_doc, "lock_at")
|
2012-06-05 03:16:26 +08:00
|
|
|
topic["position"] = get_int_val(meta_doc, "position")
|
2014-07-21 20:17:01 +08:00
|
|
|
wf_state = get_node_val(meta_doc, "workflow_state")
|
|
|
|
topic["workflow_state"] = wf_state if wf_state.present?
|
2016-05-20 04:52:09 +08:00
|
|
|
topic["group_category"] = get_node_val(meta_doc, "group_category")
|
2017-06-09 07:28:35 +08:00
|
|
|
topic["todo_date"] = get_time_val(meta_doc, "todo_date")
|
2022-07-19 21:44:47 +08:00
|
|
|
%w[has_group_category allow_rating only_graders_can_rate sort_by_rating locked is_anonymous_author].each do |setting|
|
2016-03-25 22:43:59 +08:00
|
|
|
get_bool_val(meta_doc, setting).tap { |val| topic[setting] = val unless val.nil? }
|
|
|
|
end
|
2021-09-29 08:07:43 +08:00
|
|
|
if (asmnt_node = meta_doc.at_css("assignment"))
|
2014-06-02 23:59:13 +08:00
|
|
|
topic["assignment"] = parse_canvas_assignment_data(asmnt_node)
|
2012-06-05 03:16:26 +08:00
|
|
|
end
|
2022-07-19 21:44:47 +08:00
|
|
|
topic["anonymous_state"] = get_node_val(meta_doc, "anonymous_state")
|
2024-08-27 20:29:14 +08:00
|
|
|
if @is_discussion_checkpoints_enabled && (val = get_int_val(meta_doc, "reply_to_entry_required_count"))
|
|
|
|
topic["reply_to_entry_required_count"] = val
|
|
|
|
end
|
2011-04-16 10:48:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
topic
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|