Class: Moodle2CC::Moodle2Converter::SectionConverter
- Inherits:
-
Object
- Object
- Moodle2CC::Moodle2Converter::SectionConverter
show all
- Includes:
- ConverterHelper
- Defined in:
- lib/moodle2cc/moodle2converter/section_converter.rb
Constant Summary
collapse
- ACTIVITY_CONVERTERS =
{
Moodle2::Models::Book => Moodle2Converter::BookConverter,
Moodle2::Models::Label => Moodle2Converter::LabelConverter,
}
- DEFAULT_NAME =
'Untitled Module'
ConverterHelper::ACTIVITY_LOOKUP, ConverterHelper::ASSESSMENT_SUFFIX, ConverterHelper::ASSIGNMENT_SUFFIX, ConverterHelper::CHAPTER_SUFFIX, ConverterHelper::CHOICE_ASSESSMENT_SUFFIX, ConverterHelper::COURSE_SUFFIX, ConverterHelper::DISCUSSION_SUFFIX, ConverterHelper::EXTERNAL_URL_SUFFIX, ConverterHelper::FEEDBACK_ASSESSMENT_SUFFIX, ConverterHelper::FILE_SUFFIX, ConverterHelper::FOLDER_SUFFIX, ConverterHelper::GLOSSARY_SUFFIX, ConverterHelper::INTRO_SUFFIX, ConverterHelper::LTI_SUFFIX, ConverterHelper::MAX_TITLE_LENGTH, ConverterHelper::MODULE_SUFFIX, ConverterHelper::PAGE_SUFFIX, ConverterHelper::QUESTIONNAIRE_ASSESSMENT_SUFFIX, ConverterHelper::QUESTION_BANK_SUFFIX, ConverterHelper::SUMMARY_PAGE_SUFFIX
Instance Method Summary
collapse
#activity_content_type, #generate_unique_identifier, #generate_unique_identifier_for, #generate_unique_identifier_for_activity, #generate_unique_resource_path, #get_unique_identifier_for_activity, #truncate_text, #workflow_state
Constructor Details
Returns a new instance of SectionConverter.
12
13
14
|
# File 'lib/moodle2cc/moodle2converter/section_converter.rb', line 12
def initialize
@converters ={}
end
|
Instance Method Details
#convert(moodle_section) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/moodle2cc/moodle2converter/section_converter.rb', line 16
def convert(moodle_section)
canvas_module = CanvasCC::Models::CanvasModule.new
canvas_module.identifier = generate_unique_identifier_for(moodle_section.id, MODULE_SUFFIX)
canvas_module.title = truncate_text(moodle_section.name)
canvas_module.workflow_state = workflow_state(moodle_section.visible)
canvas_module.module_items += convert_activity(moodle_section) if moodle_section.summary && !moodle_section.summary.strip.empty?
canvas_module.module_items += moodle_section.activities.map { |a| convert_activity(a) }
canvas_module.module_items = canvas_module.module_items.flatten.compact
handle_untitled_module!(canvas_module)
canvas_module
end
|
#convert_activity(moodle_activity) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/moodle2cc/moodle2converter/section_converter.rb', line 41
def convert_activity(moodle_activity)
begin
activity_converter_for(moodle_activity).convert_to_module_items(moodle_activity)
rescue Exception => e
Moodle2CC::OutputLogger.logger.info e.message
nil
end
end
|
#convert_to_module_items(moodle_activity) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/moodle2cc/moodle2converter/section_converter.rb', line 50
def convert_to_module_items(moodle_activity)
module_item = CanvasCC::Models::ModuleItem.new
module_item.identifier = generate_unique_identifier
module_item.workflow_state = workflow_state(moodle_activity.visible)
module_item.title = truncate_text(moodle_activity.name)
unless moodle_activity.is_a? Moodle2::Models::Label
if moodle_activity.is_a? Moodle2::Models::ExternalUrl
module_item.identifierref = module_item.identifier
module_item.url = moodle_activity.external_url.gsub(/\s/, '%20')
elsif moodle_activity.is_a? Moodle2::Models::Resource
module_item.identifierref = moodle_activity.file.content_hash if moodle_activity.file
elsif moodle_activity.is_a? Moodle2::Models::Lti
module_item.identifierref = module_item.identifier
module_item.url = moodle_activity.url.gsub(/\s/, '%20')
else
module_item.identifierref = get_unique_identifier_for_activity(moodle_activity)
end
end
module_item.content_type = activity_content_type(moodle_activity)
module_item.indent = '0'
[module_item]
end
|
#convert_to_summary_page(moodle_section) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/moodle2cc/moodle2converter/section_converter.rb', line 31
def convert_to_summary_page(moodle_section)
canvas_page = CanvasCC::Models::Page.new
canvas_page.identifier = generate_unique_identifier_for_activity(moodle_section)
canvas_page.title = truncate_text(moodle_section.name)
canvas_page.workflow_state = workflow_state(moodle_section.visible)
canvas_page.editing_roles = CanvasCC::Models::Page::EDITING_ROLE_TEACHER
canvas_page.body = moodle_section.summary
canvas_page
end
|