/** * * @global object $CFG * @global object $CURMAN */ public function enrol() { global $CFG, $CURMAN; $this->data_delete_record(); $class = new cmclass($this->classid); $courseid = $class->get_moodle_course_id(); // enrol directly in the course $student = new student($this); $student->enrolmenttime = max(time(), $class->startdate); $student->add(); if ($courseid) { $course = $CURMAN->db->get_record('course', 'id', $this->id); // the elis plugin is treated specially if ($course->enrol != 'elis') { // send the user to the Moodle enrolment page $a = new stdClass(); $a->crs = $course; $a->class = $class; $a->wwwroot = $CFG->wwwroot; $subject = get_string('moodleenrol_subj', 'block_curr_admin', $a); $message = get_string('moodleenrol', 'block_curr_admin', $a); } } if (!isset($message)) { $a = $class->idnumber; $subject = get_string('nowenroled', 'block_curr_admin', $a); $message = get_string('nowenroled', 'block_curr_admin', $a); } $user = cm_get_moodleuser($this->userid); $from = get_admin(); notification::notify($message, $user, $from); email_to_user($user, $from, $subject, $message); }
function action_savenew() { global $USER, $CFG, $CURMAN; $clsid = cm_get_param('clsid', 0); $class = new cmclass($clsid); if (!$class->is_enrollable()) { print_error('notenrollable'); } // check if class is full if (!empty($class->maxstudents) && student::count_enroled($class->id) >= $class->maxstudents) { $form = $this->create_waitlistform($classid); $form->display(); return; } // call the Moodle enrolment plugin if attached to a Moodle course, and // it's not the elis plugin $courseid = $class->get_moodle_course_id(); if ($courseid) { $course = $CURMAN->db->get_record('course', 'id', $courseid); // the elis plugin is treated specially if ($course->enrol != 'elis') { // FIXME: add message redirect("{$CFG->wwwroot}/course/enrol.php?id={$courseid}"); } } $cuserid = cm_get_crlmuserid($USER->id); $sturecord = array(); $sturecord['classid'] = $class->id; $sturecord['userid'] = $cuserid; $sturecord['enrolmenttime'] = max(time(), $class->startdate); $sturecord['completetime'] = 0; $newstu = new student($sturecord); if (($status = $newstu->add()) !== true) { if (!empty($status->message)) { echo cm_error('Record not created. Reason: ' . $status->message); } else { echo cm_error('Record not created.'); } } $this->action_default(); }