--- loncom/interface/lonquickgrades.pm 2009/02/26 16:17:30 1.47 +++ loncom/interface/lonquickgrades.pm 2010/12/03 22:00:28 1.56 @@ -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.56 2010/12/03 22:00:28 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; @@ -62,45 +61,103 @@ sub real_handler { &Apache::loncommon::no_cache($r); $r->send_http_header; - my $showPoints = + my $showPoints = $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard'; - my $notshowSPRSlink = - $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external'; + my $notshowSPRSlink = + (($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"}]; $r->print(&Apache::loncommon::start_page($title,undef, {'bread_crumbs' => $brcrum}) ); - if (!$showPoints && !$notshowSPRSlink ) { - $r->print('

' - .&mt('This screen shows how many problems (or problem parts) you have completed' - .', and how many you have not yet done.' - .' You can also look at [_1]a detailed score sheet[_2].' - ,'','') - .'

'); + &startGradeScreen($r,'quick'); + + $r->rflush(); + +# my $uname='korte'; +# my $udom='gerd'; + + my $uname; + my $udom; + + my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)= + &getData($showPoints,$uname,$udom); + + if ($showCategories) { + &outputCategories($r,$showPoints,$notshowTotals, + $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted); + } else { + &outputTable($r,$showPoints,$notshowTotals, + $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted); } + &endGradeScreen($r); + return OK; - $r->print('

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

'); +} - $r->rflush(); +sub startGradeScreen { + my ($r,$mode)=@_; - # End navmap using boilerplate + 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 'externalnototals') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories')); + my $notshowTotals= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'; + my $showCategories= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'; + + my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}); + my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'}); + + if ($allowed_to_view) { + $r->print('
'); + if ($notshowTotals) { $r->print (' '.&mt('Students do not see total points.').' '); } + if ($notshowSPRSlink){ $r->print (' '.&mt('Students do not see link to spreadsheet.').' '); } + if ($showPoints) { $r->print (' '.&mt('Students will see points based on problem weights.').' '); } + if ($showCategories) { $r->print (' '.&mt('Students will see points based on categories.').' '); } + $r->print(' '.&Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading').'
'); + } + + + $r->print("\n".''."\n"); + $r->print('
'); +} + +sub endGradeScreen { + my ($r)=@_; + $r->print('
'); +} + + +sub getData { + + my ($showPoints,$uname,$udom)=@_; + + &Apache::lonnet::logthis("About to call with $uname $udom"); + + # Create the nav map + my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom); + + my $res = $navmap->firstResource(); # temp resource to access constants my $iterator = $navmap->getIterator(undef, undef, undef, 1); my $depth = 1; @@ -215,11 +272,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 +293,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 +322,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 +334,7 @@ sub real_handler { $r->print('' .$thisIndent .'' - .$correct.' / '.$attempted.' / '.$total + .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total) .'' .&Apache::loncommon::end_data_table_row() ); @@ -270,7 +342,7 @@ sub real_handler { $r->print('' .$thisIndent .'' - .$correct.' / '.$total + .$correct.($notshowTotals?'':' / '.$total) .'' .&Apache::loncommon::end_data_table_row()); } @@ -291,28 +363,41 @@ 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; +} + +# +# Outputting category-based grades. +# + +sub outputCategories { + + my ($r,$showPoints,$notshowTotals, + $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)=@_; } # 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;