Module: Moodle2CC::CC::CCHelper
- Included in:
- Assessment, Assignment, Converter, Course, DiscussionTopic, Label, Question, WebContent, WebLink, Wiki, Moodle2CC::Canvas::QuestionBank, Moodle2CC::Canvas::QuestionGroup
- Defined in:
- lib/moodle2cc/cc/cc_helper.rb
Defined Under Namespace
Classes: HtmlContentExporter
Constant Summary
collapse
- CANVAS_NAMESPACE =
'http://canvas.instructure.com/xsd/cccv1p0'
- XSD_URI =
'http://canvas.instructure.com/xsd/cccv1p0.xsd'
- IMS_DATE =
"%Y-%m-%d"
- IMS_DATETIME =
"%Y-%m-%dT%H:%M:%S"
- CC_EXTENSION =
'imscc'
- QTI_EXTENSION =
".xml.qti"
- CANVAS_PLATFORM =
'canvas.instructure.com'
- ASSESSMENT_TYPE =
Common Cartridge 1.1 (What Canvas exports)
'imsqti_xmlv1p2/imscc_xmlv1p1/assessment'
- QUESTION_BANK =
'imsqti_xmlv1p2/imscc_xmlv1p1/question-bank'
- DISCUSSION_TOPIC =
"imsdt_xmlv1p1"
- LOR =
"associatedcontent/imscc_xmlv1p1/learning-application-resource"
- WEB_LINK =
"imswl_xmlv1p1"
- WEBCONTENT =
"webcontent"
- BASIC_LTI =
'imsbasiclti_xmlv1p0'
- BLTI_NAMESPACE =
"http://www.imsglobal.org/xsd/imsbasiclti_v1p0"
- QTI_ASSESSMENT_TYPE =
'imsqti_xmlv1p2'
- OBJECT_TOKEN =
"$CANVAS_OBJECT_REFERENCE$"
- COURSE_TOKEN =
"$CANVAS_COURSE_REFERENCE$"
- WIKI_TOKEN =
"$WIKI_REFERENCE$"
- WEB_CONTENT_TOKEN =
"$IMS_CC_FILEBASE$"
- MOODLE_FILEBASE_TOKEN =
"$@FILEPHP@$"
- MOODLE_SLASH_TOKEN =
"$@SLASH@$"
- ASSESSMENT_CC_QTI =
"assessment_qti.xml"
- ASSESSMENT_NON_CC_FOLDER =
'non_cc_assessments'
- ASSESSMENT_META =
"assessment_meta.xml"
- ASSIGNMENT_GROUPS =
"assignment_groups.xml"
- ASSIGNMENT_SETTINGS =
"assignment_settings.xml"
- COURSE_SETTINGS =
"course_settings.xml"
- COURSE_SETTINGS_DIR =
"course_settings"
- EXTERNAL_FEEDS =
"external_feeds.xml"
- GRADING_STANDARDS =
"grading_standards.xml"
- EVENTS =
"events.xml"
- LEARNING_OUTCOMES =
"learning_outcomes.xml"
- MANIFEST =
'imsmanifest.xml'
- MODULE_META =
"module_meta.xml"
- RUBRICS =
"rubrics.xml"
- EXTERNAL_TOOLS =
"external_tools.xml"
- FILES_META =
"files_meta.xml"
- SYLLABUS =
"syllabus.html"
- WEB_RESOURCES_FOLDER =
'web_resources'
- WIKI_FOLDER =
'wiki_content'
- MEDIA_OBJECTS_FOLDER =
'media_objects'
- CC_ASSIGNMENT_FOLDER =
File.join(WEB_RESOURCES_FOLDER, "assignments")
- CC_WIKI_FOLDER =
File.join(WEB_RESOURCES_FOLDER, "pages")
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.convert_file_path_tokens(content) ⇒ Object
.create_key(object, prepend = "") ⇒ Object
105
106
107
108
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 105
def self.create_key(object, prepend="")
key = object.to_s
"i" + Digest::MD5.hexdigest(prepend + key)
end
|
.create_mod_key(mod) ⇒ Object
110
111
112
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 110
def self.create_mod_key(mod)
create_key("#{mod.mod_type}_#{mod.id}", 'mod_')
end
|
.create_resource_key(mod) ⇒ Object
114
115
116
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 114
def self.create_resource_key(mod)
create_key("#{mod.mod_type}_#{mod.id}", 'resource_')
end
|
.file_query_string(sub_path) ⇒ Object
sub_path is the last part of a file url: /courses/1/files/1(/download) we want to handle any sort of extra params to the file url, both in the path components and the query string
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 268
def self.file_query_string(sub_path)
return if sub_path.blank?
qs = []
uri = URI.parse(sub_path)
unless uri.path == "/preview" qs << "canvas_#{Rack::Utils.escape(uri.path[1..-1])}=1"
end
Rack::Utils.parse_query(uri.query).each do |k,v|
qs << "canvas_qs_#{Rack::Utils.escape(k)}=#{Rack::Utils.escape(v)}"
end
return nil if qs.blank?
"?#{qs.join("&")}"
end
|
.file_slug(name) ⇒ Object
128
129
130
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 128
def self.file_slug(name)
slug = name.downcase.gsub(/\s/, '-').gsub(/[^a-z0-9\.\-]/, '').gsub(/\.*$/, '')
end
|
.ims_date(date = nil) ⇒ Object
118
119
120
121
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 118
def self.ims_date(date=nil)
date ||= Time.now
date.respond_to?(:utc) ? date.utc.strftime(IMS_DATE) : date.strftime(IMS_DATE)
end
|
.ims_datetime(date = nil) ⇒ Object
123
124
125
126
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 123
def self.ims_datetime(date=nil)
date ||= Time.now
date.respond_to?(:utc) ? date.utc.strftime(IMS_DATETIME) : date.strftime(IMS_DATETIME)
end
|
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 247
def self.media_object_info(obj, client = nil, flavor = nil)
unless client
client = Kaltura::ClientV3.new
client.startSession(Kaltura::SessionType::ADMIN)
end
if flavor
assets = client.flavorAssetGetByEntryId(obj.media_id)
asset = assets.sort_by { |f| f[:size].to_i }.reverse.find { |f| f[:containerFormat] == flavor }
asset ||= assets.first
else
asset = client.flavorAssetGetOriginalAsset(obj.media_id)
end
filename = "#{obj.media_id}.#{asset[:fileExt]}" if asset
{ :asset => asset, :filename => filename }
end
|
Instance Method Details
#convert_file_path_tokens(content) ⇒ Object
#create_key(object, prepend = "") ⇒ Object
77
78
79
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 77
def create_key(object, prepend="")
CCHelper.create_key(object, prepend)
end
|
#create_mod_key(mod) ⇒ Object
81
82
83
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 81
def create_mod_key(mod)
CCHelper.create_mod_key(mod)
end
|
#create_resource_key(mod) ⇒ Object
#file_slug(name) ⇒ Object
97
98
99
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 97
def file_slug(name)
CCHelper.file_slug(name)
end
|
#get_html_title_and_body(doc) ⇒ Object
151
152
153
154
155
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 151
def get_html_title_and_body(doc)
title = get_node_val(doc, 'html head title')
body = doc.at_css('html body').to_s.gsub(%r{</?body>}, '').strip
[title, body]
end
|
#get_html_title_and_body_and_id(doc) ⇒ Object
136
137
138
139
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 136
def get_html_title_and_body_and_id(doc)
id = get_node_val(doc, 'html head meta[name=identifier] @content')
get_html_title_and_body(doc) << id
end
|
#get_html_title_and_body_and_meta_fields(doc) ⇒ Object
141
142
143
144
145
146
147
148
149
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 141
def get_html_title_and_body_and_meta_fields(doc)
meta_fields = {}
doc.css('html head meta').each do |meta_node|
if key = meta_node['name']
meta_fields[key] = meta_node['content']
end
end
get_html_title_and_body(doc) << meta_fields
end
|
#ims_date(date = nil) ⇒ Object
89
90
91
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 89
def ims_date(date=nil)
CCHelper.ims_date(date)
end
|
#ims_datetime(date = nil) ⇒ Object
93
94
95
|
# File 'lib/moodle2cc/cc/cc_helper.rb', line 93
def ims_datetime(date=nil)
CCHelper.ims_datetime(date)
end
|