[LON-CAPA-cvs] cvs: loncom /interface lonquickgrades.pm

www www@source.lon-capa.org
Tue, 24 May 2011 17:17:24 -0000


www		Tue May 24 17:17:24 2011 EDT

  Modified files:              
    /loncom/interface	lonquickgrades.pm 
  Log:
  First calculations and being able to suppress output
  
  
Index: loncom/interface/lonquickgrades.pm
diff -u loncom/interface/lonquickgrades.pm:1.88 loncom/interface/lonquickgrades.pm:1.89
--- loncom/interface/lonquickgrades.pm:1.88	Sun May 22 21:53:52 2011
+++ loncom/interface/lonquickgrades.pm	Tue May 24 17:17:24 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Quick Student Grades Display
 #
-# $Id: lonquickgrades.pm,v 1.88 2011/05/22 21:53:52 www Exp $
+# $Id: lonquickgrades.pm,v 1.89 2011/05/24 17:17:24 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -572,7 +572,7 @@
     my %performance=&dumpdata($navmaps);
     my $maxpos=$#order;
     for (my $i=0;$i<=$maxpos;$i++) {
-        my ($value,$weight)=&output_and_calc_category($r,$cangrade,$navmaps,$order[$i],$i,$maxpos,\%performance,%categories);
+        my ($value,$weight)=&output_and_calc_category($r,$cangrade,$navmaps,$order[$i],$i,$maxpos,\%performance,1,%categories);
         $sum+=$value*$weight;
         $total+=$weight;
     }
@@ -604,16 +604,16 @@
 #
 
 sub output_and_calc_category {
-    my ($r,$cangrade,$navmaps,$id,$currentpos,$maxpos,$performance,%categories)=@_;
+    my ($r,$cangrade,$navmaps,$id,$currentpos,$maxpos,$performance,$output,%categories)=@_;
     my $value=0;
     my $weight=0;
     my $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
     my %lt=&Apache::lonlocal::texthash(
            'up' => 'Move Up',
            'dw' => 'Move Down');
-    $r->print("\n".&Apache::loncommon::start_data_table_row());
+    if ($output) { $r->print("\n".&Apache::loncommon::start_data_table_row()); }
 
-    if ($cangrade) {
+    if ($output && $cangrade) {
         $r->print(<<ENDMOVE);
 <td>
 <div class="LC_docs_entry_move">
@@ -640,79 +640,100 @@
         $r->print('<td><a href="javascript:storecmd(\'delcat_'.$id.'\');">'.&mt('Delete').'</a></td>');
         $r->print('<td><input type="text" name="name_'.$id.
                   '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_name'}).'" /></td>');
-    } else {
+    } elsif ($output) {
         $r->print('<td>'.$categories{$id.'_name'}.'</td>');
     }
-# Content
-    $r->print('<td><ul>');
+# Content display and summing up of points
+    my $totalpossible=0;
+    my $totalcorrect=0;
+    if ($output) { $r->print('<td><ul>'); }
     foreach my $contentid (split(/\,/,$categories{$id.'_content'})) {
-        $r->print('<li>');
-        $r->print(&Apache::lonnet::gettitle($contentid).' '.$$performance{$contentid});
-        if ($cangrade) {
-           $r->print(' <a href="javascript:storecmd(\'delcont_'.$id.'______'.$contentid.'\');">'.&mt('Delete').'</a>');
+        my ($type,$possible,$attempted,$correct)=split(/\:/,$$performance{$contentid});
+        $totalpossible+=$possible;
+        $totalcorrect+=$correct;
+        if ($output) {
+           $r->print('<li>');
+           $r->print(&Apache::lonnet::gettitle($contentid).' ('.$correct.'/'.$possible.')');
+           if ($cangrade) {
+              $r->print(' <a href="javascript:storecmd(\'delcont_'.$id.'______'.$contentid.'\');">'.&mt('Delete').'</a>');
+           }
+           $r->print('</li>');
         }
-        $r->print('</li>');
     }
-    $r->print('</ul>');
-    if ($cangrade) {
-        $r->print('<br />'.&Apache::loncommon::selectresource_link('quickform','addcont_'.$id,&mt('Add Problem or Folder')).'<br />');
+    if ($output) {
+       $r->print('</ul>');
+       $r->print('<p>'.&mt('Total raw points: [_1]/[_2]',$totalcorrect,$totalpossible).'</p>'); 
+       if ($cangrade) {
+           $r->print('<br />'.&Apache::loncommon::selectresource_link('quickform','addcont_'.$id,&mt('Add Problem or Folder')).'<br />');
+       }
+       $r->print('</td>'); 
     }
-    $r->print('</td>'); 
-
 # Total
     if ($cangrade) {
-       $r->print('<td>'.
+       if ($output) { 
+          $r->print('<td>'.
                   '<select name="totaltype_'.$id.'">'.
                   '<option value="default"'.($categories{$id.'_totaltype'} eq 'default'?' selected="selected"':'').'>'.&mt('default').'</option>'.
                   '<option value="typein"'.($categories{$id.'_totaltype'} eq 'typein'?' selected="selected"':'').'>'.&mt('Type-in value').'</option>'.
                   '</select>'.
                   '<input type="text" size="4" name="total_'.$id.
-                  '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_total'}).'" /></td>');
+                  '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_total'}).'" /></td>'); 
+       }
     } else {
-        $r->print('<td>'.($categories{$id.'_totaltype'} eq 'default'?&mt('default'):$categories{$id.'_total'}).'</td>');
+       if ($output) {
+          $r->print('<td>'.($categories{$id.'_totaltype'} eq 'default'?&mt('default'):$categories{$id.'_total'}).'</td>');
+       }
     }
 
 
 # Calculation
-    $r->print('<td><ul>');
+    if ($output) { $r->print('<td><ul>'); }
     foreach my $calcrule (split(/\,/,$categories{$id.'_calculations'})) {
-        $r->print('<li>');
+        if ($output) { $r->print('<li>'); }
         my ($code,$value)=split(/\:/,$calcrule);
-        $r->print(&pretty_prt_rule($cangrade,$id,$code,$value));
+        if ($output) { $r->print(&pretty_prt_rule($cangrade,$id,$code,$value)); }
         if ($cangrade) {
-           $r->print(' <a href="javascript:storecmd(\'delrule_'.$id.'______'.$code.'\');">'.&mt('Delete').'</a>');
+           if ($output) { $r->print(' <a href="javascript:storecmd(\'delrule_'.$id.'______'.$code.'\');">'.&mt('Delete').'</a>'); }
         }
-        $r->print('</li>');
+        if ($output) { $r->print('</li>'); }
     }
-    $r->print('</ul>');
+    if ($output) { $r->print('</ul>'); }
     if ($cangrade) {
-        $r->print('<br />'.&new_calc_rule_form($id));
+        if ($output) { $r->print('<br />'.&new_calc_rule_form($id)); }
     }
-    $r->print('</td>');
+    if ($output) { $r->print('</td>'); }
 
 # Weight
     if ($cangrade) {
-       $r->print('<td>'.
+       if ($output) { 
+          $r->print('<td>'.
                   '<input type="text" size="4" name="weight_'.$id.
                   '" value="'.&Apache::lonhtmlcommon::entity_encode($categories{$id.'_weight'}).'" /></td>');
+       }
     } else {
-        $r->print('<td>'.$categories{$id.'_weight'}.'</td>');
+       if ($output) {
+          $r->print('<td>'.$categories{$id.'_weight'}.'</td>');
+       }
     }
 # Achieved
-    $r->print('<td>');
+    if ($output) { $r->print('<td>'); }
     if ($cangrade) {
-        $r->print('<select name="displayachieved_'.$id.'">'.
+        if ($output) {
+           $r->print('<select name="displayachieved_'.$id.'">'.
                   '<option value="percent"'.($categories{$id.'_displayachieved'} eq 'percent'?' selected="selected"':'').'>'.&mt('percent').'</option>'.
                   '<option value="points"'.($categories{$id.'_displayachieved'} eq 'points'?' selected="selected"':'').'>'.&mt('points').'</option>'.
                   '</select>');
+        }
     } else {
-        if ($categories{$id.'_displayachieved'} eq 'percent') {
-            $r->print(&mt('percent'));
-        } else {
-            $r->print(&mt('points'));
+        if ($output) {
+            if ($categories{$id.'_displayachieved'} eq 'percent') {
+                $r->print(&mt('percent'));
+            } else {
+                $r->print(&mt('points'));
+            }
         }
     }
-    $r->print('</td>');
+    if ($output) { $r->print('</td>'); }
 
     return ($value,$weight);
 }