Module: CourseUser::TodoConcern

Extended by:
ActiveSupport::Concern
Included in:
CourseUser
Defined in:
app/models/concerns/course_user/todo_concern.rb

Instance Method Summary collapse

Instance Method Details

#create_todos_for_course_userObject

Create todos for all course_users.


11
12
13
14
15
16
# File 'app/models/concerns/course_user/todo_concern.rb', line 11

def create_todos_for_course_user
  return unless user
  items =
    Course::LessonPlan::Item.where(course_id: course_id).includes(:actable).select(&:has_todo?)
  Course::LessonPlan::Todo.create_for!(items, self)
end

#delete_todosObject

Delete all todos of the user in current course.


19
20
21
22
23
# File 'app/models/concerns/course_user/todo_concern.rb', line 19

def delete_todos
  items_in_current_course =
    Course::LessonPlan::Item.where(course_id: course_id).select(:id)
  Course::LessonPlan::Todo.where(user_id: user_id, item_id: items_in_current_course).delete_all
end