mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +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;
|
||||
}
|
||||
|
||||
}
|
||||
61
remove.php
Normal file
61
remove.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/>.
|
||||
|
||||
/**
|
||||
* Delete an outage.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
use \auth_outage\outage;
|
||||
use \auth_outage\outageutils;
|
||||
use \auth_outage\outagedb;
|
||||
use \auth_outage\outagedeleteform;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
$renderer = outageutils::pagesetup();
|
||||
|
||||
$mform = new outagedeleteform();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/list.php');
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
outagedb::get()->delete($fromform->id);
|
||||
redirect('/auth/outage/list.php');
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$outage = outagedb::get()->getbyid($id);
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage #' . $id . ' not found.');
|
||||
}
|
||||
|
||||
$dataid = new stdClass();
|
||||
$dataid->id = $outage->id;
|
||||
$mform->set_data($dataid);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $renderer->renderdeleteconfirmation($outage);
|
||||
|
||||
$mform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
12
renderer.php
12
renderer.php
@@ -31,6 +31,11 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
*/
|
||||
class auth_outage_renderer extends plugin_renderer_base
|
||||
{
|
||||
public function renderdeleteconfirmation(outage $outage) {
|
||||
return html_writer::tag('h3', 'You are about to remove the following outage:')
|
||||
. $this->renderoutage($outage, false);
|
||||
}
|
||||
|
||||
public function renderoutagelist(array $outages) {
|
||||
global $OUTPUT;
|
||||
|
||||
@@ -38,7 +43,7 @@ class auth_outage_renderer extends plugin_renderer_base
|
||||
|
||||
// Generate list of outages.
|
||||
foreach ($outages as $outage) {
|
||||
$html .= $this->renderoutagelistentry($outage);
|
||||
$html .= $this->renderoutage($outage, true);
|
||||
}
|
||||
|
||||
// Add 'add' button.
|
||||
@@ -52,7 +57,7 @@ class auth_outage_renderer extends plugin_renderer_base
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function renderoutagelistentry(outage $outage) {
|
||||
private function renderoutage(outage $outage, $buttons) {
|
||||
global $OUTPUT;
|
||||
|
||||
$created = core_user::get_user($outage->createdby, 'firstname,lastname', MUST_EXIST);
|
||||
@@ -98,8 +103,7 @@ class auth_outage_renderer extends plugin_renderer_base
|
||||
. userdate($outage->lastmodified, '%d %h %Y %l:%M%P')
|
||||
)
|
||||
. html_writer::empty_tag('br')
|
||||
. $linkedit . $linkdelete
|
||||
. html_writer::empty_tag('br')
|
||||
. ($buttons ? $linkedit . $linkdelete . html_writer::empty_tag('br') : '')
|
||||
. html_writer::empty_tag('br')
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user