[LON-CAPA-cvs] cvs: loncom /interface lonaboutme.pm lonparmset.pm lonviewclasslist.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 20 Jul 2007 00:15:07 -0000


This is a MIME encoded message

--raeburn1184890507
Content-Type: text/plain

raeburn		Thu Jul 19 20:15:07 2007 EDT

  Modified files:              
    /loncom/interface	lonviewclasslist.pm lonparmset.pm lonaboutme.pm 
  Log:
  Student-viewable classlist can now be set to only display students who have agreed to be listed, and can also be set to indicate whether there are viewable portfolio files.
  - new options set in Course Parameters
  - students set option to appear in roster in roster page itself.
  
  
--raeburn1184890507
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070719201507.txt"

Index: loncom/interface/lonviewclasslist.pm
diff -u loncom/interface/lonviewclasslist.pm:1.7 loncom/interface/lonviewclasslist.pm:1.8
--- loncom/interface/lonviewclasslist.pm:1.7	Thu Aug 24 23:26:05 2006
+++ loncom/interface/lonviewclasslist.pm	Thu Jul 19 20:15:06 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to display the classlist 
 #
-# $Id: lonviewclasslist.pm,v 1.7 2006/08/25 03:26:05 raeburn Exp $
+# $Id: lonviewclasslist.pm,v 1.8 2007/07/20 00:15:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -83,16 +83,17 @@
 $start_page
 $breadcrumbs
 ENDHEADER
-    #
+
+    # Get classlist view settings
+    my %viewsettings = &retrieve_view_settings();
+
     # Print classlist
-    my $cid = $env{'request.course.id'};
-    my $viewpermission = 'course.'.$cid.'.student_classlist_view';
-    if (&allowed_to_view_classlist()) {
-        $r->print(&html_classlist());
-    } else {
-        $r->print('<h2>'.
-                  &mt("You are not authorized to view the classlist for your course.").
-                  '</h2>');
+    if (keys(%viewsettings) > 0) {
+        $r->print(&html_classlist($r,\%viewsettings));
+    } else {
+        $r->print('<h3>'.
+                  &mt("Display of a student-viewable course roster is not currently enabled.").
+                  '</h3>');
     }
     #
     # Finish up
@@ -100,56 +101,147 @@
     return OK;
 }
 
-sub allowed_to_view_classlist {
-    return 0 if (! exists($env{'request.course.id'}));
-    my $cid = $env{'request.course.id'};
-    my $viewpermission = 'course.'.$cid.'.student_classlist_view';
-    if (exists($env{$viewpermission}) &&
-        $env{$viewpermission} =~ /^(all|section)$/) {
-        return $env{$viewpermission};
-    } else {
-        return 0;
+sub retrieve_view_settings {
+    my %viewsettings;
+    if (exists($env{'request.course.id'})) {
+        my $cid = $env{'request.course.id'};
+        my $viewpermission = 'course.'.$cid.'.student_classlist_view';
+        my $student_opt_in = 'course.'.$cid.'.student_classlist_opt_in';
+        my $portfiles_link = 'course.'.$cid.'.student_classlist_portfiles';
+        if (exists($env{$viewpermission}) &&
+            $env{$viewpermission} =~ /^(all|section)$/) {
+            $viewsettings{'permission'} = $env{$viewpermission};
+            if ($viewsettings{'permission'} =~ /^section$/i) {
+                $viewsettings{'limit_to_section'} = 1;
+            } else {
+                $viewsettings{'limit_to_section'} = 0;
+            }
+            $viewsettings{'student_opt_in'} = $env{$student_opt_in};
+            $viewsettings{'portfiles_link'} = $env{$portfiles_link};
+        }
     }
+    return %viewsettings;
 }
 
 sub html_classlist {
-    my $limit_to_section = (&allowed_to_view_classlist()=~ /^section$/i);
-    my $Str;
-    if ($limit_to_section) {
+    my ($r,$viewsettings) = @_;
+    my ($Str,$title,$secdisplay,$cid,$cdom,$cnum,$listtype,%publicroster);
+    my $fullroster = &Apache::loncoursedata::get_classlist();
+    my $classlist;
+
+    if ($env{'form.action'} eq 'setenv') {
+        $Str .= &process_student_prefs();
+    }
+    $Str .= '<h3>'.&mt('Student-viewable course roster').'</h3>';
+
+    $cid = $env{'request.course.id'};
+    $cdom = $env{'course.'.$cid.'.domain'};
+    $cnum = $env{'course.'.$cid.'.num'};
+
+    if ($viewsettings->{'limit_to_section'}) {
         if ($env{'request.course.sec'} eq '') {
-            $Str .= '<h2>'.
-                &mt('Students with no section').'</h2>';
+            $title = '<h4>'.&mt('Students with no section').'</h4>';
+            $listtype = 'without a section';
         } else {
-            $Str.='<h2>'.
-                &mt('Students in section "[_1]"',
-                    $env{'request.course.sec'}).
-                    '</h2>';
+            $title ='<h4>'.&mt('Students in section "[_1]"',
+                               $env{'request.course.sec'}).'</h4>';
+            $listtype = 'in the section';
+            $secdisplay = " ($env{'request.course.sec'}) ";
         }
+    } else {
+        $title .= '<h4>'.&mt('Students in any section').'</h4>';
+        $listtype = 'in the course';
     }
-    # 
-    my $classlist = &Apache::loncoursedata::get_classlist();
-    #
+
+    if ($viewsettings->{'student_opt_in'}) {
+        if ($env{'request.role'} =~ /^st/)  {
+            $Str .= &print_roster_form();
+        }
+        %publicroster = &Apache::lonnet::dump('publicroster',$cdom,$cnum);
+    }
+
+    $Str .= $title;
+
+    my $fullcount = 0;
+    my $publiccount = 0;
+    my $displaycount = 0;
+    my $sectionidx  = &Apache::loncoursedata::CL_SECTION();
+    my $statusidx   = &Apache::loncoursedata::CL_STATUS();
+
+    foreach my $student (keys(%{$fullroster})) {
+        my $section  = $fullroster->{$student}->[$sectionidx];
+        my $status   = $fullroster->{$student}->[$statusidx];
+        next if (lc($status) ne 'active');
+        if ($viewsettings->{'limit_to_section'}) {
+            next if ($section ne $env{'request.course.sec'});
+        }
+        $fullcount ++;
+        if ($viewsettings->{'student_opt_in'}) {
+            if ($publicroster{$student}) {
+                $classlist->{$student} = $fullroster->{$student};
+                $publiccount ++;
+            }
+        } else {
+            $classlist->{$student} = $fullroster->{$student};
+        }
+    }
+    if ($viewsettings->{'student_opt_in'}) {
+        $displaycount = $publiccount;
+        if ($fullcount > $publiccount) {
+            if ($publiccount) {
+                $Str .= &mt('Only students who have opted to be listed in the roster ([_1] out of [_2] students) are shown.',$publiccount,$fullcount).'<br />';
+            } else {
+                if ($fullcount == 1) {
+                    $Str .= &mt('The single student '.$listtype.'[_1] has opted not to be listed in the roster.',$secdisplay);
+                } else {
+                    $Str .= &mt('None of the [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);
+                }
+                return $Str;
+            }
+        } else {
+            if ($fullcount > 1) {
+                $Str .= &mt('All [_1] students '.$listtype.'[_2] have opted to be listed in the roster.',$fullcount,$secdisplay);
+            } elsif ($fullcount == 1) {
+                $Str .= &mt('The single student '.$listtype.'[_1] has opted to be listed in the roster.',$secdisplay);
+            }
+        }
+    } else {
+        $displaycount = $fullcount;
+        if ($fullcount > 1) {
+            $Str .= &mt('All [_1] students '.$listtype.'[_2] are listed in the roster.',$fullcount,$secdisplay);
+        } elsif ($fullcount == 1) {
+            $Str .= &mt('There is only a single student '.$listtype.'[_1]',$secdisplay);
+        }
+    }
+    undef($fullroster);
+
+    if (!$displaycount) {
+        $Str .= &mt('There are currently no students to display.');
+        return $Str;
+    }
+
     # Set up a couple variables.
     my $usernameidx = &Apache::loncoursedata::CL_SNAME();
     my $domainidx   = &Apache::loncoursedata::CL_SDOM();
     my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME();
-    my $sectionidx  = &Apache::loncoursedata::CL_SECTION();
-    my $statusidx   = &Apache::loncoursedata::CL_STATUS();
-    #
+
     # Sort the students
     my $sortby = $fullnameidx;
     my @Sorted_Students = sort {
         lc($classlist->{$a}->[$sortby])  cmp lc($classlist->{$b}->[$sortby])
         } (keys(%$classlist));
-    $Str .= '<table>'.$/.
-        '<tr>'.
+    $Str .= '<br />'.&Apache::loncommon::start_data_table()."\n".
+            &Apache::loncommon::start_data_table_header_row()."\n".
         '<th></th>'. # for the count
         '<th>'.&mt('Student').'</th>'.
         '<th>'.&mt('Username').'</th>';
-    if (! $limit_to_section) {
+    if (! $viewsettings->{'limit_to_section'}) {
         $Str .= '<th>'.&mt('Section').'</th>';
     }
-    $Str .='</tr>'.$/;
+    if ($viewsettings->{'portfiles_link'}) {
+        $Str .= '<th>'.&mt('Available Portfolio files').'</th>';
+    }
+    $Str .= &Apache::loncommon::end_data_table_header_row();
     my $count ++;
     foreach my $student (@Sorted_Students) {
         my $username = $classlist->{$student}->[$usernameidx];
@@ -159,14 +251,10 @@
             $fullname = &mt('Name not given');
         }
         my $section  = $classlist->{$student}->[$sectionidx];
-        my $status   = $classlist->{$student}->[$statusidx];
-        next if (lc($status) ne 'active');
-        if ($limit_to_section) {
-            if ($section ne $env{'request.course.sec'}) {
-                next;
-            }
+        if ($section eq '') {
+            $section = &mt('none');
         }
-        $Str .= '<tr>'.
+        $Str .= &Apache::loncommon::start_data_table_row()."\n".
             '<td>'.$count++.'</td>'.
             '<td>'.&Apache::loncommon::aboutmewrapper($fullname,
                                                       $username,
@@ -175,15 +263,99 @@
             &Apache::loncommon::messagewrapper
             ('<img src="/adm/lonIcons/mailto.gif" border="0" />&nbsp;'.
              $username.'@'.$domain,$username,$domain).'</td>';
-        if (! $limit_to_section) {
+        if (! $viewsettings->{'limit_to_section'}) {
             $Str .= '<td>'.$section.'</td>';
         }
-        $Str .= '</tr>'.$/;
+        if ($viewsettings->{'portfiles_link'}) {
+            my $filecounts = &Apache::lonaboutme::portfolio_files($r,'showlink',undef,undef,$domain,$username,$fullname);
+            my $link;
+            if (ref($filecounts) eq 'HASH') {
+                $link = &mt('[quant,_1,file,files,No files]',$filecounts->{'both'});
+                if ($filecounts->{'both'} > 0) {
+                    $link = '<a href="/adm/'.$domain.'/'.$username.'/aboutme/portfolio?classlist">'.$link.'</a>'; 
+                }
+            } else {
+                $link = &mt("Error retrieving file information.");
+            }
+            $Str .= '<td>'.$link.'</td>';
+        }
+        $Str .= &Apache::loncommon::end_data_table_row()."\n";
     }
-    $Str .= '</table>';
+    $Str .= &Apache::loncommon::end_data_table();
     return $Str;
 }
 
+sub print_roster_form {
+    my $cid = $env{'request.course.id'};
+    my $showinroster = $env{'environment.internal.'.$cid.'.showinroster'};
+    my ($showoff,$showon);
+    if ($showinroster) {
+        $showon = ' checked="checked" ';
+        $showoff = ' ';
+    } else {
+        $showoff = ' checked="checked" ';
+        $showon = ' ';
+    }
+    my $output = '<hr /><h4>'.&mt('Your roster setting').'</h4>';
+    if ($showinroster) {
+        $output .= &mt('You are currently listed in the student-viewable roster.');
+    } else {
+        $output .=  &mt('You are currently <b>not</b> listed in the student-viewable roster.');
+    }
+    $output .= '<br />'.&mt('Include yourself in the roster?').'&nbsp;&nbsp;'.
+        '<form name="studentparm" method="post">'.
+        '<span class="LC_nobreak"><label><input type="radio" name="showinroster" value="1"'.$showon.'/>'.&mt('Yes').'</label>&nbsp;&nbsp;<label>'.
+        '<input type="radio" name="showinroster" value="0"'.$showoff.'/>'.&mt('No').
+        '</label></span><br /><br />'.
+        '<input type="hidden" name="action" value="setenv" />'.
+        '<input type="submit" name="studentsubmit" value="'.&mt('Save').'" /></form><hr />';
+    return $output;
+}
+
+sub process_student_prefs {
+    my $cid = $env{'request.course.id'};
+    my $cdom = $env{'course.'.$cid.'.domain'};
+    my $cnum = $env{'course.'.$cid.'.num'};
+    my $uname = $env{'user.name'};
+    my $udom = $env{'user.domain'};
+    my $student = $uname.':'.$udom;
+    my %pubroster = &Apache::lonnet::get('publicroster',[$student],$cdom,$cnum);
+    my $visibility = &mt('off');
+    my $showinroster = $env{'form.showinroster'};
+    if ($showinroster) {
+        $visibility = &mt('on');
+    }
+    my $sturoster = 0;
+    if ($pubroster{$student}) {
+        $sturoster = 1;
+    }
+    my $output;
+    if ($sturoster ne $showinroster) {
+        my %changeHash = (
+            'environment.internal.'.$cid.'.showinroster' => $showinroster,
+        );
+        my $putresult = &Apache::lonnet::put('environment',
+                                             \%changeHash,$udom,$uname);
+        if ($putresult eq 'ok') {
+            &Apache::lonnet::appenv(%changeHash);
+            my $result = &Apache::lonnet::put('publicroster',{$student => $showinroster,},$cdom,$cnum);
+            if ($result eq 'ok') {
+                $output .= &mt('Display of your name in the student-viewable roster set to <b>[_1]</b>.',$visibility);
+            } else {
+                $output .= &mt('Error occurred saving display setting.');
+            }
+        } else {
+            $output .= &mt('Error occurred saving display setting.');
+        }
+    } else {
+        $output .= &mt('Display of your name in the student-viewable roster unchanged (set to <b>[_1]</b>).',$visibility);
+    }
+    return $output;
+}
+
+
+
+
 ###################################################################
 ###################################################################
 
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.371 loncom/interface/lonparmset.pm:1.372
--- loncom/interface/lonparmset.pm:1.371	Wed Jun 20 17:06:51 2007
+++ loncom/interface/lonparmset.pm	Thu Jul 19 20:15:06 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.371 2007/06/20 21:06:51 albertel Exp $
+# $Id: lonparmset.pm,v 1.372 2007/07/20 00:15:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2170,7 +2170,8 @@
                                  '('.&mt('"[_1]" for visible separation','<tt>yes</tt>').', '.
                                  &mt('changes will not show until next login').')',
              'student_classlist_view' => '<b>'.&mt('Allow students to view classlist.').'</b>'.&mt('("all":students can view all sections,"section":students can only view their own section.blank or "disabled" prevents student view.'),
-
+             'student_classlist_portfiles' => '<b>'.&mt('Include link to accessible portfolio files').'</b><br />'.&mt('"[_1]" for link to each a listing of each student\'s files.','<tt>yes</tt>'),
+             'student_classlist_opt_in' => '<b>'.&mt("Student's agreement needed for listing in student-viewable roster").'</b><br />'.&mt('"[_1]" to require students to opt-in to listing in the roster (on the roster page).','<tt>yes</tt>'),
              'plc.roles.denied'=> '<b>'.&mt('Disallow live chatroom use for Roles').
                                   '</b><br />"<tt>st</tt>": '.
                                   &mt('student').', "<tt>ta</tt>": '.
@@ -2263,6 +2264,8 @@
                              'default_xml_style','pageseparators',
                              'question.email','question.email.text','comment.email','comment.email.text','policy.email','policy.email.text',
                              'student_classlist_view',
+                             'student_classlist_opt_in',
+                             'student_classlist_portfiles',
                              'plc.roles.denied','plc.users.denied',
                              'pch.roles.denied','pch.users.denied',
                              'allow_limited_html_in_feedback',
Index: loncom/interface/lonaboutme.pm
diff -u loncom/interface/lonaboutme.pm:1.63 loncom/interface/lonaboutme.pm:1.64
--- loncom/interface/lonaboutme.pm:1.63	Wed May 23 17:44:11 2007
+++ loncom/interface/lonaboutme.pm	Thu Jul 19 20:15:06 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # "About Me" Personal Information
 #
-# $Id: lonaboutme.pm,v 1.63 2007/05/23 21:44:11 albertel Exp $
+# $Id: lonaboutme.pm,v 1.64 2007/07/20 00:15:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -327,7 +327,8 @@
 sub print_portfiles_link {
     my ($r,$is_course) = @_;
     my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
-    my $filecounts = &portfolio_files($r,'showlink',undef,$is_course);
+    my $filecounts = &portfolio_files($r,'showlink',undef,$is_course,
+                                      $cdom,$cnum,$name);
     my $query_string = &build_query_string();
     my $output;
     my %lt = &Apache::lonlocal::texthash(
@@ -459,7 +460,8 @@
                &mt('Update display').'" />';
     $output .= '</form><br /><br />';
     $r->print($output);
-    my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course);
+    my $filecounts = &portfolio_files($r,'listfiles',\%lt,$is_course,
+                                      $cdom,$cnum,$name);
     if (!($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public')) {
         my $query_string = &build_query_string();
         $r->print('<br /><br /><a href="/adm/'.$cdom.'/'.$cnum.
@@ -475,8 +477,7 @@
 }
 
 sub portfolio_files {
-    my ($r,$mode,$lt,$is_course) = @_;
-    my ($cdom,$cnum,$name) = &aboutme_info($r,$is_course);
+    my ($r,$mode,$lt,$is_course,$cdom,$cnum,$name) = @_;
     my $filecounts = {
                        withpass    => 0,
                        withoutpass => 0,

--raeburn1184890507--