[LON-CAPA-cvs] cvs: loncom /automation batchcreatecourse.pm /enrollment Enrollment.pm

raeburn raeburn@source.lon-capa.org
Sat, 31 Oct 2009 17:55:01 -0000


raeburn		Sat Oct 31 17:55:01 2009 EDT

  Modified files:              
    /loncom/automation	batchcreatecourse.pm 
    /loncom/enrollment	Enrollment.pm 
  Log:
  - Accommodate Communities.
   - Coordinator role is "co".
   - Role names depend on course type.
  
  
Index: loncom/automation/batchcreatecourse.pm
diff -u loncom/automation/batchcreatecourse.pm:1.31 loncom/automation/batchcreatecourse.pm:1.32
--- loncom/automation/batchcreatecourse.pm:1.31	Sat Sep  5 20:20:17 2009
+++ loncom/automation/batchcreatecourse.pm	Sat Oct 31 17:54:51 2009
@@ -1,5 +1,5 @@
 #
-# $Id: batchcreatecourse.pm,v 1.31 2009/09/05 20:20:17 raeburn Exp $
+# $Id: batchcreatecourse.pm,v 1.32 2009/10/31 17:54:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -197,9 +197,10 @@
     open(FILE,"<$$perlvarref{'lonTabDir'}.'/rolesplain.tab");
     my @rolesplain = <FILE>;
     close(FILE);
-    foreach (@rolesplain) {
-        if ($_ =~ /^(st|ta|ex|ad|in|cc):([\w\s]+)$/) {
-            $longroles{$1} = $2;
+    foreach my $item (@rolesplain) {
+        if ($item =~ /^(st|ta|ep|ad|in|cc|co):([\w\s]+):?([\w\s]*)/) {
+            $longroles{'Course'}{$1} = $2;
+            $longroles{'Community'}{$1} = $3;
         }
     }
     my ($logmsg,$keysmsg,$newusermsg,$addresult);
@@ -403,7 +404,20 @@
     my $xliststr = '';
     my $noenddate = '';
     my $outcome;
-    my ($courseid,$crsudom,$crsunum);
+    my ($courseid,$crsudom,$crsunum,$crstype,$ccrole,$rolenames);
+    if ($details->{'crstype'} eq 'Community') {
+        $crstype = $details->{'crstype'};
+        $ccrole ='co';
+        if (ref($longroles) eq 'HASH') {
+            $rolenames = $longroles->{'Community'};
+        }
+    } else {
+        $crstype = 'Course';
+        $ccrole = 'cc';
+        if (ref($longroles) eq 'HASH') {
+            $rolenames = $longroles->{'Course'};
+        }
+    }
     my $linefeed;
     if ($context eq 'auto') {
         $linefeed = "\n";
@@ -453,9 +467,9 @@
                     'cid' => '',
                     'context' => 'createowner',
                     'linefeed' => $linefeed,
-                    'role' => 'cc',
+                    'role' => $ccrole,
                    };
-        $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo,$context);
+        $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$rolenames,\%courseinfo,$context);
     } else {
         $outcome = 'ok';
     }
@@ -521,16 +535,18 @@
     }
     
 #
-# Make owner a course coordinator
+# Make owner a coordinator
 #
     if (($owner_domain) && ($owner_uname)) {
-        &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,'cc','','','','',$context);
+        &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,$ccrole,'','','','',$context);
     }
 
 #
 # Process other reqested users
 #
-    my @courseroles = qw(st ep ta in cc);
+
+    my @courseroles = qw(st ep ta in);
+    push(@courseroles,$ccrole);
     if (&owner_is_dc($owner_uname,$owner_domain,$crsudom)) {
         push(@courseroles,'ad');
     }
@@ -567,7 +583,7 @@
                     }
                 }
                 my $firstsec;
-                unless (($firstrole eq 'cc') || ($firstrole eq ''))  {
+                unless (($firstrole eq $ccrole) || ($firstrole eq ''))  {
                     $firstsec = $details->{'users'}{$userkey}{$firstrole}{'usec'}[0];
                 }
                 my $userargs = {
@@ -595,7 +611,7 @@
                 $outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo,$context);
 # now add other roles and other sections.
                 if ($outcome eq 'ok') {
-                    if ((($firstrole ne 'st') && ($firstrole ne 'cc') && ($firstrole ne '')) && (@{$details->{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) {
+                    if ((($firstrole ne 'st') && ($firstrole ne $ccrole) && ($firstrole ne '')) && (@{$details->{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) {
                         for (my $i=1; $i<@{$details->{'users'}{$userkey}{$firstrole}{'usec'}}; $i++) {
                             my $curr_role = $firstrole;
                             my $start = $details->{'users'}{$userkey}{$curr_role}{'start'};
@@ -623,7 +639,7 @@
                                     $url .= '/'.$usec;
                                 }
                                 $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
-                            } elsif ($curr_role eq 'cc') {
+                            } elsif ($curr_role eq $ccrole) {
                                 $url = '/'.$crsudom.'/'.$crsunum;
                                 my $usec = '';
                                 $$output .=
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.41 loncom/enrollment/Enrollment.pm:1.42
--- loncom/enrollment/Enrollment.pm:1.41	Wed Aug 19 18:43:31 2009
+++ loncom/enrollment/Enrollment.pm	Sat Oct 31 17:55:01 2009
@@ -1,5 +1,5 @@
 # Automated Enrollment manager
-# $Id: Enrollment.pm,v 1.41 2009/08/19 18:43:31 raeburn Exp $
+# $Id: Enrollment.pm,v 1.42 2009/10/31 17:55:01 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -92,9 +92,17 @@
     open(FILE,"<$$configvars{'lonTabDir'}.'/rolesplain.tab");
     my @rolesplain = <FILE>;
     close(FILE);
-    foreach (@rolesplain) {
-        if ($_ =~ /^(st|ta|ex|ad|in|cc):([\w\s]+)$/) {
-            $longroles{$1} = $2;
+    foreach my $item (@rolesplain) {
+        if ($_ =~ /^(st|ta|ex|ad|in|cc|co):([\w\s]+):?([\w\s]*)/) {
+            if ($courseinfo{'type'} eq 'Community') {
+                unless($1 eq 'cc') {
+                    $longroles{$1} = $3;
+                }
+            } else {
+                unless($1 eq 'co') { 
+                    $longroles{$1} = $2;
+                }
+            }
         }
     }