Class: Guide
Instance Method Summary
collapse
Methods included from WithStats
#started?, #stats_for
#expectations, #expectations=, #expectations_yaml, #expectations_yaml=
Methods included from WithUsages
#usage_in_organization, #usage_in_organization_of_type
Methods included from WithSlug
#import!, #slug_parts
#description_teaser
aggregate_of, all_except, defaults, name_model_as, numbered, #save, #save_and_notify!, #save_and_notify_changes!, #update_and_notify!, update_or_create!
Instance Method Details
#as_complement_of(book) ⇒ Object
83
84
85
|
# File 'app/models/guide.rb', line 83
def as_complement_of(book) book.complements.find_by(guide_id: id) || Complement.new(guide: self, book: book)
end
|
#as_lesson_of(topic) ⇒ Object
79
80
81
|
# File 'app/models/guide.rb', line 79
def as_lesson_of(topic)
topic.lessons.find_by(guide_id: id) || Lesson.new(guide: self, topic: topic)
end
|
27
28
29
|
# File 'app/models/guide.rb', line 27
def chapter
lesson.try(:chapter) end
|
#clear_progress!(user) ⇒ Object
15
16
17
18
19
20
21
|
# File 'app/models/guide.rb', line 15
def clear_progress!(user)
transaction do
exercises.each do |exercise|
exercise.assignment_for(user)&.destroy!
end
end
end
|
#done_for?(user) ⇒ Boolean
56
57
58
|
# File 'app/models/guide.rb', line 56
def done_for?(user)
stats_for(user).done?
end
|
#exercises_count ⇒ Object
31
32
33
|
# File 'app/models/guide.rb', line 31
def exercises_count
exercises.count
end
|
#first_exercise ⇒ Object
48
49
50
|
# File 'app/models/guide.rb', line 48
def first_exercise
exercises.first
end
|
#import_from_json!(json) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/models/guide.rb', line 60
def import_from_json!(json)
self.assign_attributes json.except('exercises', 'language', 'id_format', 'id', 'teacher_info', 'collaborators')
self.language = Language.for_name(json['language'])
self.save!
json['exercises'].each_with_index do |e, i|
exercise = Exercise.find_by(guide_id: self.id, bibliotheca_id: e['id'])
exercise = exercise ?
exercise.ensure_type!(e['type']) :
Exercise.class_for(e['type']).new(guide_id: self.id, bibliotheca_id: e['id'])
exercise.import_from_json! (i+1), e
end
self.exercises.where('number > ?', json['exercises'].size).destroy_all
reload
end
|
23
24
25
|
# File 'app/models/guide.rb', line 23
def lesson
usage_in_organization_of_type Lesson
end
|
#next_exercise(user) ⇒ Object
44
45
46
|
# File 'app/models/guide.rb', line 44
def next_exercise(user)
pending_exercises(user).order('public.exercises.number asc').first
end
|
#pending_exercises(user) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'app/models/guide.rb', line 35
def pending_exercises(user)
exercises.
joins("left join public.assignments assignments
on assignments.exercise_id = exercises.id
and assignments.submitter_id = #{user.id}
and assignments.status = #{Mumuki::Laboratory::Status::Passed.to_i}").
where('assignments.id is null')
end
|
52
53
54
|
# File 'app/models/guide.rb', line 52
def search_tags
exercises.flat_map(&:search_tags).uniq
end
|