/** * Perform all necessary tasks to remove a student enrolment from the system. */ function delete() { /// Remove any grade records for this enrolment. $result = student_grade::delete_for_user_and_class($this->userid, $this->classid); /// Unenrol them from the Moodle class. if ($moodlecourseid = moodle_get_course($this->classid)) { if (($mcourse = $this->_db->get_record('course', array('id' => $moodlecourseid))) && ($muser = $this->users->get_moodleuser())) { $sql = 'SELECT enrol.* FROM {user_enrolments} enrolments JOIN {enrol} enrol ON enrol.id = enrolments.enrolid WHERE enrol.courseid = ? AND enrolments.userid = ?'; $enrolments = $this->_db->get_recordset_sql($sql, array($moodlecourseid, $muser->id)); foreach ($enrolments as $enrolment) { $plugin = enrol_get_plugin($enrolment->enrol); $plugin->unenrol_user($enrolment, $muser->id); } unset($enrolments); } } parent::delete(); if ($this->completestatusid == STUSTATUS_NOTCOMPLETE) { $pmclass = $this->pmclass; if (empty($pmclass->maxstudents) || $pmclass->maxstudents > static::count_enroled($pmclass->id)) { $wlst = waitlist::get_next($this->classid); if (!empty($wlst)) { $wlst->enrol(); } } } return $result; }
/** * Perform all necessary tasks to remove a student enrolment from the system. */ function delete() { /// Remove any grade records for this enrolment. $result = student_grade::delete_for_user_and_class($this->userid, $this->classid); /// Unenrol them from the Moodle class. if (!empty($this->classid) && !empty($this->userid) && ($moodlecourseid = get_field('crlm_class_moodle', 'moodlecourseid', 'classid', $this->classid)) && ($muserid = cm_get_moodleuserid($this->userid))) { $context = get_context_instance(CONTEXT_COURSE, $moodlecourseid); if ($context && $context->id) { role_unassign(0, $muserid, 0, $context->id); } } $result = $result && $this->data_delete_record(); if ($this->completestatusid == STUSTATUS_NOTCOMPLETE) { $cmclass = new cmclass($this->classid); if (empty($cmclass->maxstudents) || $cmclass->maxstudents > student::count_enroled($cmclass->id)) { $wlst = waitlist::get_next($this->classid); if (!empty($wlst)) { $wlst->enrol(); } } } return $result; }
public function update() { $status = parent::update(); if ($this->moodlecourseid || $this->autocreate) { moodle_attach_class($this->id, $this->moodlecourseid, '', true, true, $this->autocreate); } if (!empty($this->oldmax) && $this->oldmax < $this->maxstudents && waitlist::count_records($this->id) > 0) { for ($i = $this->oldmax; $i < $this->maxstudents; $i++) { $next_student = waitlist::get_next($this->id); if (!empty($next_student)) { $next_student->enrol(); } else { break; } } } $status = $status && field_data::set_for_context_from_datarecord('class', $this); return $status; }
public static function check_autoenrol_after_course_completion($enrolment) { if ($enrolment->completestatusid != STUSTATUS_NOTCOMPLETE) { $pmclass = new pmclass($enrolment->classid); $pmclass->load(); if ((empty($pmclass->maxstudents) || $pmclass->maxstudents > student::count_enroled($pmclass->id)) && !empty($pmclass->enrol_from_waitlist)) { $wlst = waitlist::get_next($enrolment->classid); if (!empty($wlst)) { $crsid = $pmclass->course->id; foreach ($pmclass->course->curriculumcourse as $curcrs) { if ($curcrs->courseid == $crsid && $curcrs->prerequisites_satisfied($wlst->userid)) { $wlst->enrol(); } } } } } return true; }
public function check_autoenrol_after_course_completion($enrolment) { if ($enrolment->completestatusid != STUSTATUS_NOTCOMPLETE) { $cmclass = new cmclass($enrolment->classid); if ((empty($cmclass->maxstudents) || $cmclass->maxstudents > student::count_enroled($cmclass->id)) && !empty($cmclass->enrol_from_waitlist)) { $wlst = waitlist::get_next($enrolment->classid); if (!empty($wlst)) { $wlst->enrol(); } } } return true; }
public function save() { $isnew = empty($this->id); parent::save(); if (isset($this->track) && is_array($this->track)) { $param['classid'] = $this->id; $param['courseid'] = $this->courseid; foreach ($this->track as $t) { if (trackassignment::exists(array(new field_filter('classid', $this->id), new field_filter('trackid', $t)))) { continue; } $param['trackid'] = $t; $trackassignobj = new trackassignment($param); $trackassignobj->save(); } } if (isset($this->unlink_attached_course) && isset($this->moodlecourseid)) { // process unlink moodle course id request $return = moodle_detach_class($this->id, $this->moodlecourseid); $this->moodlecourseid = 0; } if ($this->moodlecourseid || $this->autocreate) { moodle_attach_class($this->id, $this->moodlecourseid, '', true, true, $this->autocreate); } if (!$isnew) { if (!empty($this->oldmax) && (!$this->maxstudents || $this->oldmax < $this->maxstudents) && ($waiting = waitlist::count_records($this->id)) > 0) { $start = student_count_records($this->id); $max = $this->maxstudents ? $this->maxstudents : $start + $waiting + 1; //error_log("pmclass.class.php::save() oldmax = {$this->oldmax}, start = {$start}, newmax = {$this->maxstudents}, waiting = {$waiting} ... max = {$max}"); for ($i = $start; $i < $max; $i++) { $next_student = waitlist::get_next($this->id); if (empty($next_student)) { break; } $next_student->enrol(); } } } field_data::set_for_context_from_datarecord(CONTEXT_ELIS_CLASS, $this); }