/**
  *
  */
 function action_updatemultiple()
 {
     global $CURMAN;
     $clsid = $this->required_param('id', PARAM_INT);
     $users = $this->optional_param('users', array());
     foreach ($users as $uid => $user) {
         $sturecord = array();
         $sturecord['id'] = $user['association_id'];
         $sturecord['classid'] = $clsid;
         $sturecord['userid'] = $uid;
         $startyear = $user['startyear'];
         $startmonth = $user['startmonth'];
         $startday = $user['startday'];
         $sturecord['enrolmenttime'] = mktime(0, 0, 0, $startmonth, $startday, $startyear);
         $endyear = $user['endyear'];
         $endmonth = $user['endmonth'];
         $endday = $user['endday'];
         $sturecord['completetime'] = mktime(0, 0, 0, $endmonth, $endday, $endyear);
         $sturecord['completestatusid'] = $user['completestatusid'];
         $sturecord['grade'] = $user['grade'];
         $sturecord['credits'] = $user['credits'];
         $sturecord['locked'] = !empty($user['locked']) ? 1 : 0;
         $stu = new student($sturecord);
         if ($stu->completestatusid == STUSTATUS_PASSED && $CURMAN->db->get_field(STUTABLE, 'completestatusid', 'id', $stu->id) != STUSTATUS_PASSED) {
             $stu->complete();
         } else {
             if (($status = $stu->update()) !== true) {
                 echo cm_error('Record not updated.  Reason: ' . $status->message);
             }
         }
         // Now once we've done all this, delete the student if we've been asked to
         if (isset($user['unenrol']) && cmclasspage::can_enrol_into_class($clsid)) {
             $stu_delete = new student($user['association_id']);
             if (!$stu_delete->delete()) {
                 echo cm_error('Student "name: ' . cm_fullname($stu->user) . '" not unenrolled.');
             }
         }
     }
     $this->action_default();
 }
示例#2
0
 /**
  * do_unenrol() new method to unenrol user from class instance
  * ELIS-8524
  */
 public function do_unenrol()
 {
     $stuid = $this->optional_param('stuid', 0, PARAM_INT);
     $wlid = $this->optional_param('wlid', 0, PARAM_INT);
     if (!empty($stuid) && ($stu = new student($stuid))) {
         $stu->delete();
     } else {
         if (!empty($wlid) && ($waitlist = new waitlist($wlid))) {
             $waitlist->delete();
         }
     }
     $this->display('available');
 }
 /**
  * Performs class_enrolment deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the association.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function class_enrolment_delete(array $data)
 {
     global $DB, $USER;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::class_enrolment_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Parse class
     if (empty($data->class_idnumber) || !($classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $data->class_idnumber)))) {
         throw new data_object_exception('ws_class_enrolment_delete_fail_invalid_class', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:class_enrol', \local_elisprogram\context\pmclass::instance($classid));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $userparams = array();
     $userid = $importplugin->get_userid_from_record($data, '', $userparams);
     if ($userid == false) {
         $a = new stdClass();
         if (empty($userparams)) {
             $a->userparams = '{empty}';
         } else {
             $a->userparams = '';
             foreach ($userparams as $userfield => $uservalue) {
                 $subfield = strpos($userfield, '_');
                 $userfield = substr($userfield, $subfield === false ? 0 : $subfield + 1);
                 if (!empty($a->userparams)) {
                     $a->userparams .= ', ';
                 }
                 $a->userparams .= "{$userfield}: '{$uservalue}'";
             }
         }
         throw new data_object_exception('ws_class_enrolment_delete_fail_invalid_user', 'local_datahub', '', $a);
     }
     $id = $DB->get_field(student::TABLE, 'id', array('classid' => $classid, 'userid' => $userid));
     // Respond.
     if (!empty($id) && ($stu = new student($id))) {
         $stu->delete();
         return array('messagecode' => get_string('ws_class_enrolment_delete_success_code', 'local_datahub'), 'message' => get_string('ws_class_enrolment_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_class_enrolment_delete_fail', 'local_datahub');
     }
 }
示例#4
0
 /**
  * Delete a student class instance enrolment
  *
  * @param object $record One record of import data
  * @param string $filename The import file name, used for logging
  * @param string $idnumber The idnumber of the class instance
  *
  * @return boolean true on success, otherwise false
  */
 function class_enrolment_delete_student($record, $filename, $idnumber)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/student.class.php');
     if (!($crsid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $idnumber)))) {
         $this->fslogger->log_failure("instance value of \"{$idnumber}\" does not refer to a valid instance of a class context.", 0, $filename, $this->linenumber, $record, "enrolment");
         return false;
     }
     $userid = $this->get_userid_from_record($record, $filename);
     // string to describe the user
     $user_descriptor = $this->get_user_descriptor($record, false, 'user_');
     if (!$DB->record_exists(student::TABLE, array('classid' => $crsid, 'userid' => $userid))) {
         $this->fslogger->log_failure("User with {$user_descriptor} is not enrolled in class instance \"{$idnumber}\" as student.", 0, $filename, $this->linenumber, $record, "enrolment");
         return false;
     }
     if (!$this->validate_class_enrolment_data('delete', $record, $filename)) {
         return false;
     }
     // obtain the class id
     $classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $idnumber));
     // delete the association
     $studentid = $DB->get_field(student::TABLE, 'id', array('userid' => $userid, 'classid' => $classid));
     $student = new student($studentid);
     $student->load();
     $student->delete();
     // log success
     $success_message = "User with {$user_descriptor} successfully unenrolled from class instance \"{$idnumber}\" as a student.";
     $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber);
     return true;
 }
示例#5
0
 public function test_delete_enrols_waitlist()
 {
     global $DB;
     $this->load_csv_data();
     $student = new student(array('userid' => 104, 'classid' => 100));
     $student->load();
     $student->save();
     $class = new pmclass(100);
     $class->load();
     $class->maxstudents = 1;
     $class->save();
     try {
         $student->delete();
     } catch (Exception $e) {
         $this->assertEquals(get_string('message_nodestinationuser', 'local_elisprogram'), $e->getMessage());
     }
 }