예제 #1
0
 /**
  * Delete a course
  * @todo: consider factoring this some more once other actions exist
  *
  * @param object $record One record of import data
  * @param string $filename The import file name, used for logging
  * @return boolean true on success, otherwise false
  */
 function course_delete($record, $filename)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/course.class.php';
     if (isset($record->idnumber)) {
         if (!$DB->record_exists(course::TABLE, array('idnumber' => $record->idnumber))) {
             $identifier = $this->get_field_mapping('idnumber');
             $this->fslogger->log_failure("{$identifier} value of \"{$record->idnumber}\" does not refer to a valid course description.", 0, $filename, $this->linenumber, $record, "course");
             return false;
         }
     }
     if (!$this->validate_course_data('delete', $record, $filename)) {
         return false;
     }
     if ($course = $DB->get_record(course::TABLE, array('idnumber' => $record->idnumber))) {
         $course = new course($course);
         $course->delete();
     }
     //log success
     $success_message = "Course description with idnumber \"{$record->idnumber}\" successfully deleted.";
     $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber);
     return true;
 }
예제 #2
0
 /**
  * Tests contexts in course data object.
  *
  * Covers:
  * local/elisprogram/lib/data/course.class.php:619
  */
 public function test_coursecontexts()
 {
     $this->setup_curriculum();
     $this->setup_curriculumcourse();
     $this->setup_courses();
     $crs = new course(100);
     $crs->delete();
 }
예제 #3
0
 /**
  * Performs course delete
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error creating the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function course_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::course_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Validate course exists.
     if (!($crsid = $DB->get_field(course::TABLE, 'id', array('idnumber' => $data->idnumber)))) {
         throw new data_object_exception('ws_course_delete_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:course_delete', \local_elisprogram\context\course::instance($crsid));
     $course = new course($crsid);
     $course->delete();
     // Confirm delete & respond.
     if (!$DB->record_exists(course::TABLE, array('id' => $crsid))) {
         return array('messagecode' => get_string('ws_course_delete_success_code', 'local_datahub'), 'message' => get_string('ws_course_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_course_delete_fail', 'local_datahub');
     }
 }