function action_confirm() { global $CURMAN; $insid = required_param('association_id', PARAM_INT); $confirm = required_param('confirm', PARAM_TEXT); $ins = new instructor($insid); $event_object = $CURMAN->db->get_record(INSTABLE, 'id', $insid); if (md5($insid) != $confirm) { echo cm_error('Invalid confirmation code!'); } else { if (!$ins->delete()) { echo cm_error('Instructor "name: ' . cm_fullname($ins->user) . '" not deleted.'); } else { //instructor_successfully_deleted echo cm_error('Instructor "name: ' . cm_fullname($ins->user) . '" deleted.'); } } $this->action_default(); }
/** * Delete an instructor class instance assignment * * @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 * @uses $CFG * @uses $DB */ function class_enrolment_delete_instructor($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/instructor.class.php'); require_once elispm::lib('data/user.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(instructor::TABLE, array('classid' => $crsid, 'userid' => $userid))) { $this->fslogger->log_failure("User with {$user_descriptor} is not enrolled in " . "class instance \"{$idnumber}\" as instructor.", 0, $filename, $this->linenumber, $record, "enrolment"); return false; } if (!$this->validate_class_enrolment_data('delete', $record, $filename)) { return false; } // obtain the cluster / userset id $classid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $idnumber)); // delete the association $studentid = $DB->get_field(instructor::TABLE, 'id', array('userid' => $userid, 'classid' => $classid)); $instructor = new instructor($studentid); $instructor->load(); $instructor->delete(); // log success $success_message = "User with {$user_descriptor} successfully unenrolled from class instance \"{$idnumber}\" as an instructor."; $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber); return true; }
/** * * Triggered when a role unassignment takes place. * @param $eventdata * @return unknown_type */ function pm_notify_role_unassign_handler($eventdata) { global $CFG, $DB; //make sure we have course manager roles defined if (empty($CFG->coursecontact)) { return true; } //retrieve the list of role ids we want to sync to curriculum admin $valid_instructor_roles = explode(',', $CFG->coursecontact); //make sure we actually care about the current role if (!in_array($eventdata->roleid, $valid_instructor_roles)) { return true; } //prevent removal from curriculum admin if the user still has an appropriate role in Moodle foreach ($valid_instructor_roles as $valid_instructor_role) { if (user_has_role_assignment($eventdata->userid, $eventdata->roleid, $eventdata->contextid)) { return true; } } //retrieve the course context if (!($course_context = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSE, 'id' => $eventdata->contextid)))) { return true; } //if the course is not tied to any curriculum admin classes, then we are done $associated_classes = $DB->get_recordset(classmoodlecourse::TABLE, array('moodlecourseid' => $course_context->instanceid)); if ($associated_classes->valid() !== true) { return true; } //retrieve the curriculum admin user's id if (!($crlm_userid = pm_get_crlmuserid($eventdata->userid))) { return true; } //clear out instructor assignments in all associated classes foreach ($associated_classes as $associated_class) { if ($instructor_record = $DB->get_record(instructor::TABLE, array('classid' => $associated_class->classid, 'userid' => $crlm_userid))) { $delete_record = new instructor($instructor_record->id); $delete_record->delete(); } } unset($associated_classes); return true; }
/** * Test ignoring user who was manually enrolled and has the instructor role assigned. */ public function test_ignore_instructor_user_not_enrolled_by_elis() { global $DB; $this->resetAfterTest(true); $this->load_csv_data(); $this->set_config_instructor_role(); $enrolinstance = null; // Define user and course objects $user = new stdClass(); $user->id = 101; $context = context_course::instance(100); $course = new stdClass(); $course->id = $context->instanceid; // Enrol user manually and give them the instructor role $role = $DB->get_record('role', array('shortname' => 'teacher')); $plugin = enrol_get_plugin('manual'); $plugin->add_instance($course); $this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id, 'manual'); // Call instructor delete method $instructor = new instructor(array('userid' => 104, 'classid' => 100)); $instructor->delete(); $result = is_enrolled($context, $user, '', true); $this->assertTrue($result); }