canvas-lms/lib/cc/events.rb

58 lines
2.2 KiB
Ruby
Raw Normal View History

#
# 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)
return nil unless @course.calendar_events.count > 0
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|
@course.calendar_events.each do |event|
migration_id = CCHelper.create_key(event)
events_node.event(:identifier=>migration_id) do |event_node|
event_node.title event.title unless event.title.blank?
event_node.description @html_exporter.html_content(event.description, @course, @manifest.exporter.user)
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
end