diff --git a/classes/forms/outage/delete.php b/classes/forms/outage/delete.php index 26139fa..23cbcd9 100644 --- a/classes/forms/outage/delete.php +++ b/classes/forms/outage/delete.php @@ -41,7 +41,7 @@ class delete extends \moodleform { $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); - $this->add_action_buttons(true, get_string('remove')); + $this->add_action_buttons(true, get_string('delete')); } /** diff --git a/classes/outagedb.php b/classes/outagedb.php index a731367..2b13d88 100644 --- a/classes/outagedb.php +++ b/classes/outagedb.php @@ -14,20 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace auth_outage; + +use auth_outage\models\outage; + /** - * The DB Context to manipulate Outages. Singleton class. + * The DB Context to manipulate Outages. * * @package auth_outage * @author Daniel Thee Roperto * @copyright Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace auth_outage; - -use auth_outage\models\outage; - -final class outagedb { +class outagedb { /** * Private constructor, use static methods instead. */ @@ -37,7 +36,7 @@ final class outagedb { /** * Gets all outage entries. */ - public static function getall() { + public static function get_all() { global $DB; $outages = []; @@ -55,7 +54,7 @@ final class outagedb { * @param $id int Outage id to get. * @return outage|null Returns the outage or null if not found. */ - public static function getbyid($id) { + public static function get_by_id($id) { global $DB; if (!is_int($id)) { @@ -144,7 +143,7 @@ final class outagedb { * @param int|null $time Timestamp considered to check for outages, null for current date/time. * @return outage|null The outage or null if no active outages were found. */ - public static function getactive($time = null) { + public static function get_active($time = null) { global $DB; if ($time === null) { diff --git a/classes/outagelib.php b/classes/outagelib.php index a6081b7..b35cfb7 100644 --- a/classes/outagelib.php +++ b/classes/outagelib.php @@ -65,7 +65,7 @@ class outagelib { } self::$initialized = true; - if (($active = outagedb::getactive()) == null) { + if (($active = outagedb::get_active()) == null) { return; } diff --git a/remove.php b/delete.php similarity index 93% rename from remove.php rename to delete.php index b5db3f0..f5ca3cb 100644 --- a/remove.php +++ b/delete.php @@ -35,14 +35,14 @@ $renderer = outagelib::pagesetup(); $mform = new \auth_outage\forms\outage\delete(); if ($mform->is_cancelled()) { - redirect('/auth/outage/list.php'); + redirect('/auth/outage/manage.php'); } else if ($fromform = $mform->get_data()) { outagedb::delete($fromform->id); - redirect('/auth/outage/list.php'); + redirect('/auth/outage/manage.php'); } $id = required_param('id', PARAM_INT); -$outage = outagedb::getbyid($id); +$outage = outagedb::get_by_id($id); if ($outage == null) { throw new invalid_parameter_exception('Outage #' . $id . ' not found.'); } diff --git a/change.php b/edit.php similarity index 90% rename from change.php rename to edit.php index af70983..0e44b3e 100644 --- a/change.php +++ b/edit.php @@ -36,16 +36,16 @@ $renderer = outagelib::pagesetup(); $mform = new \auth_outage\forms\outage\edit(); if ($mform->is_cancelled()) { - redirect('/auth/outage/list.php'); + redirect('/auth/outage/manage.php'); } else if ($fromform = $mform->get_data()) { $fromform = outagelib::parseformdata($fromform); $outage = new outage($fromform); $id = outagedb::save($outage); - redirect('/auth/outage/list.php#auth_outage_id_' . $id); + redirect('/auth/outage/manage.php#auth_outage_id_' . $id); } $id = required_param('id', PARAM_INT); -$outage = outagedb::getbyid($id); +$outage = outagedb::get_by_id($id); if ($outage == null) { throw new invalid_parameter_exception('Outage #' . $id . ' not found.'); } @@ -55,6 +55,6 @@ $mform->set_data($data); $PAGE->navbar->add($outage->title); echo $OUTPUT->header(); -echo $renderer->rendersubtitle('modifyoutage'); +echo $renderer->rendersubtitle('outageedit'); $mform->display(); echo $OUTPUT->footer(); diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index efe9311..2200137 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -34,11 +34,10 @@ $string['menudefaults'] = 'Default Settings'; $string['menumanage'] = 'Manage'; $string['messageoutageongoing'] = 'Our system will be under maintenance until {$a->stop}.'; $string['messageoutagewarning'] = 'There is an scheduled downtime from {$a->start} until {$a->stop}.'; -$string['modify'] = 'Modify'; -$string['modifyoutage'] = 'Modify Outage'; +$string['outageedit'] = 'Edit Outage'; $string['outagecreate'] = 'Create Outage'; -$string['outageremove'] = 'Remove Outage'; -$string['outageremovewarning'] = 'You are about to permanently remove the outage below. This cannot be undone.'; +$string['outagedelete'] = 'Delete Outage'; +$string['outagedeletewarning'] = 'You are about to permanently delete the outage below. This cannot be undone.'; $string['outageslist'] = 'Outages List'; $string['pluginname'] = 'Outage'; $string['starttimeerrornotinfuture'] = 'Start time must be in the future.'; diff --git a/lib.php b/lib.php index 31903ec..c89f4d6 100644 --- a/lib.php +++ b/lib.php @@ -24,7 +24,7 @@ */ defined('MOODLE_INTERNAL') || die; -// FIXME hook not installing in courses/index.php page. +// FIXME hook not installing in courses/index.php page as guest. function auth_outage_extend_navigation_user() { \auth_outage\outagelib::inject(); diff --git a/list.php b/manage.php similarity index 95% rename from list.php rename to manage.php index dd2c840..d5af095 100644 --- a/list.php +++ b/manage.php @@ -33,6 +33,6 @@ $renderer = outagelib::pagesetup(); echo $OUTPUT->header(); -echo $renderer->renderoutagelist(outagedb::getall()); +echo $renderer->renderoutagelist(outagedb::get_all()); echo $OUTPUT->footer(); diff --git a/create.php b/new.php similarity index 93% rename from create.php rename to new.php index 329a938..e6fb30d 100644 --- a/create.php +++ b/new.php @@ -35,12 +35,12 @@ outagelib::pagesetup(); $mform = new \auth_outage\forms\outage\edit(); if ($mform->is_cancelled()) { - redirect('/auth/outage/list.php'); + redirect('/auth/outage/manage.php'); } else if ($fromform = $mform->get_data()) { $fromform = outagelib::parseformdata($fromform); $outage = new outage($fromform); $id = outagedb::save($outage); - redirect('/auth/outage/list.php#auth_outage_id_' . $id); + redirect('/auth/outage/manage.php#auth_outage_id_' . $id); } $PAGE->navbar->add(get_string('outagecreate', 'auth_outage')); diff --git a/renderer.php b/renderer.php index 18d6444..d50bc15 100644 --- a/renderer.php +++ b/renderer.php @@ -38,8 +38,8 @@ class auth_outage_renderer extends plugin_renderer_base { } public function renderdeleteconfirmation(outage $outage) { - return $this->rendersubtitle('outageremove') - . html_writer::tag('p', get_string('outageremovewarning', 'auth_outage')) + return $this->rendersubtitle('outagedelete') + . html_writer::tag('p', get_string('outagedeletewarning', 'auth_outage')) . $this->renderoutage($outage, false); } @@ -54,14 +54,14 @@ class auth_outage_renderer extends plugin_renderer_base { } // Add 'add' button. - $url = new moodle_url('/auth/outage/create.php'); + $url = new moodle_url('/auth/outage/new.php'); $img = html_writer::empty_tag('img', ['src' => $OUTPUT->pix_url('t/add'), 'alt' => get_string('create'), 'class' => 'iconsmall']); $html .= html_writer::tag('p', html_writer::link( $url, $img . ' ' . get_string('outagecreate', 'auth_outage'), - ['title' => get_string('remove')] + ['title' => get_string('delete')] ) ); @@ -83,19 +83,19 @@ class auth_outage_renderer extends plugin_renderer_base { trim($modified->firstname . ' ' . $modified->lastname) ); - $url = new moodle_url('/auth/outage/change.php', ['id' => $outage->id]); + $url = new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]); $img = html_writer::empty_tag( 'img', - ['src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('modify', 'auth_outage'), 'class' => 'iconsmall'] + ['src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall'] ); - $linkedit = html_writer::link($url, $img, ['title' => get_string('modify', 'auth_outage')]); + $linkedit = html_writer::link($url, $img, ['title' => get_string('edit')]); - $url = new moodle_url('/auth/outage/remove.php', ['id' => $outage->id]); + $url = new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]); $img = html_writer::empty_tag( 'img', - ['src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('remove'), 'class' => 'iconsmall'] + ['src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall'] ); - $linkdelete = html_writer::link($url, $img, ['title' => get_string('remove')]); + $linkdelete = html_writer::link($url, $img, ['title' => get_string('delete')]); // TODO use language pack below, solve together with Issue #12. return html_writer::div( diff --git a/settings.php b/settings.php index 7e2361e..61dfc18 100644 --- a/settings.php +++ b/settings.php @@ -50,7 +50,7 @@ if ($hassiteconfig && is_enabled_auth('outage')) { new admin_externalpage( 'auth_outage_manage', get_string('menumanage', 'auth_outage'), - new moodle_url($CFG->wwwroot . '/auth/outage/list.php') + new moodle_url($CFG->wwwroot . '/auth/outage/manage.php') ) ); } diff --git a/tests/outagedb_test.php b/tests/outagedb_test.php index 77704f1..30a2ab0 100644 --- a/tests/outagedb_test.php +++ b/tests/outagedb_test.php @@ -51,12 +51,12 @@ class outagedb_test extends advanced_testcase { // Create something. $id = outagedb::save($this->createoutage(1)); // Get should work. - $outage = outagedb::getbyid($id); + $outage = outagedb::get_by_id($id); self::assertNotNull($outage); // Delete it. outagedb::delete($id); // Get should be null. - $outage = outagedb::getbyid($id); + $outage = outagedb::get_by_id($id); self::assertNull($outage); } @@ -70,7 +70,7 @@ class outagedb_test extends advanced_testcase { // Delete it. outagedb::delete($id); // Should not exist anymore. - self::assertNull(outagedb::getbyid($id)); + self::assertNull(outagedb::get_by_id($id)); } /** @@ -80,14 +80,14 @@ class outagedb_test extends advanced_testcase { $this->resetAfterTest(true); $amount = 10; // Should start empty. - $outages = outagedb::getall(); + $outages = outagedb::get_all(); self::assertSame([], $outages); // Create some stuff outages. for ($i = 0; $i < $amount; $i++) { outagedb::save($this->createoutage($i)); } // Count entries created. - self::assertSame($amount, count(outagedb::getall())); + self::assertSame($amount, count(outagedb::get_all())); } /** @@ -107,7 +107,7 @@ class outagedb_test extends advanced_testcase { // With all created outages. foreach ($outages as $id => $outage) { // Get it. - $inserted = outagedb::getbyid($id); + $inserted = outagedb::get_by_id($id); self::assertNotNull($inserted); // Check its data. foreach (['starttime', 'stoptime', 'warningduration', 'title', 'description'] as $field) { @@ -122,12 +122,12 @@ class outagedb_test extends advanced_testcase { $inserted->title = 'Title ID' . $id; outagedb::save($inserted); // Get it again and check data. - $updated = outagedb::getbyid($id); + $updated = outagedb::get_by_id($id); self::assertSame('Title ID' . $id, $updated->title); self::assertSame($inserted->description, $updated->description); // Delete it. outagedb::delete($id); - $deleted = outagedb::getbyid($id); + $deleted = outagedb::get_by_id($id); self::assertNull($deleted); } } @@ -139,36 +139,36 @@ class outagedb_test extends advanced_testcase { $now = time(); // Should never fail. - self::assertEquals([], outagedb::getall(), 'Ensure there are no other outages that can affect the test.'); - self::assertNull(outagedb::getactive($now), 'There should be no active outage at this point.'); + self::assertEquals([], outagedb::get_all(), 'Ensure there are no other outages that can affect the test.'); + self::assertNull(outagedb::get_active($now), 'There should be no active outage at this point.'); // An outage that starts in the future and is not in warning period. self::saveoutage($now, 2, 3, 1); - self::assertNull(outagedb::getactive($now), 'No active outages yet.'); + self::assertNull(outagedb::get_active($now), 'No active outages yet.'); // An outage that is already in the past. self::saveoutage($now, -3, -2, 1); - self::assertNull(outagedb::getactive($now), 'No active outages yet.'); + self::assertNull(outagedb::get_active($now), 'No active outages yet.'); // An outage in warning period. $activeid = self::saveoutage($now, 1, 2, 2); - self::assertSame($activeid, outagedb::getactive($now)->id, 'Wrong active outage picked.'); + self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.'); // Another outage in warning period, but ignored as it starts after the previous one. self::saveoutage($now, 2, 3, 3); - self::assertSame($activeid, outagedb::getactive($now)->id, 'Wrong active outage picked.'); + self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.'); // An ongoing outage. $activeid = self::saveoutage($now, -2, 2, 1); - self::assertSame($activeid, outagedb::getactive($now)->id, 'Wrong active outage picked.'); + self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.'); // Another ongoing outage but ignored because it started after the previous one. self::saveoutage($now, -1, 2, 1); - self::assertSame($activeid, outagedb::getactive($now)->id, 'Wrong active outage picked.'); + self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.'); // Another ongoing outage starting at the same time, but ignored as it stops before the previous one. self::saveoutage($now, -2, 1, 1); - self::assertSame($activeid, outagedb::getactive($now)->id, 'Wrong active outage picked.'); + self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.'); } /**