[LON-CAPA-cvs] cvs: loncom / lond /enrollment localenroll.pm /interface lonplacementtest.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Sun May 29 23:16:43 EDT 2016


raeburn		Mon May 30 03:16:43 2016 EDT

  Modified files:              
    /loncom/interface	lonplacementtest.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom	lond 
    /loncom/enrollment	localenroll.pm 
  Log:
  - Bug 6808. New course container -- "Placement" for Placement Tests.
    - Student's score on a placement test can be exported by customizing 
      localenroll.pm in /home/httpd/lib/perl on domain's library server.
    - When a placement test is completed by the student, the chain:
      lonnet::auto_export_grades() > lond::auto_export_grades_handler()
      > localenroll::export_grades() is used to export grades (e.g. to 
      a CMS).
  
  
-------------- next part --------------
Index: loncom/interface/lonplacementtest.pm
diff -u loncom/interface/lonplacementtest.pm:1.4 loncom/interface/lonplacementtest.pm:1.5
--- loncom/interface/lonplacementtest.pm:1.4	Thu Apr 14 15:43:45 2016
+++ loncom/interface/lonplacementtest.pm	Mon May 30 03:16:28 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
-# Handler for a Placement Test course container
+# Handler for a Placement Test course container 
 #
-# $Id: lonplacementtest.pm,v 1.4 2016/04/14 15:43:45 raeburn Exp $
+# $Id: lonplacementtest.pm,v 1.5 2016/05/30 03:16:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -19,7 +19,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with LON-CAPA; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
 # /home/httpd/html/adm/gpl.txt
 #
@@ -120,13 +120,16 @@
     my $incomplete;
     if (@resources) {
         my $firstsymb = $resources[0]->symb();
-        my %bytitle;
+        my (%bytitle,%bysymb);
         foreach my $res (@resources) {
             my $currsymb = $res->symb();
             my $title = $res->compTitle;
             unless (exists($bytitle{$title})) {
                 $bytitle{$title} = 0;
             }
+            unless (exists($bysymb{$currsymb})) {
+                $bysymb{$currsymb} = 0;
+            }
             my $notdone = 0;
             my $done = 0;
             my %storetries;
@@ -171,6 +174,7 @@
                 $totaldone += $done;
             }
             $bytitle{$title} += $points;
+            $bysymb{$currsymb} += $points;
             $totalpoints += $points;
         }
         if ($makenew) {
@@ -180,16 +184,53 @@
                                                              4,$newmax,'int_pos',
                                                              $env{'user.name'},
                                                              $env{'user.domain'});
-            my %grades = (
-                             uname   => $env{'user.name'},
-                             domain  => $env{'user.domain'},
-                             total   => $totalpoints,
-                             bytitle => \%bytitle,
-                         );
-            my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-            my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-            if (($cnum ne '') && ($cdom ne '')) {
-                &Apache::lonnet::auto_export_grades($cnum,$cdom,\%grades);
+            my $user = $env{'user.name'}.':'.$env{'user.domain'};
+            if ($user) {
+                my %grades = (
+                               $user => {
+                                          role            => $env{'request.role'},
+                                          id              => $env{'environment.id'},
+                                          status          => $env{'environment.inststatus'},
+                                          lastname        => $env{'environment.lastname'},
+                                          firstname       => $env{'environment.firstname'},
+                                          permanentemail  => $env{'environment.permanentemail'},
+                                          section         => $env{'request.course.sec'},
+                                          total           => $totalpoints,
+                                          category        => '',
+                                          gradebookcolumn => '',
+                                          context         => $map,
+                                        },
+                             );
+                $grades{$user}{bytitle} = \%bytitle;
+                $grades{$user}{bysymb} = \%bysymb;
+                my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+                my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+                my $scope = 'map';
+                my $instcode = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'};
+                my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
+                my $context = 'completion';
+                if (($cnum ne '') && ($cdom ne '')) {
+                    my %info = (
+                                  scope    => $scope,
+                                  instcode => $instcode,
+                                  crstype  => $crstype,
+                                  context  => $context, 
+                               ); 
+                    my $response = &Apache::lonnet::auto_export_grades($cdom,$cnum,\%info,\%grades);
+                    my $outcome;
+                    if (ref($response) eq 'HASH') {
+                        if ($response->{$user}) {
+                            $outcome = 'ok';
+                        } else {
+                            $outcome = 'fail';
+                        }
+                    } else {
+                        $outcome = $response;
+                    }
+                    unless ($outcome eq 'ok') {
+                        &Apache::lonnet::logthis("Placement Test grade export for $env{'user.name'}:$env{'user.domain'} in $env{'request.course.id'} was: $outcome"); 
+                    }
+                }
             }
         }
     }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1308 loncom/lonnet/perl/lonnet.pm:1.1309
--- loncom/lonnet/perl/lonnet.pm:1.1308	Mon May 30 02:45:43 2016
+++ loncom/lonnet/perl/lonnet.pm	Mon May 30 03:16:33 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1308 2016/05/30 02:45:43 raeburn Exp $
+# $Id: lonnet.pm,v 1.1309 2016/05/30 03:16:33 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8293,8 +8293,30 @@
 }
 
 sub auto_export_grades {
-    my ($cnum,$cdom,$gradesref) = @_;
-    return;
+    my ($cdom,$cnum,$inforef,$gradesref) = @_;
+    my ($homeserver,%exportresponse);
+    if ($cdom =~ /^$match_domain$/) {
+        $homeserver = &domain($cdom,'primary');
+    }
+    unless (($homeserver eq 'no_host') || ($homeserver eq '')) {
+        my $info;
+        if (ref($inforef) eq 'HASH') {
+            $info = &freeze_escape($inforef);
+        }
+        if (ref($gradesref) eq 'HASH') {
+            my $grades = &freeze_escape($gradesref);
+            my $response=&reply('encrypt:autoexportgrades:'.$cdom.':'.$cnum.':'.
+                                $info.':'.$grades,$homeserver);
+            unless ($response =~ /(con_lost|error|no_such_host|refused|unknown_command)/) {
+                my @items = split(/&/,$response);
+                foreach my $item (@items) {
+                    my ($key,$value) = split('=',$item);
+                    $exportresponse{&unescape($key)} = &thaw_unescape($value);
+                }
+            }
+        }
+    }
+    return \%exportresponse;
 }
 
 sub check_instcode_cloning {
Index: loncom/lond
diff -u loncom/lond:1.521 loncom/lond:1.522
--- loncom/lond:1.521	Sun May  8 20:48:35 2016
+++ loncom/lond	Mon May 30 03:16:38 2016
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.521 2016/05/08 20:48:35 raeburn Exp $
+# $Id: lond,v 1.522 2016/05/30 03:16:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -64,7 +64,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.521 $'; #' stupid emacs
+my $VERSION='$Revision: 1.522 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -5462,6 +5462,51 @@
 &register_handler("autocreatepassword", \&create_auto_enroll_password_handler, 
 		  0, 1, 0);
 
+sub auto_export_grades_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+    my ($cdom,$cnum,$info,$data) = split(/:/,$tail);
+    my $inforef = &Apache::lonnet::thaw_unescape($info);
+    my $dataref = &Apache::lonnet::thaw_unescape($data);
+    my ($outcome,$result);;
+    eval {
+        local($SIG{__DIE__})='DEFAULT';
+        my %rtnhash;
+        $outcome=&localenroll::export_grades($cdom,$cnum,$inforef,$dataref,\%rtnhash);
+        if ($outcome eq 'ok') {
+            foreach my $key (keys(%rtnhash)) {
+                $result .= &escape($key).'='.&Apache::lonnet::freeze_escape($rtnhash{$key}).'&';
+            }
+            $result =~ s/\&$//;
+        }
+    };
+    if (!$@) {
+        if ($outcome eq 'ok') {
+            if ($cipher) {
+                my $cmdlength=length($result);
+                $result.="         ";
+                my $encresult='';
+                for (my $encidx=0;$encidx<=$cmdlength;$encidx+=8) {
+                    $encresult.= unpack("H16",
+                                        $cipher->encrypt(substr($result,
+                                                                $encidx,
+                                                                8)));
+                }
+                &Reply( $client, "enc:$cmdlength:$encresult\n", $userinput);
+            } else {
+                &Failure( $client, "error:no_key\n", $userinput);
+            }
+        } else {
+            &Reply($client, "$outcome\n", $userinput);
+        }
+    } else {
+        &Failure($client,"export_error\n",$userinput);
+    }
+    return 1;
+}
+&register_handler("autoexportgrades", \&auto_export_grades_handler,
+                  0, 1, 0);
+
 #   Retrieve and remove temporary files created by/during autoenrollment.
 #
 # Formal Parameters:
Index: loncom/enrollment/localenroll.pm
diff -u loncom/enrollment/localenroll.pm:1.54 loncom/enrollment/localenroll.pm:1.55
--- loncom/enrollment/localenroll.pm:1.54	Sat Apr  2 04:31:26 2016
+++ loncom/enrollment/localenroll.pm	Mon May 30 03:16:42 2016
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for 
 # automated enrollment
-# $Id: localenroll.pm,v 1.54 2016/04/02 04:31:26 raeburn Exp $
+# $Id: localenroll.pm,v 1.55 2016/05/30 03:16:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -542,6 +542,54 @@
 
 =pod
 
+=item export_grades()
+ 
+This routine can be customized to push grade information to some other gradebook,
+LCMS, or administrative system external to LON-CAPA.
+
+export_grades() takes five arguments -
+(a) the LON-CAPA course ID
+(b) the LON-CAPA course domain
+(c) a hash reference containing the following: 
+    scope    => scope of the grades (e.g., course, map or resource).
+    instcode => institutional course code (if an official course)
+    crstype  => course type -- Course, Community or Placement
+    context  => calling context, e.g., "completion" when a student completes a placement test.
+(d) a perl data structure (hash of a hash) containing the grade data.
+    in the outer hash, the keys are student's username:domain
+    in the inner hash, keys are:  
+    id        => student/employee ID
+    lastname  => student's last name
+    firstname => student's first name
+    email     => student's "permannent" e-mail address
+    section   => student's LON-CAPA course section
+    total     => total points earned
+    bytitle   => reference to a hash (keys are question titles, values are points
+    bysymb    => reference to a hash (keys are symbs, i.e., unique resource identifiers).
+(e) reference to a hash which will contain information to return.
+    keys will be the student's username:domain. Value of 1 to show grades pushed 
+    successfully. 
+
+=cut
+
+sub export_grades
+    my ($cnum,$cdom,$hashref,$dataref,$outgoing) = @_;
+    my %info;
+    if (ref($hashref) eq 'HASH') {
+        %info = %{$hashref};
+    }
+    if ((ref($dataref) eq 'HASH') && (ref($outgoing) eq 'HASH')) {
+        foreach my $key (keys(%{$dataref})) {
+            $outgoing->{$key} = 1;
+        }
+        return 'ok';
+    } else {
+        return 'error';
+    }
+}
+
+=pod
+
 =item create_password()
 
  This is called when the authentication method set for the automated 


More information about the LON-CAPA-cvs mailing list