--- loncom/interface/lonquickgrades.pm 2008/12/12 18:44:32 1.43.2.1 +++ loncom/interface/lonquickgrades.pm 2010/12/03 21:33:52 1.55 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Quick Student Grades Display # -# $Id: lonquickgrades.pm,v 1.43.2.1 2008/12/12 18:44:32 raeburn Exp $ +# $Id: lonquickgrades.pm,v 1.55 2010/12/03 21:33:52 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,42 +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'; + + + 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}) + ); - # Create the nav map - my $navmap = Apache::lonnavmaps::navmap->new(); + &startGradeScreen($r,'quick'); + + $r->rflush(); + +# my $uname='korte'; +# my $udom='gerd'; - if (!defined($navmap)) { - my $requrl = $r->uri; - $env{'user.error.msg'} = "$requrl:bre:0:0:Navamp initialization failed."; - return HTTP_NOT_ACCEPTABLE; + 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; - # 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 = $showPoints ? "Points Display" : "Completed Problems Display"; - $r->print(&Apache::loncommon::start_page($title)); - - 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].' - ,'','') - .'

'); +} + +sub startGradeScreen { + my ($r,$mode)=@_; + + 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 (''); } + if ($notshowSPRSlink){ $r->print (''); } + if ($showPoints) { $r->print (''); } + if ($showCategories) { $r->print (''); } + $r->print('
'.&mt('Students do not see total points.').''.&mt('Students do not see link to spreadsheet.').''.&mt('Students will see points based on problem weights.').''.&mt('Students will see points based on categories.').''.&Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading').'
'); } - $r->print('

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

'); - $r->rflush(); + $r->print(''); + $r->print('
'); +} + +sub endGradeScreen { + my ($r)=@_; + $r->print('
'); +} + + +sub getData { + + my ($showPoints,$uname,$udom)=@_; - # End navmap using boilerplate + &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; @@ -212,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); @@ -227,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--; } @@ -247,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() .''); @@ -255,22 +330,22 @@ sub real_handler { for (my $i = 1; $i < $depth; $i++) { $thisIndent .= $indentString; } $r->print("$thisIndent$title"); - if ($totalAttempted) { - $r->print('' + if ($totalAttempted) { + $r->print('' .$thisIndent .'' - .$correct.' / '.$attempted.' / '.$total + .$correct.' / '.$attempted.($notshowTotals?'':' / '.$total) .'' .&Apache::loncommon::end_data_table_row() ); - } else { - $r->print('' + } else { + $r->print('' .$thisIndent .'' - .$correct.' / '.$total + .$correct.($notshowTotals?'':' / '.$total) .'' .&Apache::loncommon::end_data_table_row()); - } + } } } @@ -288,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;