Class: Topic
- Inherits:
-
Content
- Object
- ActiveRecord::Base
- ApplicationRecord
- Content
- Topic
- Defined in:
- app/models/topic.rb
Instance Method Summary collapse
- #as_chapter_of(book) ⇒ Object
- #first_lesson ⇒ Object
-
#fork_children_into!(dup, organization, syncer) ⇒ Object
Forking.
- #import_from_resource_h!(resource_h) ⇒ Object
- #pending_lessons(user) ⇒ Object
- #reindex_usages! ⇒ Object
- #to_expanded_resource_h ⇒ Object
Methods inherited from Content
#fork_to!, #public?, #to_resource_h
Methods included from WithProgress
#completed_for?, #completion_percentage_for, #dirty_progress_if_structural_children_changed!, #dirty_progresses!, #progress_for
Methods included from WithUsages
#usage_in_organization, #usage_in_organization_of_type
Methods included from WithSlug
#normalize_slug!, #rebase!, #rebased_dup, #transparent_id, #transparent_params
Methods included from WithDescription
Methods included from Mumuki::Domain::Syncable
#platform_class_name, #sync_key
Methods inherited from ApplicationRecord
aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes
Instance Method Details
#as_chapter_of(book) ⇒ Object
30 31 32 |
# File 'app/models/topic.rb', line 30 def as_chapter_of(book) book.chapters.find_by(topic_id: id) || Chapter.new(topic: self, book: book) end |
#first_lesson ⇒ Object
14 15 16 |
# File 'app/models/topic.rb', line 14 def first_lesson lessons.first end |
#fork_children_into!(dup, organization, syncer) ⇒ Object
Forking
40 41 42 |
# File 'app/models/topic.rb', line 40 def fork_children_into!(dup, organization, syncer) dup.lessons = lessons.map { |lesson| lesson.guide.fork_to!(organization, syncer, quiet: true).as_lesson_of(dup) } end |
#import_from_resource_h!(resource_h) ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/models/topic.rb', line 18 def import_from_resource_h!(resource_h) dirty_progress_if_structural_children_changed! do self.assign_attributes resource_h.except(:lessons, :description) self.description = resource_h[:description].squeeze(' ') rebuild_lessons! resource_h[:lessons].to_a.map { |it| lesson_for(it) } end end |
#pending_lessons(user) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/topic.rb', line 44 def pending_lessons(user) guides. joins('left join public.exercises exercises on exercises.guide_id = guides.id'). joins("left join public.assignments assignments on assignments.exercise_id = exercises.id and assignments.submitter_id = #{user.id} and assignments.submission_status = #{Mumuki::Domain::Status::Submission::Passed.to_i}"). where('assignments.id is null'). group('public.guides.id', 'lessons.number').map(&:lesson) end |
#reindex_usages! ⇒ Object
34 35 36 |
# File 'app/models/topic.rb', line 34 def reindex_usages! Chapter.where(topic: self).map(&:book).each(&:reindex_usages!) end |
#to_expanded_resource_h ⇒ Object
26 27 28 |
# File 'app/models/topic.rb', line 26 def super.merge(appendix: appendix, lessons: lessons.map(&:slug)) end |