Module: Course::Achievement::ControllerHelper

Includes:
AchievementsHelper, Condition::ConditionsHelper
Defined in:
app/helpers/course/achievement/controller_helper.rb

Instance Method Summary collapse

Methods included from Condition::ConditionsHelper

#component_enabled?

Methods included from AchievementsHelper

#achievement_badge_path, #display_achievement_badge

Instance Method Details

#achievement_status_class(achievement, current_course_user) ⇒ Array<String>

A helper to add a CSS class for each achievement, based on whether the course_user is an admin, course staff, or student. For students, the method also checks whether the course_user has obtained the achievement.

Parameters:

  • achievement (Course::Achievement)

    The actual achievement.

  • current_course_user (Course::User)

    The current_course_user.

Returns:

  • (Array<String>)

    CSS class to be added to the achievement tag.


22
23
24
25
26
27
28
29
30
# File 'app/helpers/course/achievement/controller_helper.rb', line 22

def achievement_status_class(achievement, current_course_user)
  if current_course_user.nil? || current_course_user.staff?
    []
  elsif achievement.course_users.include?(current_course_user)
    ['granted']
  else
    ['locked']
  end
end

#display_locked_achievement_badgeString

Returns the HTML code to display a locked achievement.

Returns:

  • (String)

    A HTML fragment containing the image to display the locked achievement.


9
10
11
12
13
# File 'app/helpers/course/achievement/controller_helper.rb', line 9

def display_locked_achievement_badge
  (:span, class: ['image']) do
    image_tag('achievement_locked.svg')
  end
end