Class: Moodle2CC::CC::Converter
- Inherits:
-
Object
- Object
- Moodle2CC::CC::Converter
show all
- Includes:
- CCHelper
- Defined in:
- lib/moodle2cc/cc/converter.rb
Constant Summary
Constants included
from CCHelper
Moodle2CC::CC::CCHelper::ASSESSMENT_CC_QTI, Moodle2CC::CC::CCHelper::ASSESSMENT_META, Moodle2CC::CC::CCHelper::ASSESSMENT_NON_CC_FOLDER, Moodle2CC::CC::CCHelper::ASSESSMENT_TYPE, Moodle2CC::CC::CCHelper::ASSIGNMENT_GROUPS, Moodle2CC::CC::CCHelper::ASSIGNMENT_SETTINGS, Moodle2CC::CC::CCHelper::BASIC_LTI, Moodle2CC::CC::CCHelper::BLTI_NAMESPACE, Moodle2CC::CC::CCHelper::CANVAS_NAMESPACE, Moodle2CC::CC::CCHelper::CANVAS_PLATFORM, Moodle2CC::CC::CCHelper::CC_ASSIGNMENT_FOLDER, Moodle2CC::CC::CCHelper::CC_EXTENSION, Moodle2CC::CC::CCHelper::CC_WIKI_FOLDER, Moodle2CC::CC::CCHelper::COURSE_SETTINGS, Moodle2CC::CC::CCHelper::COURSE_SETTINGS_DIR, Moodle2CC::CC::CCHelper::COURSE_TOKEN, Moodle2CC::CC::CCHelper::DISCUSSION_TOPIC, Moodle2CC::CC::CCHelper::EVENTS, Moodle2CC::CC::CCHelper::EXTERNAL_FEEDS, Moodle2CC::CC::CCHelper::EXTERNAL_TOOLS, Moodle2CC::CC::CCHelper::FILES_META, Moodle2CC::CC::CCHelper::GRADING_STANDARDS, Moodle2CC::CC::CCHelper::IMS_DATE, Moodle2CC::CC::CCHelper::IMS_DATETIME, Moodle2CC::CC::CCHelper::LEARNING_OUTCOMES, Moodle2CC::CC::CCHelper::LOR, Moodle2CC::CC::CCHelper::MANIFEST, Moodle2CC::CC::CCHelper::MEDIA_OBJECTS_FOLDER, Moodle2CC::CC::CCHelper::MODULE_META, Moodle2CC::CC::CCHelper::MOODLE_FILEBASE_TOKEN, Moodle2CC::CC::CCHelper::MOODLE_SLASH_TOKEN, Moodle2CC::CC::CCHelper::OBJECT_TOKEN, Moodle2CC::CC::CCHelper::QTI_ASSESSMENT_TYPE, Moodle2CC::CC::CCHelper::QTI_EXTENSION, Moodle2CC::CC::CCHelper::QUESTION_BANK, Moodle2CC::CC::CCHelper::RUBRICS, Moodle2CC::CC::CCHelper::SYLLABUS, Moodle2CC::CC::CCHelper::WEBCONTENT, Moodle2CC::CC::CCHelper::WEB_CONTENT_TOKEN, Moodle2CC::CC::CCHelper::WEB_LINK, Moodle2CC::CC::CCHelper::WEB_RESOURCES_FOLDER, Moodle2CC::CC::CCHelper::WIKI_FOLDER, Moodle2CC::CC::CCHelper::WIKI_TOKEN, Moodle2CC::CC::CCHelper::XSD_URI
Instance Method Summary
collapse
Methods included from CCHelper
#convert_file_path_tokens, convert_file_path_tokens, #create_key, create_key, create_mod_key, #create_mod_key, #create_resource_key, create_resource_key, file_query_string, #file_slug, file_slug, #get_html_title_and_body, #get_html_title_and_body_and_id, #get_html_title_and_body_and_meta_fields, ims_date, #ims_date, ims_datetime, #ims_datetime, media_object_info
Constructor Details
#initialize(moodle_backup, destination_dir) ⇒ Converter
Returns a new instance of Converter.
5
6
7
8
9
10
|
# File 'lib/moodle2cc/cc/converter.rb', line 5
def initialize(moodle_backup, destination_dir)
@resource_factory = Moodle2CC::ResourceFactory.new Moodle2CC::CC
@moodle_backup = moodle_backup
@export_dir = Dir.mktmpdir
@destination_dir = destination_dir
end
|
Instance Method Details
#convert ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/moodle2cc/cc/converter.rb', line 24
def convert
File.open(File.join(@export_dir, MANIFEST), 'w') do |file|
@document = Builder::XmlMarkup.new(:target => file, :indent => 2)
@document.instruct!
create_manifest
end
create_web_resources
Zip::File.open(imscc_tmp_path, Zip::File::CREATE) do |zipfile|
Dir["#{@export_dir}/**/*"].each do |file|
zipfile.add(file.sub(@export_dir + '/', ''), file)
end
end
FileUtils.mv imscc_tmp_path, imscc_path
FileUtils.rm_r @export_dir
end
|
#create_manifest ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/moodle2cc/cc/converter.rb', line 40
def create_manifest
@document.manifest(
"identifier" => create_key(@moodle_backup.course.id, "common_cartridge_"),
"xmlns" => "http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1",
"xmlns:lom" => "http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource",
"xmlns:lomimscc" => "http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation" => "http://www.imsglobal.org/xsd/imsccv1p1/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imscp_v1p2_v1p0.xsd http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest http://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd"
) do |manifest_node|
@manifest_node = manifest_node
@manifest_node.metadata do |md|
md.schema "IMS Common Cartridge"
md.schemaversion "1.1.0"
md.lomimscc :lom do |lom|
lom.lomimscc :general do |general|
general.lomimscc :title do |title|
title.lomimscc :string, @moodle_backup.course.fullname
end
end
lom.lomimscc :lifeCycle do |lifecycle|
lifecycle.lomimscc :contribute do |contribute|
contribute.lomimscc :date do |date|
date.lomimscc :dateTime, ims_date
end
end
end
lom.lomimscc :rights do |rights|
rights.lomimscc :copyrightAndOtherRestrictions do |node|
node.lomimscc :value, 'yes'
end
rights.lomimscc :description do |desc|
desc.lomimscc :string, 'Private (Copyrighted) - http://en.wikipedia.org/wiki/Copyright'
end
end
end
end
create_organizations
@manifest_node.resources do |resources_node|
create_resources(resources_node)
end
end
end
|
#create_organizations ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/moodle2cc/cc/converter.rb', line 85
def create_organizations
course = Course.new(@moodle_backup.course)
@manifest_node.organizations do |orgs|
orgs.organization(
:identifier => 'org_1',
:structure => 'rooted-hierarchy'
) do |org|
org.item(:identifier => "LearningModules") do |root_item|
@moodle_backup.course.sections.each do |section|
next if section.mods.length == 0
root_item.item(:identifier => create_key(section.id, "section_")) do |item_node|
item_node.title "#{course.format} #{section.number}"
section.mods.each do |mod|
resource = @resource_factory.get_resource_from_mod(mod.instance) if mod.instance
resource.create_organization_item_node(item_node) if resource
end
end
end
end
end
end
end
|
#create_resources(resources_node) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/moodle2cc/cc/converter.rb', line 108
def create_resources(resources_node)
resources = []
@moodle_backup.course.mods.each_with_index do |mod, index|
resources << @resource_factory.get_resource_from_mod(mod, index)
end
@moodle_backup.files.each do |file|
unless resources.find { |r| r.respond_to?(:url) && r.url == file }
mod = Moodle2CC::Moodle::Mod.new
mod.mod_type = 'resource'
mod.type = 'file'
mod.reference = file
mod.course = @moodle_backup.course
resources << @resource_factory.get_resource_from_mod(mod)
end
end
resources.compact.each do |resource|
resource.create_resource_node(resources_node)
resource.create_files(@export_dir)
end
end
|
#create_web_resources ⇒ Object
130
131
132
133
134
|
# File 'lib/moodle2cc/cc/converter.rb', line 130
def create_web_resources
web_resources_folder = File.join(@export_dir, WEB_RESOURCES_FOLDER)
FileUtils.mkdir_p(web_resources_folder)
@moodle_backup.copy_files_to(web_resources_folder)
end
|
#imscc_file_name ⇒ Object
12
13
14
|
# File 'lib/moodle2cc/cc/converter.rb', line 12
def imscc_file_name
"#{file_slug(@moodle_backup.course.fullname)}.imscc"
end
|
#imscc_path ⇒ Object
16
17
18
|
# File 'lib/moodle2cc/cc/converter.rb', line 16
def imscc_path
@imscc_path ||= File.join(@destination_dir, imscc_file_name)
end
|
#imscc_tmp_path ⇒ Object
20
21
22
|
# File 'lib/moodle2cc/cc/converter.rb', line 20
def imscc_tmp_path
@imscc_tmp_path ||= File.join(@export_dir, imscc_file_name)
end
|