Module: Course::LeaderboardsHelper

Includes:
Achievement::AchievementsHelper
Included in:
ControllerHelper
Defined in:
app/helpers/course/leaderboards_helper.rb

Instance Method Summary collapse

Methods included from Achievement::AchievementsHelper

#achievement_badge_path, #display_achievement_badge

Instance Method Details

#display_user_countInteger

Returns Number of users to be displayed, based on leaderboard settings.

Returns:

  • (Integer)

    Number of users to be displayed, based on leaderboard settings.


6
7
8
# File 'app/helpers/course/leaderboards_helper.rb', line 6

def display_user_count
  @display_user_count ||= @settings.display_user_count
end

#leaderboard_position(course, course_user, display_user_count) ⇒ nil, Integer

Computes the position of a student on a course's leaderboard.

Parameters:

  • course (Course)
  • course_user (CourseUser)

    The student to query for.

  • display_user_count (Integer)

    The number of positions available on the leaderboard

Returns:

  • (nil)

    if student is not on the leaderboard

  • (Integer)

    position of the student on the leaderboard


17
18
19
20
21
# File 'app/helpers/course/leaderboards_helper.rb', line 17

def leaderboard_position(course, course_user, display_user_count)
  index = course.course_users.students.without_phantom_users.includes(:user).
          ordered_by_experience_points.take(display_user_count).find_index(course_user)
  index && index + 1
end