--- loncom/interface/lonquickgrades.pm 2009/02/26 16:17:30 1.47 +++ loncom/interface/lonquickgrades.pm 2010/12/02 00:53:37 1.52 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Quick Student Grades Display # -# $Id: lonquickgrades.pm,v 1.47 2009/02/26 16:17:30 schafran Exp $ +# $Id: lonquickgrades.pm,v 1.52 2010/12/02 00:53:37 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,7 +25,6 @@ # # http://www.lon-capa.org/ # -# Created Nov. 14, 2002 by Jeremy Bowers package Apache::lonquickgrades; @@ -65,21 +64,14 @@ sub real_handler { my $showPoints = $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard'; my $notshowSPRSlink = - $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external'; + (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals')); + my $notshowTotals= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'; + my $showCategories= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'; - # Create the nav map - my $navmap = Apache::lonnavmaps::navmap->new(); - if (!defined($navmap)) { - my $requrl = $r->uri; - $env{'user.error.msg'} = "$requrl:bre:0:0:Navamp initialization failed."; - return HTTP_NOT_ACCEPTABLE; - } - - # Keep this hash in sync with %statusIconMap in lonnavmaps; they - # should match color/icon - my $res = $navmap->firstResource(); # temp resource to access constants - # Header my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display"; my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}]; @@ -87,6 +79,8 @@ sub real_handler { {'bread_crumbs' => $brcrum}) ); + $r->print(&Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading')); + if (!$showPoints && !$notshowSPRSlink ) { $r->print('

' .&mt('This screen shows how many problems (or problem parts) you have completed' @@ -99,8 +93,21 @@ sub real_handler { $r->print('

'.&mt('This may take a few moments to display.').'

'); $r->rflush(); + my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=&getData($showPoints); + &outputTable($r,$showPoints,$notshowTotals, + $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted); + return OK; + +} - # End navmap using boilerplate +sub getData { + + my ($showPoints)=@_; + + # Create the nav map + my $navmap = Apache::lonnavmaps::navmap->new(); + + my $res = $navmap->firstResource(); # temp resource to access constants my $iterator = $navmap->getIterator(undef, undef, undef, 1); my $depth = 1; @@ -215,11 +222,17 @@ sub real_handler { } $curRes = $iterator->next(); } + return ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted); +} - $iterator = $navmap->getIterator(undef, undef, undef, 1); - $depth = 1; - $iterator->next(); # ignore first BEGIN_MAP - $curRes = $iterator->next(); +# +# Outputting everything. +# + +sub outputTable { + + my ($r,$showPoints,$notshowTotals, + $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_; my @start = (255, 255, 192); my @end = (0, 192, 0); @@ -230,12 +243,21 @@ sub real_handler { $r->print(&Apache::loncommon::start_data_table() .&Apache::loncommon::start_data_table_header_row() .''.&mt('Folder').''); - $title = &mt($showPoints ? "Points Scored" : "Done"); + my $title = &mt($showPoints ? "Points Scored" : "Done"); if ($totalAttempted) { - $title .= " / " . &mt("Attempted"); + $title .= " / " . &mt("Attempted"); } - $r->print("$title / ".&mt('Total').'' + $r->print("$title".($notshowTotals?'':" / ".&mt('Total')).'' .&Apache::loncommon::end_data_table_header_row()); +# +# Output of folder scores +# + + my $iterator = $navmap->getIterator(undef, undef, undef, 1); + my $depth = 1; + $iterator->next(); # ignore first BEGIN_MAP + my $curRes = $iterator->next(); + while ($depth > 0) { if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} if ($curRes == $iterator->END_MAP()) { $depth--; } @@ -250,7 +272,7 @@ sub real_handler { if ($total > 0) { my $ratio; $ratio = $correct / $total; - my $color = mixColors(\@start, \@end, $ratio); + my $color = &mixColors(\@start, \@end, $ratio); $r->print(&Apache::loncommon::start_data_table_row() .''); @@ -262,7 +284,7 @@ sub real_handler { $r->print('' .$thisIndent .'' - .$correct.' / '.$attempted.' / '.$total + .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total) .'' .&Apache::loncommon::end_data_table_row() ); @@ -270,7 +292,7 @@ sub real_handler { $r->print('' .$thisIndent .'' - .$correct.' / '.$total + .$correct.($notshowTotals?'':' / '.$total) .'' .&Apache::loncommon::end_data_table_row()); } @@ -291,28 +313,31 @@ sub real_handler { .&Apache::loncommon::end_data_table_row()); } +# +# show totals (if applicable), close table +# if ($showPoints) { - my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct"); + my $maxHelpLink = Apache::loncommon::help_open_topic("Quick_Grades_Possibly_Correct"); - $title = $showPoints ? "Points" : "Parts Done"; - my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done"); - $r->print(&Apache::loncommon::start_data_table_row() - .''.$totaltitle.': '.$totalRight.'
'); - $r->print(&mt("Max Possible To Date")." $maxHelpLink: $totalPossible
"); - $title = $showPoints ? "Points" : "Parts"; - $r->print(&mt("Total $title In Course").': '.$totalParts.'' + $title = $showPoints ? "Points" : "Parts Done"; + my $totaltitle = $showPoints ? &mt("Awarded Total Points") : &mt("Total Parts Done"); + $r->print(&Apache::loncommon::start_data_table_row() + .''.$totaltitle.': '.$totalRight.'
'); + $r->print(&mt('Max Possible To Date')." $maxHelpLink: $totalPossible
"); + $title = $showPoints ? "Points" : "Parts"; + $r->print(&mt("Total $title In Course").': '.$totalParts.'' .&Apache::loncommon::end_data_table_row()); } $r->print(&Apache::loncommon::end_data_table() .&Apache::loncommon::end_page()); - return OK; } # Pass this two refs to arrays for the start and end color, and a number # from 0 to 1 for how much of the latter you want to mix in. It will # return a string ready to show ("#FFC309"); + sub mixColors { my $start = shift; my $end = shift;