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

raeburn raeburn at source.lon-capa.org
Fri Mar 1 13:09:19 EST 2013


raeburn		Fri Mar  1 18:09:20 2013 EDT

  Modified files:              
    /loncom/interface	coursecatalog.pm 
  Log:
  - Include totals for student credit hours, in DC view when "Show full details"
    checked, if credits enabled for official or unofficial courses.     
  
  
-------------- next part --------------
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.72 loncom/interface/coursecatalog.pm:1.73
--- loncom/interface/coursecatalog.pm:1.72	Wed Jan 23 15:23:19 2013
+++ loncom/interface/coursecatalog.pm	Fri Mar  1 18:09:16 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.72 2013/01/23 15:23:19 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.73 2013/03/01 18:09:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -405,8 +405,6 @@
             if (($env{'form.currcat_0'} ne '') && 
                 ($env{'form.currcat_0'} ne 'instcode::0')) {
                 $catlinks .= $crumbsymbol;
-            } else {
-                $catlinks .= '</td>';
             }
         }
     } else {
@@ -740,7 +738,6 @@
     } else {
         $wasacctext .= &mt('where students had access ...');
     }
-    $wasacctext .= '<br />';
     return $wasacctext;
 }
 
@@ -946,10 +943,20 @@
     }
     $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
     &Apache::loncommon::end_data_table_header_row();
-    my %numbers;
+    my (%numbers,%creditsum);
+    my ($showcredits,$defofficial,$defunofficial);
+    my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
+    unless ($env{'form.currcat_0'} eq 'communities::0') {
+        if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+            $showcredits = 1;
+            $defofficial = $domdefaults{'officialcredits'};
+            $defunofficial = $domdefaults{'unofficialcredits'}; 
+        }
+    }
     my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$domain,$details,
                                             $usersections,\@fields,\%fieldtitles,
-                                            $wasactiveon,\%numbers);
+                                            $wasactiveon,\%numbers,\%creditsum,
+                                            $showcredits,$defofficial,$defunofficial);
     my %Sortby;
     foreach my $course (sort(keys(%{$courses}))) {
         if ($env{'form.sortby'} eq 'code') {
@@ -992,33 +999,51 @@
                                                      'Previous' => 'Total previous students',
                                                      'courses'  => 'Total unique codes and courses without codes',
                                                      'sections' => 'Total sections',
-                                                     'xlists'   => 'Total cross-listings',  
+                                                     'xlists'   => 'Total cross-listings',
                                                  );
+            if ($showcredits) {
+                $lt{'cr_Active'} = &mt('Total current student credit hours');
+                $lt{'cr_Future'} = &mt('Total future student credit hours');
+                $lt{'cr_Previous'} = &mt('Total previous student credit hours');
+            }
             if ($env{'form.currcat_0'} eq 'communities::0') {
                 $lt{'courses'} = &mt('Total communities');
                 $lt{'Active'} = &mt('Total current members'); 
                 $lt{'Future'} = &mt('Total future members');
                 $lt{'Previous'} = &mt('Total previous members');
-            } 
+            }
+            my $colspan = 8;
+            if ($showcredits) {
+                $colspan = 4;
+            }
             $output .= '<tr class="LC_footer_row">'.
                        '<td colspan="2"> </td>'.
-                       '<td colspan="8">'.
+                       '<td colspan="'.$colspan.'">'.
                        '<table border="0">';
             foreach my $item ('courses','sections','xlists') {
                 $output .= '<tr>'.
-                           '<td>'.$lt{$item}.'</td>'.
+                           '<td>'.$lt{$item}.'</td><td> </td>'.
                            '<td align="right">'.$numbers{$item}.'</td>'.
                            '</tr>'."\n";
             }
             if (@fields > 0) { 
                 foreach my $status (@fields) {
                     $output .= '<tr>'.
-                               '<td>'.$lt{$status}.'</td>'.
+                               '<td>'.$lt{$status}.'</td><td> </td>'.
                                '<td align="right">'.$numbers{$status}.'</td>'.
                                '</tr>'."\n";
                 }
             }
-            $output .= '</table></td></tr>';
+            $output .= '</table></td>';
+            if ($showcredits) {
+                $output .= '<td colspan="'.$colspan.'" valign="bottom"><table>';
+                foreach my $status (@fields) {
+                    $output .= '<tr>'.
+                               '<td>'.$lt{'cr_'.$status}.'</td><td> </td>'.
+                               '<td align="right">'.$creditsum{$status}.'</td></tr>';
+                }
+                $output .= '</table></td></tr>';
+            }
         }
     }
     $output .= &Apache::loncommon::end_data_table();
@@ -1027,14 +1052,14 @@
 
 sub build_courseinfo_hash {
     my ($courses,$knownuser,$domain,$details,$usersections,$fields,$fieldtitles,
-        $wasactiveon,$numbers) = @_;
+        $wasactiveon,$numbers,$creditsum,$showcredits,$defofficial,$defunofficial) = @_;
     my %courseinfo;
     my $now = time;
     my $gettotals;
     if ((keys(%{$courses}) > 0) && (&user_is_dc($domain)) && ($details)) {
         $gettotals = 1;
     }
-    my (%uniquecodes,$nocodes),;
+    my (%uniquecodes,$nocodes,$defcreds);
     foreach my $course (keys(%{$courses})) {
         my $descr;
         if (ref($courses->{$course}) eq 'HASH') {
@@ -1116,6 +1141,16 @@
             $showsyllabus = $coursehash{'showsyllabus'};
         }
         $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
+        if ($showcredits) {
+            if ($coursehash{'internal.defaultcredits'}) {
+                $courseinfo{$course}{'defaultcredits'} = $coursehash{'internal.defaultcredits'};
+            } elsif ($instcode ne '') {
+                $courseinfo{$course}{'defaultcredits'} = $defofficial;
+            } else {
+                $courseinfo{$course}{'defaultcredits'} = $defunofficial;
+            }
+            $defcreds = $courseinfo{$course}{'defaultcredits'};
+        }
         if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
             ($knownuser && ($details == 1))) {
             my $milestone;
@@ -1136,7 +1171,7 @@
             }
             $courseinfo{$course}{'counts'} =  
                 &count_students($cdom,$cnum,$numsec,$fields,$fieldtitles,$gettotals,
-                                $numbers,$milestone);
+                                $numbers,$creditsum,$showcredits,$defcreds,$milestone);
             if ($instcode ne '') {
                 $courseinfo{$course}{'autoenrollment'} =
                     &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
@@ -1201,7 +1236,8 @@
 }
 
 sub count_students {
-    my ($cdom,$cnum,$numsec,$fieldsref,$titlesref,$getcounts,$numbers,$wasactiveon) = @_;
+    my ($cdom,$cnum,$numsec,$fieldsref,$titlesref,$getcounts,$numbers,$creditsum,
+        $showcredits,$defcreds,$wasactiveon) = @_;
     my $countslist = '<span class="LC_nobreak">'.
                      &mt('[quant,_1,section,sections,No sections]',$numsec).'</span>';
     my (@fields,%titles,$showexpired);
@@ -1216,23 +1252,42 @@
         return;
     }
     my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
-    my %student_count = (
+    my (%student_count,%credit_count);
+    %student_count = (
                            Active   => 0,
                            Future   => 0,
                            Previous => 0,
-                       );
+                     );
+    if ($showcredits) {
+        %credit_count = (
+                          Active   => 0,
+                          Future   => 0,
+                          Previous => 0,
+                        );
+    }
     my %idx;
     $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
     $idx{'end'}    = &Apache::loncoursedata::CL_END();
+    $idx{'credits'} = &Apache::loncoursedata::CL_CREDITS();
     while (my ($student,$data) = each(%$classlist)) {
         my $status = $data->[$idx{'status'}];
+        my $credits = $data->[$idx{'credits'}];
+        if ($credits eq '') {
+            $credits = $defcreds;  
+        }
         if ($status eq 'Expired') {
             if (($showexpired) &&
                 ($data->[$idx{'end'}] >= $wasactiveon)) {
                 $student_count{'Previous'} ++;
+                if ($showcredits) {
+                    $credit_count{'Previous'} += $credits; 
+                }
             }
         } else {
             $student_count{$status} ++;
+            if ($showcredits) {
+                $credit_count{$status} += $credits;
+            }
         }
     }
     if (@fields) {
@@ -1241,6 +1296,9 @@
             $countslist .= '<span class="LC_nobreak">'.$titles{$status}.': '.
                            $student_count{$status}.'</span><br />';
             $numbers->{$status} += $student_count{$status};
+            if ($showcredits) {
+                $creditsum->{$status} += $credit_count{$status};
+            }
         }
     }
     return $countslist;


More information about the LON-CAPA-cvs mailing list