Class: Moodle2CC::Canvas::Course

Inherits:
Moodle2CC::CC::Course show all
Defined in:
lib/moodle2cc/canvas/course.rb

Constant Summary

Constants included from Moodle2CC::CC::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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from Moodle2CC::CC::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(course) ⇒ Course

Returns a new instance of Course.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/moodle2cc/canvas/course.rb', line 6

def initialize(course)
  super

  @course = course

  @id = course.id
  @title = course.fullname
  @course_code = course.shortname
  @start_at = ims_datetime(Time.at(course.startdate))
  @is_public = course.visible
  @syllabus_body = convert_file_path_tokens(course.sections.first.summary)
  @resource_factory = Moodle2CC::ResourceFactory.new Moodle2CC::Canvas
end

Instance Attribute Details

#course_codeObject

Returns the value of attribute course_code.



4
5
6
# File 'lib/moodle2cc/canvas/course.rb', line 4

def course_code
  @course_code
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/moodle2cc/canvas/course.rb', line 4

def format
  @format
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/moodle2cc/canvas/course.rb', line 4

def id
  @id
end

#is_publicObject

Returns the value of attribute is_public.



4
5
6
# File 'lib/moodle2cc/canvas/course.rb', line 4

def is_public
  @is_public
end

#start_atObject

Returns the value of attribute start_at.



4
5
6
# File 'lib/moodle2cc/canvas/course.rb', line 4

def start_at
  @start_at
end

#syllabus_bodyObject

Returns the value of attribute syllabus_body.



4
5
6
# File 'lib/moodle2cc/canvas/course.rb', line 4

def syllabus_body
  @syllabus_body
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/moodle2cc/canvas/course.rb', line 4

def title
  @title
end

Instance Method Details

#create_assignment_groups_xml(export_dir) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/moodle2cc/canvas/course.rb', line 108

def create_assignment_groups_xml(export_dir)
  path = File.join(export_dir, COURSE_SETTINGS_DIR, ASSIGNMENT_GROUPS)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    document = Builder::XmlMarkup.new(:target => file, :indent => 2)
    document.instruct!
    document.assignmentGroups(
      'xsi:schemaLocation' => "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd",
      'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
      'xmlns' => "http://canvas.instructure.com/xsd/cccv1p0"
    ) do |assignment_groups_node|
      @course.sections.each do |section|
        next unless section.mods.select { |mod| mod.instance.mod_type == "assignment" }.length > 0
        assignment_groups_node.assignmentGroup(:identifier => create_key(section.id, "assignment_group_")) do |assignment_group_node|
          assignment_group_node.title "Week #{section.number}"
        end
      end
    end
  end
end

#create_course_settings_xml(export_dir) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/moodle2cc/canvas/course.rb', line 58

def create_course_settings_xml(export_dir)
  path = File.join(export_dir, COURSE_SETTINGS_DIR, COURSE_SETTINGS)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    document = Builder::XmlMarkup.new(:target => file, :indent => 2)
    document.instruct!
    document.course(
      :identifier => identifier,
      'xsi:schemaLocation' => "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd",
      'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
      'xmlns' => "http://canvas.instructure.com/xsd/cccv1p0"
    ) do |course_node|
      course_node.title @title
      course_node.course_code @course_code
      course_node.start_at @start_at
      course_node.is_public @is_public
      course_node.license 'private'
    end
  end
end

#create_files(export_dir) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/moodle2cc/canvas/course.rb', line 40

def create_files(export_dir)
  create_syllabus_file(export_dir)
  create_course_settings_xml(export_dir)
  create_files_meta_xml(export_dir)
  create_assignment_groups_xml(export_dir)
  create_module_meta_xml(export_dir)
end

#create_files_meta_xml(export_dir) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/moodle2cc/canvas/course.rb', line 129

def create_files_meta_xml(export_dir)
  path = File.join(export_dir, COURSE_SETTINGS_DIR, FILES_META)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    document = Builder::XmlMarkup.new(:target => file, :indent => 2)
    document.instruct!
    document.filesMeta(
      'xsi:schemaLocation' => "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd",
      'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
      'xmlns' => "http://canvas.instructure.com/xsd/cccv1p0")
  end
end

#create_module_meta_xml(export_dir) ⇒ Object



79
80
81
82
83
84
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/canvas/course.rb', line 79

def create_module_meta_xml(export_dir)
  path = File.join(export_dir, COURSE_SETTINGS_DIR, MODULE_META)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    document = Builder::XmlMarkup.new(:target => file, :indent => 2)
    document.instruct!
    document.modules(
      'xsi:schemaLocation' => "http://canvas.instructure.com/xsd/cccv1p0 http://canvas.instructure.com/xsd/cccv1p0.xsd",
      'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
      'xmlns' => "http://canvas.instructure.com/xsd/cccv1p0"
    ) do |modules_node|
      @course.sections.each do |section|
        next if section.mods.length == 0
        modules_node.module(:identifier => create_key(section.id, 'section_')) do |module_node|
          module_node.title "#{@format} #{section.number}"
          module_node.position section.number
          module_node.require_sequential_progress false
          module_node.items do |items_node|
            section.mods.each_with_index do |mod, index|
              resource = @resource_factory.get_resource_from_mod(mod.instance)
              resource.create_module_meta_item_node(items_node, index) if resource
            end
          end
        end
      end
    end
  end
end

#create_resource_node(resources_node) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/moodle2cc/canvas/course.rb', line 24

def create_resource_node(resources_node)
  syllabus_href = File.join(COURSE_SETTINGS_DIR, SYLLABUS)
  resources_node.resource(
    :intendeduse => 'syllabus',
    :href => syllabus_href,
    :type => LOR,
    :identifier => create_key(syllabus_href, 'resource_')
  ) do |resource_node|
    resource_node.file(:href => File.join(COURSE_SETTINGS_DIR, SYLLABUS))
    resource_node.file(:href => File.join(COURSE_SETTINGS_DIR, COURSE_SETTINGS))
    resource_node.file(:href => File.join(COURSE_SETTINGS_DIR, FILES_META))
    resource_node.file(:href => File.join(COURSE_SETTINGS_DIR, MODULE_META))
    resource_node.file(:href => File.join(COURSE_SETTINGS_DIR, ASSIGNMENT_GROUPS))
  end
end

#create_syllabus_file(export_dir) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/moodle2cc/canvas/course.rb', line 48

def create_syllabus_file(export_dir)
  template = File.expand_path('../templates/syllabus.html.erb', __FILE__)
  path = File.join(export_dir, COURSE_SETTINGS_DIR, SYLLABUS)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    erb = ERB.new(File.read(template))
    file.write(erb.result(binding))
  end
end

#identifierObject



20
21
22
# File 'lib/moodle2cc/canvas/course.rb', line 20

def identifier
  create_key(id, 'course_')
end