Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }