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