Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/WeBWorK/ContentGenerator/GatewayQuiz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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"};

Expand All @@ -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.
Expand Down
22 changes: 8 additions & 14 deletions lib/WeBWorK/HTML/StudentNav.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading