/** * Performs class deletion * @throws moodle_exception If there was an error in passed parameters. * @throws data_object_exception If there was an error deleting the entity. * @param array $data The incoming data parameter. * @return array An array of parameters, if successful. */ public static function class_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::class_delete_parameters(), array('data' => $data)); // Context validation. $context = context_user::instance($USER->id); self::validate_context($context); // Initialize version1elis importplugin for utility functions. $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis'); // Get the class. $clsid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $data['idnumber'])); if (empty($clsid)) { throw new data_object_exception('ws_class_delete_fail_invalid_idnumber', 'local_datahub', '', $data); } // Capability checking. require_capability('local/elisprogram:class_delete', \local_elisprogram\context\pmclass::instance($clsid)); // Delete the class. $pmclass = new pmclass($clsid); $pmclass->delete(); // Verify class deleted & respond. if (!$DB->record_exists(pmclass::TABLE, array('id' => $clsid))) { return array('messagecode' => get_string('ws_class_delete_success_code', 'local_datahub'), 'message' => get_string('ws_class_delete_success_msg', 'local_datahub')); } else { throw new data_object_exception('ws_class_delete_fail', 'local_datahub'); } }
/** * Tests contexts in pmclass data object. * * Covers: * local/elisprogram/lib/data/pmclass.class.php:259 */ public function test_classcontexts() { $this->setup_curriculum(); $this->setup_curriculumcourse(); $this->setup_courses(); $this->setup_classes(); $pmclass = new pmclass(101); $pmclass->delete(); }
function class_delete($record, $filename) { global $DB, $CFG; if (isset($record->idnumber)) { if (!$DB->record_exists(pmclass::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 class instance.", 0, $filename, $this->linenumber, $record, "class"); return false; } } if ($course = $DB->get_record(pmclass::TABLE, array('idnumber' => $record->idnumber))) { $course = new pmclass($course); $course->delete(); } //log success $success_message = "Class instance with idnumber \"{$record->idnumber}\" successfully deleted."; $this->fslogger->log_success($success_message, 0, $filename, $this->linenumber); return true; }