Basic delete outage entry implemented. Still missing rules on which ones can be deleted.

This commit is contained in:
Daniel Thee Roperto
2016-08-31 16:48:21 +10:00
parent 9e1b5e8315
commit 1dafbc8672
4 changed files with 154 additions and 6 deletions

View File

@@ -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]);
}
}

View 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;
}
}