mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Basic delete outage entry implemented. Still missing rules on which ones can be deleted.
This commit is contained in:
@@ -88,8 +88,12 @@ final class outagedb
|
||||
public function getbyid($id) {
|
||||
global $DB;
|
||||
|
||||
if (!is_int($id)) throw new InvalidArgumentException('$id must be an int.');
|
||||
if ($id <= 0) throw new InvalidArgumentException('$id must be positive.');
|
||||
if (!is_int($id)) {
|
||||
throw new InvalidArgumentException('$id must be an int.');
|
||||
}
|
||||
if ($id <= 0) {
|
||||
throw new InvalidArgumentException('$id must be positive.');
|
||||
}
|
||||
|
||||
$outage = $DB->get_record('auth_outage', ['id' => $id]);
|
||||
if ($outage === false) {
|
||||
@@ -130,4 +134,22 @@ final class outagedb
|
||||
$DB->update_record('auth_outage', $outage);
|
||||
return $outage->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an outage from the database.
|
||||
*
|
||||
* @param $id Outage ID to delete
|
||||
*/
|
||||
public function delete($id) {
|
||||
global $DB;
|
||||
|
||||
if (!is_int($id)) {
|
||||
throw new InvalidArgumentException('$id must be an int.');
|
||||
}
|
||||
if ($id <= 0) {
|
||||
throw new InvalidArgumentException('$id must be positive.');
|
||||
}
|
||||
|
||||
$DB->delete_records('auth_outage', ['id' => $id]);
|
||||
}
|
||||
}
|
||||
61
classes/outagedeleteform.php
Normal file
61
classes/outagedeleteform.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
}
|
||||
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
/**
|
||||
* Outage delete confirmation form.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outagedeleteform extends \moodleform {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see moodleform::definition()
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$this->add_action_buttons(true, 'Remove');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the parts of the request form for this module
|
||||
*
|
||||
* @param array $data An array of form data
|
||||
* @param array $files An array of form files
|
||||
* @return array of error messages
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
$mform = $this->_form;
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user