Sha256: 954e5acd17f6d0279908df640f748d174be7d9dde0f9f3ee255c169382eba5ae
Contents?: true
Size: 1.45 KB
Versions: 19
Compression:
Stored size: 1.45 KB
Contents
class Topic < Content numbered :lessons aggregate_of :lessons has_many :lessons, -> { order(number: :asc) }, dependent: :delete_all has_many :guides, -> { order('lessons.number') }, through: :lessons has_many :exercises, -> { order('exercises.number') }, through: :guides markdown_on :appendix 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::Laboratory::Status::Submission::Passed.to_i}"). where('assignments.id is null'). group('public.guides.id', 'lessons.number').map(&:lesson) end def first_lesson lessons.first end def import_from_json!(json) self.assign_attributes json.except('lessons', 'id', 'description', 'teacher_info') self.description = json['description'].squeeze(' ') rebuild! json['lessons'].map { |it| lesson_for(it) } Organization.all.each { |org| org.reindex_usages! } end def as_chapter_of(book) book.chapters.find_by(topic_id: id) || Chapter.new(topic: self, book: book) end private def lesson_for(slug) Guide.find_by!(slug: slug).as_lesson_of(self) rescue ActiveRecord::RecordNotFound raise "Guide for slug #{slug} could not be found" end end
Version data entries
19 entries across 19 versions & 1 rubygems