Class: ContentModules::LessonModule
- Inherits:
-
BitCore::ContentModule
- Object
- BitCore::ContentModule
- ContentModules::LessonModule
- Defined in:
- app/models/content_modules/lesson_module.rb
Overview
Container for didactic content.
Constant Summary collapse
- SLIDESHOW_PROVIDER_TYPE =
BitCore::ContentProviders::SlideshowProvider.to_s
Class Method Summary collapse
Instance Method Summary collapse
- #build_slide(attrs = {}) ⇒ Object
- #destroy_slide(slide) ⇒ Object
- #lesson_provider ⇒ Object
- #plain_title ⇒ Object
- #pretty_title ⇒ Object
- #slides ⇒ Object
- #sort(slide_ids) ⇒ Object
Class Method Details
.sort(arm_id, lesson_ids) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/content_modules/lesson_module.rb', line 8 def self.sort(arm_id, lesson_ids) start_position = Arm.find(arm_id) .bit_core_tools.find_by_type("Tools::Learn") .content_modules .where(type: [nil, "BitCore::ContentModule"]) .order(position: :asc).maximum(:position) start_position ||= 1 start_position += 1 transaction do connection.execute "SET CONSTRAINTS " \ "bit_core_content_module_position DEFERRED" lesson_ids.each_with_index do |id, idx| find(id).update_attribute(:position, idx + start_position) end end end |
Instance Method Details
#build_slide(attrs = {}) ⇒ Object
53 54 55 56 57 |
# File 'app/models/content_modules/lesson_module.rb', line 53 def (attrs = {}) .build(attrs.merge(position: .count + 1)) end |
#destroy_slide(slide) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/content_modules/lesson_module.rb', line 59 def () position = .position .transaction do if .destroy! .where("position >= ?", position).each_with_index do |s, i| s.update_column(:position, position + i) end end end true rescue false end |
#lesson_provider ⇒ Object
43 44 45 46 47 |
# File 'app/models/content_modules/lesson_module.rb', line 43 def lesson_provider @lesson_provider ||= (content_providers.find_by_type(SLIDESHOW_PROVIDER_TYPE) || add_content_provider(SLIDESHOW_PROVIDER_TYPE)) end |
#plain_title ⇒ Object
37 38 39 40 41 |
# File 'app/models/content_modules/lesson_module.rb', line 37 def plain_title return "" if title.nil? title.gsub(/\*\*/, "") end |
#pretty_title ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/content_modules/lesson_module.rb', line 26 def pretty_title return "" if title.nil? Redcarpet::Markdown.new( Redcarpet::Render::HTML.new( filter_html: true, safe_links_only: true ) ).render(title).html_safe end |
#slides ⇒ Object
49 50 51 |
# File 'app/models/content_modules/lesson_module.rb', line 49 def lesson_provider.try(:source_content).try(:slides) || [] end |
#sort(slide_ids) ⇒ Object
76 77 78 79 80 |
# File 'app/models/content_modules/lesson_module.rb', line 76 def sort() lesson_provider.source_content.sort() end |