Class: Course::LessonPlan::Todo

Inherits:
ApplicationRecord show all
Includes:
Workflow
Defined in:
app/models/course/lesson_plan/todo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_for!(items, course_users) ⇒ Array<String>

Creates todos to the given course_users for the given lesson_plan_item(s). This uses bulk imports, hence callbacks for todos will not be called upon creation.

Parameters:

Returns:

  • (Array<String>)

    Array of string of ids of successfully created todos.


40
41
42
43
44
45
46
47
# File 'app/models/course/lesson_plan/todo.rb', line 40

def create_for!(items, course_users)
  return unless items && course_users
  items = [items] if items.is_a?(Course::LessonPlan::Item)
  course_users = [course_users] if course_users.is_a?(CourseUser)
  result = Course::LessonPlan::Todo.
           import(*build_import_attributes_for(items, course_users), validate: false)
  result.ids
end

.delete_for(item, course_users = nil) ⇒ Array<Course::LessonPlan::Todo>|nil

Destroy todos for the associated lesson_plan_item for specified course_users. If no course_user is specified, destroy all todos for that lesson_plan_item.

Parameters:

  • item (Course::LessonPlan::Item)

    Item’s todos to be deleted

  • course_users (Array<CourseUser>) (defaults to: nil)

    If specified, filter of course_users to delete todos.

Returns:


56
57
58
59
60
# File 'app/models/course/lesson_plan/todo.rb', line 56

def delete_for(item, course_users = nil)
  return unless item
  user_ids = course_users ? course_users.select(:user_id) : item.todos.select(:user_id)
  item.todos.where.has { user_id.in(user_ids) }.destroy_all
end

Instance Method Details

#can_user_start?Boolean

Checks if item can be started by user. #can_start? must be implemented by lesson_plan_item’s actable class, otherwise all item’s are true by default.

Returns:

  • (Boolean)

    Whether the todo can be started or not.


85
86
87
# File 'app/models/course/lesson_plan/todo.rb', line 85

def can_user_start?
  item.can_user_start?(user)
end