Class: Course::Controller

Inherits:
ApplicationController show all
Defined in:
app/controllers/course/controller.rb

Instance Method Summary collapse

Methods included from ApplicationSignInCallbacksConcern

#sign_in

Methods included from ApplicationPaginationConcern

#page_param

Methods included from ApplicationAnnouncementsConcern

#global_announcements, #unread_global_announcements

Methods included from ApplicationInstanceUserConcern

#current_instance_user

Methods included from ApplicationUserTimeZoneConcern

#set_time_zone

Methods included from ApplicationUserConcern

#handle_access_denied, #publicly_accessible?

Methods included from ApplicationComponentsConcern

#handle_component_not_found

Instance Method Details

#current_abilityObject

Override of Cancancan#current_ability to provide current course.


54
55
56
# File 'app/controllers/course/controller.rb', line 54

def current_ability
  @current_ability ||= Ability.new(current_user, current_course, current_course_user, session)
end

#current_component_hostCourse::ControllerComponentHost

Gets the component host for current instance and course

Returns:


48
49
50
# File 'app/controllers/course/controller.rb', line 48

def current_component_host
  @current_component_host ||= Course::ControllerComponentHost.new(self)
end

#current_courseCourse

Gets the current course.

Returns:

  • (Course)

    The current course that the user is browsing.


27
28
29
# File 'app/controllers/course/controller.rb', line 27

def current_course
  @course
end

#current_course_userCourseUser?

Gets the current course user.

Returns:

  • (CourseUser)

    The course user that belongs to the signed in user and the loaded course.

  • (nil)

    If there is no user session, or no course is loaded.


36
37
38
39
40
41
# File 'app/controllers/course/controller.rb', line 36

def current_course_user
  return nil unless current_course

  @current_course_user ||= current_course.course_users.with_course_statistics.
                           find_by(user: current_user)
end

Gets the sidebar items. The sidebar items are ordered by the settings of current course.

is not specified.

Parameters:

  • type (Symbol) (defaults to: nil)

    The type of sidebar item, all sidebar items will be returned if the type

Returns:

  • (Array)

    The array of ordered sidebar items of the given type.


14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/course/controller.rb', line 14

def sidebar_items(type: nil)
  weights_hash = sidebar_items_weights
  items = sidebar_items_of_type(type)

  items.sort do |a, b|
    weight_a = weights_hash[a[:key]] || a[:weight]
    weight_b = weights_hash[b[:key]] || b[:weight]
    (weight_a <=> weight_b).nonzero? || a[:key].to_s <=> b[:key].to_s
  end
end