Class: Moodle2CC::Canvas::Assignment

Inherits:
Moodle2CC::CC::Assignment show all
Includes:
Resource
Defined in:
lib/moodle2cc/canvas/assignment.rb

Constant Summary collapse

SETTINGS_ATTRIBUTES =
[:title, :points_possible, :grading_type, :due_at,
:lock_at, :unlock_at, :all_day, :all_day_date, :submission_types,
:position, :peer_reviews, :automatic_peer_reviews, :peer_review_count,
:anonymous_peer_reviews, :assignment_group_identifierref]

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

Attributes inherited from Moodle2CC::CC::Assignment

#body, #meta_fields

Instance Method Summary collapse

Methods included from Resource

#create_module_meta_item_node

Methods inherited from Moodle2CC::CC::Assignment

#build_meta_fields, #create_html, #create_resource_node

Methods included from Moodle2CC::CC::Resource

#create_organization_item_node, #create_resource_node, included

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(mod, position = 0) ⇒ Assignment

Returns a new instance of Assignment.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/moodle2cc/canvas/assignment.rb', line 11

def initialize(mod, position=0)
  super
  @rel_path = "#{identifier}/#{file_slug(@title)}.html"
  @resource_type = LOR
  @body = convert_file_path_tokens(mod.description)
  @points_possible = mod.grade_item ? mod.grade_item.grade_max : mod.grade
  @grading_type = 'points'
  if mod.time_due.to_i > 0
    @due_at = ims_datetime(Time.at(mod.time_due))
    @all_day = Time.at(mod.time_due).utc.strftime('%H:%M') == '23:59' ? true : false
    if @all_day
      @all_day_date = ims_date(Time.at(mod.time_due))
    end
    if mod.prevent_late
      @lock_at = @due_at
    end
  end
  if mod.time_available.to_i > 0
    @unlock_at = ims_datetime(Time.at(mod.time_available))
  end
  if mod.submission_end.to_i > 0
    @due_at = ims_datetime(Time.at(mod.submission_end))
  end
  @submission_types = get_submission_types(mod)
  @position = position
  @peer_reviews = @automatic_peer_reviews = mod.mod_type == 'workshop'
  @peer_review_count = mod.number_of_student_assessments
  @anonymous_peer_reviews = mod.anonymous
  @assignment_group_identifierref = create_key(mod.section_mod.section.id, 'assignment_group_')
end

Instance Method Details

#create_files(export_dir) ⇒ Object



69
70
71
72
# File 'lib/moodle2cc/canvas/assignment.rb', line 69

def create_files(export_dir)
  super
  create_settings_xml(export_dir)
end

#create_module_meta_item_elements(item_node) ⇒ Object



93
94
95
96
# File 'lib/moodle2cc/canvas/assignment.rb', line 93

def create_module_meta_item_elements(item_node)
  item_node.content_type 'Assignment'
  item_node.identifierref @identifier
end

#create_resource_sub_nodes(resource_node) ⇒ Object



65
66
67
# File 'lib/moodle2cc/canvas/assignment.rb', line 65

def create_resource_sub_nodes(resource_node)
  resource_node.file(:href => File.join(identifier, ASSIGNMENT_SETTINGS))
end

#create_settings_xml(export_dir) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/moodle2cc/canvas/assignment.rb', line 74

def create_settings_xml(export_dir)
  path = File.join(export_dir, identifier, ASSIGNMENT_SETTINGS)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    settings_node = Builder::XmlMarkup.new(:target => file, :indent => 2)
    settings_node.instruct!
    settings_node.assignment(
      :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 |assignment_node|
      SETTINGS_ATTRIBUTES.each do |attr|
        assignment_node.tag!(attr, send(attr)) unless send(attr).nil?
      end
    end
  end
end

#get_submission_types(mod) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/moodle2cc/canvas/assignment.rb', line 42

def get_submission_types(mod)
  if mod.mod_type == 'assignment'
    case mod.assignment_type
    when 'online'
      'online_text_entry'
    when 'upload'
      if mod.var2 == 1
        'online_upload,online_text_entry'
      else
        'online_upload'
      end
    when 'uploadsingle'
      'online_upload'
    else
      'none'
    end
  elsif mod.mod_type == 'workshop'
    submission_types = ['online_text_entry']
    submission_types.unshift('online_upload') if mod.number_of_attachments > 0
    submission_types.join(',')
  end
end