@@ -37,23 +37,67 @@ def add_assignments
3737 end
3838 end
3939
40+ VERSION_1_3 = Gem ::Version . new ( '1.3' )
41+
4042 def add_assignment ( assignment )
4143 migration_id = CCHelper . create_key ( assignment )
4244
4345 lo_folder = File . join ( @export_dir , migration_id )
4446 FileUtils ::mkdir_p lo_folder
4547
4648 file_name = "#{ assignment . title . to_url } .html"
47- relative_path = File . join ( migration_id , file_name )
4849 path = File . join ( lo_folder , file_name )
50+ html_path = File . join ( migration_id , file_name )
4951
5052 # Write the assignment description as an .html file
51- # That way at least the content of the assignment will
52- # appear when someone non-canvas imports the package
53+ # That way at least the content of the assignment will appear
54+ # for agents that support neither CC 1.3 nor Canvas assignments
5355 File . open ( path , 'w' ) do |file |
5456 file << @html_exporter . html_page ( assignment . description || '' , "Assignment: " + assignment . title )
5557 end
5658
59+ if Gem ::Version . new ( @manifest . cc_version ) >= VERSION_1_3
60+ add_cc_assignment ( assignment , migration_id , lo_folder , html_path )
61+ else
62+ add_canvas_assignment ( assignment , migration_id , lo_folder , html_path )
63+ end
64+ end
65+
66+ def add_cc_assignment ( assignment , migration_id , lo_folder , html_path )
67+ File . open ( File . join ( lo_folder , CCHelper ::ASSIGNMENT_XML ) , 'w' ) do |assignment_file |
68+ document = Builder ::XmlMarkup . new ( :target => assignment_file , :indent => 2 )
69+ document . instruct!
70+
71+ document . assignment ( "identifier" => migration_id ,
72+ "xmlns" => CCHelper ::ASSIGNMENT_NAMESPACE ,
73+ "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance" ,
74+ "xsi:schemaLocation" => "#{ CCHelper ::ASSIGNMENT_NAMESPACE } #{ CCHelper ::ASSIGNMENT_XSD_URI } "
75+ ) do |a |
76+ AssignmentResources . create_cc_assignment ( a , assignment , migration_id )
77+ end
78+ end
79+
80+ xml_path = File . join ( migration_id , CCHelper ::ASSIGNMENT_XML )
81+ @resources . resource ( :identifier => migration_id ,
82+ :type => CCHelper ::ASSIGNMENT_TYPE ,
83+ :href => xml_path
84+ ) do |res |
85+ res . file ( :href => xml_path )
86+ end
87+
88+ @resources . resource ( :identifier => migration_id + "_fallback" ,
89+ :type => CCHelper ::WEBCONTENT
90+ ) do |res |
91+ res . tag! ( 'cpx:variant' , :identifier => migration_id + "_variant" ,
92+ :identifierref => migration_id
93+ ) do |var |
94+ var . tag! ( 'cpx:metadata' )
95+ end
96+ res . file ( :href => html_path )
97+ end
98+ end
99+
100+ def add_canvas_assignment ( assignment , migration_id , lo_folder , html_path )
57101 assignment_file = File . new ( File . join ( lo_folder , CCHelper ::ASSIGNMENT_SETTINGS ) , 'w' )
58102 document = Builder ::XmlMarkup . new ( :target => assignment_file , :indent => 2 )
59103 document . instruct!
@@ -64,21 +108,53 @@ def add_assignment(assignment)
64108 "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance" ,
65109 "xsi:schemaLocation" => "#{ CCHelper ::CANVAS_NAMESPACE } #{ CCHelper ::XSD_URI } "
66110 ) do |a |
67- AssignmentResources . create_assignment ( a , assignment )
111+ AssignmentResources . create_canvas_assignment ( a , assignment )
68112 end
69113 assignment_file . close
70114
71115 @resources . resource (
72- :identifier => migration_id ,
73- "type" => CCHelper ::LOR ,
74- :href => relative_path
116+ :identifier => migration_id ,
117+ "type" => CCHelper ::LOR ,
118+ :href => html_path
75119 ) do |res |
76- res . file ( :href => relative_path )
120+ res . file ( :href => html_path )
77121 res . file ( :href => File . join ( migration_id , CCHelper ::ASSIGNMENT_SETTINGS ) )
78122 end
79123 end
80-
81- def self . create_assignment ( node , assignment )
124+
125+ SUBMISSION_TYPE_MAP = {
126+ "online_text_entry" => "html" ,
127+ "online_url" => "url" ,
128+ "online_upload" => "file"
129+ } . freeze
130+
131+ def self . create_cc_assignment ( node , assignment , migration_id )
132+ node . title ( assignment . title )
133+ node . text ( assignment . description , texttype : 'text/html' )
134+ if assignment . points_possible
135+ node . gradable ( assignment . graded? , points_possible : assignment . points_possible )
136+ else
137+ node . gradable ( assignment . graded? )
138+ end
139+ node . submission_formats do |fmt |
140+ assignment . submission_types . split ( ',' ) . each do |st |
141+ if cc_type = SUBMISSION_TYPE_MAP [ st ]
142+ fmt . format ( :type => cc_type )
143+ end
144+ end
145+ end
146+ node . extensions do |ext |
147+ ext . assignment ( "identifier" => migration_id + "_canvas" ,
148+ "xmlns" => CCHelper ::CANVAS_NAMESPACE ,
149+ "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance" ,
150+ "xsi:schemaLocation" => "#{ CCHelper ::CANVAS_NAMESPACE } #{ CCHelper ::XSD_URI } "
151+ ) do |a |
152+ AssignmentResources . create_canvas_assignment ( a , assignment )
153+ end
154+ end
155+ end
156+
157+ def self . create_canvas_assignment ( node , assignment )
82158 node . title assignment . title
83159 node . due_at CCHelper ::ims_datetime ( assignment . due_at ) if assignment . due_at
84160 node . lock_at CCHelper ::ims_datetime ( assignment . lock_at ) if assignment . lock_at
0 commit comments