diff --git a/lib/canvas/cc/basic_lti_links.rb b/lib/canvas/cc/basic_lti_links.rb new file mode 100644 index 00000000000..cc2f72be1da --- /dev/null +++ b/lib/canvas/cc/basic_lti_links.rb @@ -0,0 +1,91 @@ +# +# 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 . +# +module Canvas::CC + module BasicLTILinks + def create_basic_lti_links + return nil unless @manifest.basic_ltis.length > 0 + + @manifest.basic_ltis.each do |ct| # These are content tags + + migration_id = CCHelper::create_key(ct) + + lti_file_name = "#{migration_id}.xml" + lti_path = File.join(@export_dir, lti_file_name) + lti_file = File.new(lti_path, 'w') + lti_doc = Builder::XmlMarkup.new(:target=>lti_file, :indent=>2) + lti_doc.instruct! + + lti_doc.cartridge_basiclti_link("xmlns" => "http://www.imsglobal.org/xsd/imslticc_v1p0", + "xmlns:blti" => 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', + "xmlns:lticm" => 'http://www.imsglobal.org/xsd/imslticm_v1p0', + "xmlns:lticp" => 'http://www.imsglobal.org/xsd/imslticp_v1p0', + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", + "xsi:schemaLocation"=> "http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd + http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd + http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd + http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd" + ) do |blti_node| + blti_node.tag! "blti:title", ct.title + if ct.url =~ %r{http://} + blti_node.launch_url ct.url + elsif ct.url =~ %r{https://} + blti_node.secure_launch_url ct.url + end + end + lti_file.close + + @resources.resource( + :identifier => migration_id, + "type" => CCHelper::BASIC_LTI + ) do |res| + res.file(:href=>lti_file_name) + end + end + + end + + def create_external_tools + return nil unless @course.context_external_tools.count > 0 + + lti_file = File.new(File.join(@canvas_resource_dir, CCHelper::EXTERNAL_TOOLS), 'w') + rel_path = File.join(CCHelper::COURSE_SETTINGS_DIR, CCHelper::EXTERNAL_TOOLS) + document = Builder::XmlMarkup.new(:target=>lti_file, :indent=>2) + document.instruct! + document.externalTools( + "xmlns" => CCHelper::CANVAS_NAMESPACE, + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", + "xsi:schemaLocation"=> "#{CCHelper::CANVAS_NAMESPACE} #{CCHelper::XSD_URI}" + ) do |et_node| + @course.context_external_tools.each do |tool| + migration_id = CCHelper.create_key(tool) + et_node.externalTool(:identifier=>migration_id) do |t_node| + t_node.title tool.name + t_node.description tool.description unless tool.description.blank? + t_node.url tool.url unless tool.url.blank? + t_node.domain tool.domain unless tool.domain.blank? + t_node.privacy_level tool.workflow_state + t_node.comment! "The Consumer Key and Shared Secret will need to be configured within Canvas" + end + end + end + + lti_file.close + rel_path + end + end +end \ No newline at end of file diff --git a/lib/canvas/cc/canvas_resource.rb b/lib/canvas/cc/canvas_resource.rb index 9af9207d1c7..46ae1138f84 100644 --- a/lib/canvas/cc/canvas_resource.rb +++ b/lib/canvas/cc/canvas_resource.rb @@ -45,6 +45,7 @@ module Canvas::CC resources << create_grading_standards resources << create_learning_outcomes resources << create_rubrics + resources << create_external_tools @resources.resource( :identifier => migration_id, diff --git a/lib/canvas/cc/cc_helper.rb b/lib/canvas/cc/cc_helper.rb index 26746124851..751ff8dda02 100644 --- a/lib/canvas/cc/cc_helper.rb +++ b/lib/canvas/cc/cc_helper.rb @@ -39,6 +39,7 @@ module CCHelper #WEB_LINK = "imswl_xmlv1p1" WEB_LINK = "imswl_xmlv1p0" WEBCONTENT = "webcontent" + BASIC_LTI = 'imsbasiclti_xmlv1p0' # substitution tokens OBJECT_TOKEN = "$CANVAS_OBJECT_REFERENCE$" @@ -60,6 +61,7 @@ module CCHelper MANIFEST = 'imsmanifest.xml' MODULE_META = "module_meta.xml" RUBRICS = "rubrics.xml" + EXTERNAL_TOOLS = "external_tools.xml" SYLLABUS = "syllabus.html" WEB_RESOURCES_FOLDER = 'web_resources' WIKI_FOLDER = 'wiki_content' diff --git a/lib/canvas/cc/manifest.rb b/lib/canvas/cc/manifest.rb index d361d18642f..8c13bddcf0c 100644 --- a/lib/canvas/cc/manifest.rb +++ b/lib/canvas/cc/manifest.rb @@ -19,13 +19,14 @@ module Canvas::CC class Manifest include CCHelper - attr_accessor :exporter, :weblinks + attr_accessor :exporter, :weblinks, :basic_ltis def initialize(exporter) @exporter = exporter @file = nil @document = nil @weblinks = [] + @basic_ltis = [] end def course diff --git a/lib/canvas/cc/organization.rb b/lib/canvas/cc/organization.rb index 5bd614ba40d..5aa2f59fa62 100644 --- a/lib/canvas/cc/organization.rb +++ b/lib/canvas/cc/organization.rb @@ -64,6 +64,10 @@ module Canvas::CC :url => ct.url} @manifest.weblinks << link attributes[:identifierref] = link[:migration_id] + elsif ct.content_type == 'ContextExternalTool' + attributes[:identifierref] = attributes[:identifier] + attributes[:identifier] = CCHelper.create_key(ct, "module_item") + @manifest.basic_ltis << ct end module_node.item(attributes) do |tag_node| tag_node.title ct.title diff --git a/lib/canvas/cc/qti/qti_generator.rb b/lib/canvas/cc/qti/qti_generator.rb index a97b7505cb8..4650971cbfa 100644 --- a/lib/canvas/cc/qti/qti_generator.rb +++ b/lib/canvas/cc/qti/qti_generator.rb @@ -194,7 +194,7 @@ module Canvas::CC :title => group['name'] ) do |section_node| section_node.selection_ordering do |so_node| - section_node.selection do |sel_node| + so_node.selection do |sel_node| if group[:assessment_question_bank_id] if bank = @course.assessment_question_banks.find(group[:assessment_question_bank_id]) sel_node.sourcebank_ref create_key(bank) diff --git a/lib/canvas/cc/qti/qti_items.rb b/lib/canvas/cc/qti/qti_items.rb index 36369a16e66..5a5a30ac047 100644 --- a/lib/canvas/cc/qti/qti_items.rb +++ b/lib/canvas/cc/qti/qti_items.rb @@ -250,7 +250,7 @@ module Canvas::CC def item_feedback(node, id, message) node.itemfeedback(:ident=>id) do |f_node| f_node.flow_mat do |flow_node| - f_node.material do |m_node| + flow_node.material do |m_node| m_node.mattext(message, :texttype=>'text') end end diff --git a/lib/canvas/cc/resource.rb b/lib/canvas/cc/resource.rb index f109fd01c52..232b41b4a35 100644 --- a/lib/canvas/cc/resource.rb +++ b/lib/canvas/cc/resource.rb @@ -24,6 +24,7 @@ module Canvas::CC include TopicResources include WebResources include WebLinks + include BasicLTILinks def initialize(manifest, manifest_node) @manifest = manifest @@ -49,8 +50,8 @@ module Canvas::CC add_web_links add_course_files QTI::QTIGenerator.generate_qti(@manifest, resources) + create_basic_lti_links #todo download kaltura videos? - #todo basic LTI links end end end diff --git a/lib/canvas/cc/xsd/cccv0p1.xsd b/lib/canvas/cc/xsd/cccv0p1.xsd index 604badd7e9a..a9ad17556e2 100644 --- a/lib/canvas/cc/xsd/cccv0p1.xsd +++ b/lib/canvas/cc/xsd/cccv0p1.xsd @@ -379,5 +379,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file