@@ -1340,7 +1340,7 @@ sub path ($c, $args) {
13401340 $courseName => $navigation_allowed ? $c -> url_for(' set_list' ) : ' ' ,
13411341 $setID eq ' Undefined_Set'
13421342 || $c -> {invalidSet } || $c -> {actingCreationError } || $c -> stash-> {actingConfirmation }
1343- ? ($setID => ' ' )
1343+ ? ($setID =~ / ^(.+),(v \d +) $ / ? ( $1 => $c -> url_for( ' problem_list ' , setID => $1 ), $2 => ' ' ) : ( $setID => ' ' ) )
13441344 : (
13451345 $c -> {set }-> set_id => $c -> url_for(' problem_list' , setID => $c -> {set }-> set_id),
13461346 ' v' . $c -> {set }-> version_id => ' '
@@ -1356,7 +1356,7 @@ sub nav ($c, $args) {
13561356 return ' ' if $c -> {invalidSet } || $c -> {actingCreationError } || $c -> stash-> {actingConfirmation };
13571357
13581358 # Set up and display a student navigation for those that have permission to act as a student.
1359- if ($c -> authz-> hasPermissions($userID , ' become_student' ) && $effectiveUserID ne $userID ) {
1359+ if ($c -> authz-> hasPermissions($userID , ' become_student' )) {
13601360 my $setID = $c -> {set }-> set_id;
13611361
13621362 return ' ' if $setID eq ' Undefined_Set' ;
@@ -1365,76 +1365,83 @@ sub nav ($c, $args) {
13651365
13661366 # Find all versions of this set that have been taken (excluding those taken by the current user).
13671367 my @users =
1368- $db -> listSetVersionsWhere({ user_id => { not_like => $userID }, set_id => { like => " $setID ,v\% " } });
1368+ $db -> listSetVersionsWhere({ user_id => { ' != ' => $userID }, set_id => { like => " $setID ,v\% " } });
13691369 my @allUserRecords = $db -> getUsers(map { $_ -> [0] } @users );
13701370
1371- my $filter = $c -> param(' studentNavFilter' );
1372-
1373- # Format the student names for display, and associate the users with the test versions.
1374- my %filters ;
1375- my @userRecords ;
1376- for (0 .. $#allUserRecords ) {
1377- # Add to the sections and recitations if defined. Also store the first user found in that section or
1378- # recitation. This user will be switched to when the filter is selected.
1379- my $section = $allUserRecords [$_ ]-> section;
1380- $filters {" section:$section " } =
1381- [ $c -> maketext(' Filter by section [_1]' , $section ), $allUserRecords [$_ ]-> user_id, $users [$_ ][2] ]
1382- if $section && !$filters {" section:$section " };
1383- my $recitation = $allUserRecords [$_ ]-> recitation;
1384- $filters {" recitation:$recitation " } =
1385- [ $c -> maketext(' Filter by recitation [_1]' , $recitation ), $allUserRecords [$_ ]-> user_id, $users [$_ ][2] ]
1386- if $recitation && !$filters {" recitation:$recitation " };
1387-
1388- # Only keep this user if it satisfies the selected filter if a filter was selected.
1389- next
1390- unless !$filter
1391- || ($filter =~ / ^section:(.*)$ / && $allUserRecords [$_ ]-> section eq $1 )
1392- || ($filter =~ / ^recitation:(.*)$ / && $allUserRecords [$_ ]-> recitation eq $1 );
1393-
1394- my $addRecord = $allUserRecords [$_ ];
1395- push @userRecords , $addRecord ;
1396-
1397- $addRecord -> {displayName } =
1398- ($addRecord -> last_name || $addRecord -> first_name
1399- ? $addRecord -> last_name . ' , ' . $addRecord -> first_name
1400- : $addRecord -> user_id);
1401- $addRecord -> {setVersion } = $users [$_ ][2];
1402- }
1371+ if (@allUserRecords ) {
1372+ my $filter = $c -> param(' studentNavFilter' );
1373+
1374+ # Format the student names for display, and associate the users with the test versions.
1375+ my %filters ;
1376+ my @userRecords ;
1377+ for (0 .. $#allUserRecords ) {
1378+ # Add to the sections and recitations if defined. Also store the first user found in that section or
1379+ # recitation. This user will be switched to when the filter is selected.
1380+ my $section = $allUserRecords [$_ ]-> section;
1381+ $filters {" section:$section " } =
1382+ [ $c -> maketext(' Filter by section [_1]' , $section ), $allUserRecords [$_ ]-> user_id, $users [$_ ][2] ]
1383+ if $section && !$filters {" section:$section " };
1384+ my $recitation = $allUserRecords [$_ ]-> recitation;
1385+ $filters {" recitation:$recitation " } = [
1386+ $c -> maketext(' Filter by recitation [_1]' , $recitation ), $allUserRecords [$_ ]-> user_id,
1387+ $users [$_ ][2]
1388+ ]
1389+ if $recitation && !$filters {" recitation:$recitation " };
1390+
1391+ # Only keep this user if it satisfies the selected filter if a filter was selected.
1392+ next
1393+ unless !$filter
1394+ || ($filter =~ / ^section:(.*)$ / && $allUserRecords [$_ ]-> section eq $1 )
1395+ || ($filter =~ / ^recitation:(.*)$ / && $allUserRecords [$_ ]-> recitation eq $1 );
1396+
1397+ my $addRecord = $allUserRecords [$_ ];
1398+ push @userRecords , $addRecord ;
1399+
1400+ $addRecord -> {displayName } =
1401+ ($addRecord -> last_name || $addRecord -> first_name
1402+ ? $addRecord -> last_name . ' , ' . $addRecord -> first_name
1403+ : $addRecord -> user_id);
1404+ $addRecord -> {setVersion } = $users [$_ ][2];
1405+ }
14031406
1404- # Sort by last name, then first name, then user_id, then set version.
1405- @userRecords = sort {
1406- lc ($a -> last_name) cmp lc ($b -> last_name)
1407- || lc ($a -> first_name) cmp lc ($b -> first_name)
1408- || lc ($a -> user_id) cmp lc ($b -> user_id)
1409- || lc ($a -> {setVersion }) <=> lc ($b -> {setVersion })
1410- } @userRecords ;
1411-
1412- # Find the previous, current, and next test.
1413- my $currentTestIndex = 0;
1414- for (0 .. $#userRecords ) {
1415- if ($userRecords [$_ ]-> user_id eq $effectiveUserID && $userRecords [$_ ]-> {setVersion } == $setVersion ) {
1416- $currentTestIndex = $_ ;
1417- last ;
1407+ # Sort by last name, then first name, then user_id, then set version.
1408+ @userRecords = sort {
1409+ lc ($a -> last_name) cmp lc ($b -> last_name)
1410+ || lc ($a -> first_name) cmp lc ($b -> first_name)
1411+ || lc ($a -> user_id) cmp lc ($b -> user_id)
1412+ || lc ($a -> {setVersion }) <=> lc ($b -> {setVersion })
1413+ } @userRecords ;
1414+
1415+ # Find the previous, current, and next test.
1416+ my $currentTestIndex = 0;
1417+ for (0 .. $#userRecords ) {
1418+ if ($userRecords [$_ ]-> user_id eq $effectiveUserID && $userRecords [$_ ]-> {setVersion } == $setVersion ) {
1419+ $currentTestIndex = $_ ;
1420+ last ;
1421+ }
14181422 }
1423+ my $prevTest = $currentTestIndex > 0 ? $userRecords [ $currentTestIndex - 1 ] : 0;
1424+ my $nextTest = $currentTestIndex < $#userRecords ? $userRecords [ $currentTestIndex + 1 ] : 0;
1425+
1426+ # Mark the current test.
1427+ $userRecords [$currentTestIndex ]{currentTest } = 1;
1428+
1429+ # Show the student nav.
1430+ return $c -> include(
1431+ ' ContentGenerator/GatewayQuiz/nav' ,
1432+ userID => $userID ,
1433+ eUserID => $effectiveUserID ,
1434+ userRecords => \@userRecords ,
1435+ setVersion => $setVersion ,
1436+ prevTest => $prevTest ,
1437+ nextTest => $nextTest ,
1438+ currentTestIndex => $currentTestIndex ,
1439+ filters => \%filters ,
1440+ filter => $filter
1441+ );
14191442 }
1420- my $prevTest = $currentTestIndex > 0 ? $userRecords [ $currentTestIndex - 1 ] : 0;
1421- my $nextTest = $currentTestIndex < $#userRecords ? $userRecords [ $currentTestIndex + 1 ] : 0;
1422-
1423- # Mark the current test.
1424- $userRecords [$currentTestIndex ]{currentTest } = 1;
1425-
1426- # Show the student nav.
1427- return $c -> include(
1428- ' ContentGenerator/GatewayQuiz/nav' ,
1429- userRecords => \@userRecords ,
1430- setVersion => $setVersion ,
1431- prevTest => $prevTest ,
1432- nextTest => $nextTest ,
1433- currentTestIndex => $currentTestIndex ,
1434- filters => \%filters ,
1435- filter => $filter
1436- );
14371443 }
1444+ return ' ' ;
14381445}
14391446
14401447sub warningMessage ($c ) {
0 commit comments