diff --git a/lib/WeBWorK/ContentGenerator/Leaderboard.pm b/lib/WeBWorK/ContentGenerator/AchievementsLeaderboard.pm similarity index 74% rename from lib/WeBWorK/ContentGenerator/Leaderboard.pm rename to lib/WeBWorK/ContentGenerator/AchievementsLeaderboard.pm index 8feb1552df..9b0a8fc7d1 100644 --- a/lib/WeBWorK/ContentGenerator/Leaderboard.pm +++ b/lib/WeBWorK/ContentGenerator/AchievementsLeaderboard.pm @@ -14,12 +14,12 @@ ################################################################################ # Leader board for achievements. -package WeBWorK::ContentGenerator::Leaderboard; +package WeBWorK::ContentGenerator::AchievementsLeaderboard; use Mojo::Base 'WeBWorK::ContentGenerator', -signatures; =head1 NAME -WeBWorK::ContentGenerator::Leaderboard - Leaderboard for achievements, +WeBWorK::ContentGenerator::AchievementsLeaderboard - Leaderboard for achievements, which lists the total number of achievement points, level, and badges earned for each user with the 'include_in_stats' status. @@ -41,7 +41,11 @@ sub initialize ($c) { return unless $c->authz->hasPermissions($c->{userName}, 'view_leaderboard'); # Get list of all users (except set-level proctors) and achievements. - my @allUsers = $db->getUsersWhere({ user_id => { not_like => 'set_id:%' } }); + my @achievements = sortAchievements($db->getAchievementsWhere); + my %achievementsById = map { $_->achievement_id => $_ } @achievements; + my %globalUserAchievements = + map { $_->user_id => $_ } $db->getGlobalUserAchievementsWhere({ user_id => { not_like => 'set_id:%' } }); + my @allBadgeIDs = $db->listAchievements; my @allBadges = @allBadgeIDs ? sortAchievements($db->getAchievements(@allBadgeIDs)) : (); @@ -49,27 +53,26 @@ sub initialize ($c) { $c->{showLevels} = 0; # Hide level column unless at least one user has a level achievement. my @rows; - for my $user (@allUsers) { + for my $user ($db->getUsersWhere({ user_id => { not_like => 'set_id:%' } })) { # Only include users who can be shown in stats. next unless $ce->status_abbrev_has_behavior($user->status, 'include_in_stats'); # Skip unless user has achievement data. - my $globalData = $db->getGlobalUserAchievement($user->user_id); + my $globalData = $globalUserAchievements{ $user->user_id }; next unless $globalData; - my $level = $globalData->level_achievement_id ? $db->getAchievement($globalData->level_achievement_id) : ''; + my $level = $globalData->level_achievement_id ? $achievementsById{ $globalData->level_achievement_id } : ''; my @badges; - for my $badge (@allBadges) { + for my $achievement (@achievements) { # Skip level achievements and only show earned achievements. - last if $badge->category eq 'level'; - next unless $db->existsUserAchievement($user->user_id, $badge->achievement_id); + last if $achievement->category eq 'level'; - my $userBadge = $db->getUserAchievement($user->user_id, $badge->achievement_id); - push(@badges, $badge) if $badge->enabled && $userBadge->earned; + my $userBadge = $db->getUserAchievement($user->user_id, $achievement->achievement_id); + push(@badges, $achievement) if $userBadge && $achievement->enabled && $userBadge->earned; } - push(@rows, [ $globalData->achievement_points, $level, $user, \@badges ]); + push(@rows, [ $globalData->achievement_points || 0, $level, $user, \@badges ]); } # Sort rows descending by achievement points (or number of badges if achievement points are equal) diff --git a/lib/WeBWorK/Utils/Routes.pm b/lib/WeBWorK/Utils/Routes.pm index 766b5fd109..57cf125a9c 100644 --- a/lib/WeBWorK/Utils/Routes.pm +++ b/lib/WeBWorK/Utils/Routes.pm @@ -323,8 +323,8 @@ my %routeParameters = ( unrestricted => 1 }, achievements_leaderboard => { - title => x('Leaderboard'), - module => 'Leaderboard', + title => x('Achievements Leaderboard'), + module => 'AchievementsLeaderboard', path => '/leaderboard', unrestricted => 1 }, diff --git a/templates/ContentGenerator/Leaderboard.html.ep b/templates/ContentGenerator/AchievementsLeaderboard.html.ep similarity index 100% rename from templates/ContentGenerator/Leaderboard.html.ep rename to templates/ContentGenerator/AchievementsLeaderboard.html.ep diff --git a/templates/HelpFiles/Leaderboard.html.ep b/templates/HelpFiles/AchievementsLeaderboard.html.ep similarity index 96% rename from templates/HelpFiles/Leaderboard.html.ep rename to templates/HelpFiles/AchievementsLeaderboard.html.ep index a2d8eac4a3..0cf76cac48 100644 --- a/templates/HelpFiles/Leaderboard.html.ep +++ b/templates/HelpFiles/AchievementsLeaderboard.html.ep @@ -14,7 +14,7 @@ %################################################################################ % % layout 'help_macro'; -% title maketext('Leaderboard Help'); +% title maketext('Achievements Leaderboard Help'); %

<%= maketext('The leaderboard orders the achievement points earned from the greatest to the least. '