MDL-38155 Enrolments: User can be suspended by bulk upload
authorJames Henestofel <henestofelj@hocking.edu>
Thu, 3 Oct 2013 03:28:31 +0000 (11:28 +0800)
committerRajesh Taneja <rajesh@moodle.com>
Mon, 7 Oct 2013 07:24:14 +0000 (15:24 +0800)
Added ability to suspend user enrolment during bulk upload,
this can be done by setting enrolstatus field in csv file

admin/tool/uploaduser/index.php
admin/tool/uploaduser/locallib.php

index 509374c..0cc90fa 100644 (file)
@@ -945,8 +945,23 @@ if ($formdata = $mform2->is_cancelled()) {
                 }
 
                 if ($rid) {
-                    // find duration
-                    $timeend   = 0;
+                    // Find duration and/or enrol status.
+                    $timeend = 0;
+                    $status = null;
+
+                    if (isset($user->{'enrolstatus'.$i})) {
+                        $enrolstatus = trim($user->{'enrolstatus'.$i});
+                        if ($enrolstatus == '') {
+                            $status = null;
+                        } else if ($enrolstatus === (string)ENROL_USER_ACTIVE) {
+                            $status = ENROL_USER_ACTIVE;
+                        } else if ($enrolstatus === (string)ENROL_USER_SUSPENDED) {
+                            $status = ENROL_USER_SUSPENDED;
+                        } else {
+                            debugging('Unknown enrolment status.');
+                        }
+                    }
+
                     if (!empty($user->{'enrolperiod'.$i})) {
                         $duration = (int)$user->{'enrolperiod'.$i} * 60*60*24; // convert days to seconds
                         if ($duration > 0) { // sanity check
@@ -956,7 +971,7 @@ if ($formdata = $mform2->is_cancelled()) {
                         $timeend = $today + $manualcache[$courseid]->enrolperiod;
                     }
 
-                    $manual->enrol_user($manualcache[$courseid], $user->id, $rid, $today, $timeend);
+                    $manual->enrol_user($manualcache[$courseid], $user->id, $rid, $today, $timeend, $status);
 
                     $a = new stdClass();
                     $a->course = $shortname;
index 01863f9..e5f2a61 100644 (file)
@@ -196,7 +196,7 @@ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $pr
             // hack: somebody wrote uppercase in csv file, but the system knows only lowercase profile field
             $newfield = $lcfield;
 
-        } else if (preg_match('/^(cohort|course|group|type|role|enrolperiod)\d+$/', $lcfield)) {
+        } else if (preg_match('/^(cohort|course|group|type|role|enrolperiod|enrolstatus)\d+$/', $lcfield)) {
             // special fields for enrolments
             $newfield = $lcfield;