Class: Topic
Instance Method Summary
collapse
Methods inherited from Content
#fork_to!
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
#description_teaser
#platform_class_name, #sync_key
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
40
41
42
|
# File 'app/models/topic.rb', line 40
def as_chapter_of(book)
book.chapters.find_by(topic_id: id) || Chapter.new(topic: self, book: book)
end
|
#first_lesson ⇒ Object
26
27
28
|
# File 'app/models/topic.rb', line 26
def first_lesson
lessons.first
end
|
#fork_children_into!(dup, organization, syncer) ⇒ Object
50
51
52
|
# File 'app/models/topic.rb', line 50
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
30
31
32
33
34
|
# File 'app/models/topic.rb', line 30
def import_from_resource_h!(resource_h)
self.assign_attributes resource_h.except(:lessons, :description)
self.description = resource_h[:description].squeeze(' ')
rebuild! resource_h[:lessons].to_a.map { |it| lesson_for(it) }
end
|
#pending_lessons(user) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/models/topic.rb', line 14
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
44
45
46
|
# File 'app/models/topic.rb', line 44
def reindex_usages!
Chapter.where(topic: self).map(&:book).each(&:reindex_usages!)
end
|
#to_resource_h ⇒ Object
36
37
38
|
# File 'app/models/topic.rb', line 36
def to_resource_h
super.merge(appendix: appendix, lessons: lessons.map(&:slug)).compact
end
|