diff --git a/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm b/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm index 428f0071ca..f23b9656d5 100644 --- a/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm +++ b/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm @@ -1376,9 +1376,13 @@ sub nav ($c, $args) { my $setVersion = $c->{set}->version_id; # Find all versions of this set that have been taken (excluding those taken by the current user). - my @users = + my @userVersions = $db->listSetVersionsWhere({ user_id => { '!=' => $userID }, set_id => { like => "$setID,v\%" } }); - my @allUserRecords = $db->getUsers(map { $_->[0] } @users); + my %users = map { $_->user_id => 1 } @userVersions; + my @allUserRecords = + grep { $users{ $_->{user_id} } } + $c->db->getUsersWhere({ -and => { user_id => { not_like => 'set_id:%' } }, user_id => { '!=' => $userID } }, + [qw/last_name first_name user_id/]); if (@allUserRecords) { my $filter = $c->param('studentNavFilter'); @@ -1390,13 +1394,15 @@ sub nav ($c, $args) { # Add to the sections and recitations if defined. Also store the first user found in that section or # recitation. This user will be switched to when the filter is selected. my $section = $allUserRecords[$_]->section; - $filters{"section:$section"} = - [ $c->maketext('Filter by section [_1]', $section), $allUserRecords[$_]->user_id, $users[$_][2] ] + $filters{"section:$section"} = [ + $c->maketext('Filter by section [_1]', $section), $allUserRecords[$_]->user_id, + $userVersions[$_][2] + ] if $section && !$filters{"section:$section"}; my $recitation = $allUserRecords[$_]->recitation; $filters{"recitation:$recitation"} = [ $c->maketext('Filter by recitation [_1]', $recitation), $allUserRecords[$_]->user_id, - $users[$_][2] + $userVersions[$_][2] ] if $recitation && !$filters{"recitation:$recitation"}; @@ -1413,7 +1419,7 @@ sub nav ($c, $args) { ($addRecord->last_name || $addRecord->first_name ? $addRecord->last_name . ', ' . $addRecord->first_name : $addRecord->user_id); - $addRecord->{setVersion} = $users[$_][2]; + $addRecord->{setVersion} = $userVersions[$_][2]; } # Sort by last name, then first name, then user_id, then set version. diff --git a/lib/WeBWorK/HTML/StudentNav.pm b/lib/WeBWorK/HTML/StudentNav.pm index 7591712a8d..afa7f3c058 100644 --- a/lib/WeBWorK/HTML/StudentNav.pm +++ b/lib/WeBWorK/HTML/StudentNav.pm @@ -15,13 +15,11 @@ sub studentNav ($c, $setID) { return '' unless $c->authz->hasPermissions($userID, 'become_student'); # Find all users for the given set (except the current user) sorted by last_name, then first_name, then user_id. - my @allUserRecords = $c->db->getUsersWhere( - { - user_id => - [ map { $_->[0] } $c->db->listUserSetsWhere({ set_id => $setID, user_id => { '!=' => $userID } }) ] - }, - [qw/last_name first_name user_id/] - ); + my %users = map { $_->[0] => 1 } $c->db->listUserSetsWhere({ set_id => $setID, user_id => { '!=' => $userID } }); + my @allUserRecords = + grep { $users{ $_->{user_id} } } + $c->db->getUsersWhere({ -and => { user_id => { not_like => 'set_id:%' } }, user_id => { '!=' => $userID } }, + [qw/last_name first_name user_id/]); return '' unless @allUserRecords; @@ -50,15 +48,11 @@ sub studentNav ($c, $setID) { || ($filter =~ /^section:(.*)$/ && $_->section eq $1) || ($filter =~ /^recitation:(.*)$/ && $_->recitation eq $1); - my $addRecord = $_; - $currentUserIndex = @userRecords if $addRecord->user_id eq $eUserID; - push @userRecords, $addRecord; + $currentUserIndex = @userRecords if $_->user_id eq $eUserID; + push @userRecords, $_; # Construct a display name. - $addRecord->{displayName} = - ($addRecord->last_name || $addRecord->first_name - ? $addRecord->last_name . ', ' . $addRecord->first_name - : $addRecord->user_id); + $_->{displayName} = ($_->last_name || $_->first_name ? $_->last_name . ', ' . $_->first_name : $_->user_id); } my $prevUser = $currentUserIndex > 0 ? $userRecords[ $currentUserIndex - 1 ] : 0; my $nextUser = $currentUserIndex < $#userRecords ? $userRecords[ $currentUserIndex + 1 ] : 0;