mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #46 - Merged new, edit and clone into a single page. Moodle code checker was complaining about duplicated code and it was right!
This commit is contained in:
committed by
Daniel Thee Roperto
parent
8791727ba4
commit
6a78557487
@@ -78,7 +78,7 @@ class base_table extends flexible_table {
|
||||
// Edit button if required.
|
||||
if ($editdelete) {
|
||||
$buttons .= html_writer::link(
|
||||
new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
new moodle_url('/auth/outage/edit.php', ['edit' => $outage->id]),
|
||||
html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/edit'),
|
||||
'alt' => get_string('edit'),
|
||||
@@ -90,7 +90,7 @@ class base_table extends flexible_table {
|
||||
|
||||
// Clone button.
|
||||
$buttons .= html_writer::link(
|
||||
new moodle_url('/auth/outage/clone.php', ['id' => $outage->id]),
|
||||
new moodle_url('/auth/outage/edit.php', ['clone' => $outage->id]),
|
||||
html_writer::empty_tag('img', [
|
||||
'src' => $OUTPUT->pix_url('t/copy'),
|
||||
'alt' => get_string('clone', 'auth_outage'),
|
||||
|
||||
@@ -170,7 +170,7 @@ class renderer extends plugin_renderer_base {
|
||||
);
|
||||
}
|
||||
|
||||
$url = new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]);
|
||||
$url = new moodle_url('/auth/outage/edit.php', ['edit' => $outage->id]);
|
||||
$img = html_writer::empty_tag(
|
||||
'img',
|
||||
['src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall']
|
||||
|
||||
60
clone.php
60
clone.php
@@ -1,60 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Clone outage.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\form\outage\edit;
|
||||
use auth_outage\output\renderer;
|
||||
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
|
||||
$mform = new edit();
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($outage = $mform->get_data()) {
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$outage = outagedb::get_by_id($id);
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage #'.$id.' not found.');
|
||||
}
|
||||
|
||||
// Remove outage id to force creating a new one.
|
||||
$outage->id = null;
|
||||
$mform->set_data($outage);
|
||||
|
||||
$PAGE->navbar->add($outage->get_title());
|
||||
echo $OUTPUT->header();
|
||||
echo renderer::get()->rendersubtitle('outageclone');
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
42
edit.php
42
edit.php
@@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Create new outage.
|
||||
* Edit an outage.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\form\outage\edit;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagelib;
|
||||
use auth_outage\output\renderer;
|
||||
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
@@ -43,15 +45,41 @@ if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$outage = outagedb::get_by_id($id);
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage #'.$id.' not found.');
|
||||
$clone = optional_param('clone', 0, PARAM_INT);
|
||||
$edit = optional_param('edit', 0, PARAM_INT);
|
||||
if ($clone && $edit) {
|
||||
throw new invalid_parameter_exception('Cannot provide both clone and edit ids.');
|
||||
}
|
||||
if ($clone) {
|
||||
// Remove outage id to force creating a new one.
|
||||
$outage = outagedb::get_by_id($clone);
|
||||
$outage->id = null;
|
||||
$action = 'outageclone';
|
||||
} else if ($edit) {
|
||||
$outage = outagedb::get_by_id($edit);
|
||||
$action = 'outageedit';
|
||||
} else {
|
||||
$config = outagelib::get_config();
|
||||
$time = time();
|
||||
$outage = new outage([
|
||||
'autostart' => $config->default_autostart,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + $config->default_duration,
|
||||
'warntime' => $time - $config->default_warning_duration,
|
||||
'title' => $config->default_title,
|
||||
'description' => $config->default_description,
|
||||
]);
|
||||
$action = 'outagecreate';
|
||||
}
|
||||
|
||||
if ($outage == null) {
|
||||
throw new invalid_parameter_exception('Outage not found.');
|
||||
}
|
||||
|
||||
$mform->set_data($outage);
|
||||
|
||||
$PAGE->navbar->add($outage->get_title());
|
||||
$PAGE->navbar->add(get_string($action.'crumb', 'auth_outage'));
|
||||
echo $OUTPUT->header();
|
||||
echo renderer::get()->rendersubtitle('outageedit');
|
||||
echo renderer::get()->rendersubtitle($action);
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -93,8 +93,11 @@ $string['messageoutagewarning'] = 'Shutting down in {{countdown}}';
|
||||
$string['na'] = 'n/a';
|
||||
$string['notfound'] = 'No outages found.';
|
||||
$string['outageedit'] = 'Edit Outage';
|
||||
$string['outageeditcrumb'] = 'Edit';
|
||||
$string['outageclone'] = 'Clone Outage';
|
||||
$string['outageclonecrumb'] = 'Clone';
|
||||
$string['outagecreate'] = 'Create Outage';
|
||||
$string['outagecreatecrumb'] = 'Create';
|
||||
$string['outagedelete'] = 'Delete Outage';
|
||||
$string['outagedeletewarning'] = 'You are about to permanently delete the outage below. This cannot be undone.';
|
||||
$string['outageduration'] = 'Outage Duration';
|
||||
|
||||
62
new.php
62
new.php
@@ -1,62 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Create new outage.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\form\outage\edit;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
|
||||
$mform = new edit();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($outage = $mform->get_data()) {
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
}
|
||||
|
||||
$config = outagelib::get_config();
|
||||
$defaults = new outage([
|
||||
'autostart' => $config->default_autostart,
|
||||
'starttime' => time(),
|
||||
'stoptime' => time() + $config->default_duration,
|
||||
'warntime' => time() - $config->default_warning_duration,
|
||||
'title' => $config->default_title,
|
||||
'description' => $config->default_description,
|
||||
]);
|
||||
$mform->set_data($defaults);
|
||||
|
||||
$PAGE->navbar->add(get_string('outagecreate', 'auth_outage'));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$mform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
@@ -67,7 +67,7 @@ class behat_auth_outage extends behat_base {
|
||||
* @Given /^I visit the Create Outage Page$/
|
||||
*/
|
||||
public function i_visit_the_create_outage_page() {
|
||||
$this->getSession()->visit($this->locate_path('/auth/outage/new.php'));
|
||||
$this->getSession()->visit($this->locate_path('/auth/outage/edit.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@ if ($viewbag['admin']) {
|
||||
}
|
||||
|
||||
$admineditlink = html_writer::link(
|
||||
new moodle_url('/auth/outage/edit.php', ['id' => $viewbag['outage']->id]),
|
||||
new moodle_url('/auth/outage/edit.php', ['edit' => $viewbag['outage']->id]),
|
||||
get_string('outageedit', 'auth_outage')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ use auth_outage\output\renderer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$urlnew = new moodle_url('/auth/outage/new.php');
|
||||
$urlnew = new moodle_url('/auth/outage/edit.php');
|
||||
?>
|
||||
|
||||
<section id="section_planned_outages">
|
||||
|
||||
Reference in New Issue
Block a user