2011-04-27 02:18:03 +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/>.
|
|
|
|
#
|
|
|
|
module CC
|
|
|
|
module Events
|
|
|
|
def create_events(document=nil)
|
2012-05-29 23:44:03 +08:00
|
|
|
return nil unless @course.calendar_events.active.count > 0
|
2011-04-27 02:18:03 +08:00
|
|
|
|
|
|
|
if document
|
|
|
|
events_file = nil
|
|
|
|
rel_path = nil
|
|
|
|
else
|
|
|
|
events_file = File.new(File.join(@canvas_resource_dir, CCHelper::EVENTS), 'w')
|
|
|
|
rel_path = File.join(CCHelper::COURSE_SETTINGS_DIR, CCHelper::EVENTS)
|
|
|
|
document = Builder::XmlMarkup.new(:target=>events_file, :indent=>2)
|
|
|
|
end
|
|
|
|
|
|
|
|
document.instruct!
|
|
|
|
document.events(
|
|
|
|
"xmlns" => CCHelper::CANVAS_NAMESPACE,
|
|
|
|
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
|
|
|
|
"xsi:schemaLocation"=> "#{CCHelper::CANVAS_NAMESPACE} #{CCHelper::XSD_URI}"
|
|
|
|
) do |events_node|
|
2012-05-29 23:44:03 +08:00
|
|
|
@course.calendar_events.active.each do |event|
|
2012-03-26 04:23:05 +08:00
|
|
|
next unless export_object?(event)
|
2011-04-27 02:18:03 +08:00
|
|
|
migration_id = CCHelper.create_key(event)
|
|
|
|
events_node.event(:identifier=>migration_id) do |event_node|
|
|
|
|
event_node.title event.title unless event.title.blank?
|
2011-10-04 23:03:19 +08:00
|
|
|
event_node.description @html_exporter.html_content(event.description)
|
2011-04-27 02:18:03 +08:00
|
|
|
event_node.start_at ims_datetime(event.start_at) if event.start_at
|
|
|
|
event_node.end_at ims_datetime(event.end_at) if event.end_at
|
|
|
|
if event.all_day
|
|
|
|
event_node.all_day 'true'
|
|
|
|
event_node.all_day_date ims_date(event.all_day_date) if event.all_day_date
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
events_file.close if events_file
|
|
|
|
rel_path
|
|
|
|
end
|
|
|
|
end
|
2011-04-28 05:21:54 +08:00
|
|
|
end
|