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