From 4e46e934d0b897247a3ea0210cf27fdee8898a21 Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Thu, 8 Sep 2016 17:25:28 +1000 Subject: [PATCH] WIP Issue #17 - Settings page done, missing forms and other references to warning duration and stop time. --- classes/forms/outage/edit.php | 4 +++- classes/models/outage.php | 8 ++++---- classes/outagedb.php | 2 +- db/install.xml | 4 ++-- lang/en/auth_outage.php | 20 +++++++++++++------- new.php | 10 ++++++++++ renderer.php | 2 +- settings.php | 30 +++++++++++++++++++++--------- tests/outagedb_test.php | 2 +- 9 files changed, 56 insertions(+), 26 deletions(-) diff --git a/classes/forms/outage/edit.php b/classes/forms/outage/edit.php index 26d3c77..21512e5 100644 --- a/classes/forms/outage/edit.php +++ b/classes/forms/outage/edit.php @@ -45,7 +45,7 @@ class edit extends \moodleform { $mform->addElement('date_time_selector', 'starttime', get_string('starttime', 'auth_outage')); - $mform->addElement('date_time_selector', 'stoptime', get_string('stoptime', 'auth_outage')); + $mform->addElement('duration', 'outageduration', get_string('outageduration', 'auth_outage')); $mform->addElement('duration', 'warningduration', get_string('warningduration', 'auth_outage')); @@ -59,6 +59,8 @@ class edit extends \moodleform { $mform->addElement('editor', 'description', get_string('description', 'auth_outage')); + $mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage')); + $this->add_action_buttons(); } diff --git a/classes/models/outage.php b/classes/models/outage.php index 7827e38..6eb68fc 100644 --- a/classes/models/outage.php +++ b/classes/models/outage.php @@ -44,9 +44,9 @@ class outage { public $stoptime = null; /** - * @var int Amount of minutes before outage starts to show the warning message. + * @var int Warning start timestamp. */ - public $warningduration = null; + public $warntime = null; /** * @var string Short description of the outage (no HTML). @@ -85,8 +85,8 @@ class outage { if (is_object($data) || is_array($data)) { outagelib::data2object($data, $this); - // FIXME types are wrong. Is this behaving as expected? - $fields = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warningduration']; + // Adjust field types as needed. + $fields = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warntime']; foreach ($fields as $f) { $this->$f = ($this->$f === null) ? null : (int)$this->$f; } diff --git a/classes/outagedb.php b/classes/outagedb.php index 2b13d88..99fd2d4 100644 --- a/classes/outagedb.php +++ b/classes/outagedb.php @@ -158,7 +158,7 @@ class outagedb { // Gets only one record if available, the one that starts(ed) first and that stops last. $data = $DB->get_records_select( 'auth_outage', - '(starttime - warningduration <= :datetime1 AND stoptime >= :datetime2)', + '(warntime <= :datetime1 AND stoptime >= :datetime2)', ['datetime1' => $time, 'datetime2' => $time], 'starttime ASC, stoptime DESC, title ASC', '*', diff --git a/db/install.xml b/db/install.xml index f375742..7f6326b 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -9,7 +9,7 @@ - + diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index d158959..82cf8c9 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -26,12 +26,17 @@ $string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a future outage and prevents them from logging in once the outage starts.'; $string['defaultlayoutcss'] = 'Layout CSS'; $string['defaultlayoutcssdescription'] = 'This CSS code will be used to display the Outage Warning Bar.'; -$string['defaultwarningmessage'] = 'Default Warning Message'; -$string['defaultwarningmessagedescription'] = 'Default warning message for outages. Use [from] and [until] placeholders as required.'; -$string['defaultwarningmessagevalue'] = 'There is an scheduled maintenance from [from] to [until] and our system will not be available during that time.'; -$string['defaultwarningtime'] = 'Default Warning Time'; -$string['defaultwarningtimedescription'] = 'Default warning time (in minutes) for outages.'; -$string['description'] = 'Public description'; +$string['defaultoutageduration'] = 'Outage Duration'; +$string['defaultoutagedurationdescription'] = 'Default duration (in minutes) of an outage.'; +$string['defaultwarningduration'] = 'Warning Duration'; +$string['defaultwarningdurationdescription'] = 'Default warning time (in minutes) for outages.'; +$string['defaultwarningtitle'] = 'Title'; +$string['defaultwarningtitledescription'] = 'Default title for outages. Use {{start}} and {{stop}} placeholders as required.'; +$string['defaultwarningtitlevalue'] = 'System down from {{start}} to {{stop}}.'; +$string['defaultwarningdescription'] = 'Description'; +$string['defaultwarningdescriptiondescription'] = 'Default warning message for outages. Use {{start}} and {{stop}} placeholders as required.'; +$string['defaultwarningdescriptionvalue'] = 'There is an scheduled maintenance from {{start}} to {{stop}} and our system will not be available during that time.'; +$string['description'] = 'Public Description'; $string['menudefaults'] = 'Default Settings'; $string['menumanage'] = 'Manage'; $string['messageoutageongoing'] = 'Our system will be under maintenance until {$a->stop}.'; @@ -40,11 +45,12 @@ $string['outageedit'] = 'Edit Outage'; $string['outagecreate'] = 'Create Outage'; $string['outagedelete'] = 'Delete Outage'; $string['outagedeletewarning'] = 'You are about to permanently delete the outage below. This cannot be undone.'; +$string['outageduration'] = 'Outage Duration'; $string['outageslist'] = 'Outages List'; $string['pluginname'] = 'Outage manager'; $string['starttime'] = 'Start date and time'; $string['stoptimeerrornotafterstart'] = 'Stop time must be after start time.'; -$string['stoptime'] = 'Stop date and time'; +$string['textplaceholdershint'] = 'You can use {{start}} and {{stop}} as placeholders on the title/description for the actual start/stop time.'; $string['titleerrorinvalid'] = 'Title cannot be left blank.'; $string['titleerrortoolong'] = 'Title cannot have more than {$a} characters.'; $string['title'] = 'Title'; diff --git a/new.php b/new.php index e6fb30d..b60d9d9 100644 --- a/new.php +++ b/new.php @@ -43,6 +43,16 @@ if ($mform->is_cancelled()) { redirect('/auth/outage/manage.php#auth_outage_id_' . $id); } +$config = get_config('auth_outage'); +$defaults = [ + 'starttime' => time(), + 'outageduration' => ($config->default_duration * 60), + 'warningduration' => ($config->warning_duration * 60), + 'title' => $config->warning_title, + 'description' => ['text' => $config->warning_description, 'format' => '1'] +]; +$mform->set_data($defaults); + $PAGE->navbar->add(get_string('outagecreate', 'auth_outage')); echo $OUTPUT->header(); diff --git a/renderer.php b/renderer.php index a925b7e..c0928c9 100644 --- a/renderer.php +++ b/renderer.php @@ -105,7 +105,7 @@ class auth_outage_renderer extends plugin_renderer_base { . html_writer::tag('i', $outage->description) . html_writer::empty_tag('br') . html_writer::tag('b', 'Warning: ') - . userdate($outage->starttime - ($outage->warningduration * 60)) + . userdate($outage->warntime, '%d %h %Y %l:%M%P') . html_writer::empty_tag('br') . html_writer::tag('b', 'Starts: ') . userdate($outage->starttime, '%d %h %Y %l:%M%P') diff --git a/settings.php b/settings.php index aca99c7..b6c0b94 100644 --- a/settings.php +++ b/settings.php @@ -28,19 +28,31 @@ if ($hassiteconfig && is_enabled_auth('outage')) { // Configure default settings page. $settings->visiblename = get_string('menudefaults', 'auth_outage'); $settings->add( - new admin_setting_configtext('auth_outage_warning_period', - get_string('defaultwarningtime', 'auth_outage'), - get_string('defaultwarningtimedescription', 'auth_outage'), - 120, PARAM_INT)); + new admin_setting_configtext('auth_outage/default_duration', + get_string('defaultoutageduration', 'auth_outage'), + get_string('defaultoutagedurationdescription', 'auth_outage'), + 60, PARAM_INT)); $settings->add( - new admin_setting_configtextarea('auth_outage_warning_text', - get_string('defaultwarningmessage', 'auth_outage'), - get_string('defaultwarningmessagedescription', 'auth_outage'), - get_string('defaultwarningmessagevalue', 'auth_outage'), + new admin_setting_configtext('auth_outage/warning_duration', + get_string('defaultwarningduration', 'auth_outage'), + get_string('defaultwarningdurationdescription', 'auth_outage'), + 60, PARAM_INT)); + $settings->add( + new admin_setting_configtext('auth_outage/warning_title', + get_string('defaultwarningtitle', 'auth_outage'), + get_string('defaultwarningtitledescription', 'auth_outage'), + get_string('defaultwarningtitlevalue', 'auth_outage'), PARAM_TEXT) ); $settings->add( - new admin_setting_configtextarea('auth_outage_css', + new admin_setting_configtextarea('auth_outage/warning_description', + get_string('defaultwarningdescription', 'auth_outage'), + get_string('defaultwarningdescriptiondescription', 'auth_outage'), + get_string('defaultwarningdescriptionvalue', 'auth_outage'), + PARAM_TEXT) + ); + $settings->add( + new admin_setting_configtextarea('auth_outage/css', get_string('defaultlayoutcss', 'auth_outage'), get_string('defaultlayoutcssdescription', 'auth_outage'), file_get_contents($CFG->dirroot.'/auth/outage/res/default.css'), diff --git a/tests/outagedb_test.php b/tests/outagedb_test.php index 30a2ab0..0c01258 100644 --- a/tests/outagedb_test.php +++ b/tests/outagedb_test.php @@ -184,7 +184,7 @@ class outagedb_test extends advanced_testcase { return outagedb::save(new outage([ 'starttime' => $now + ($start * 60 * 60), 'stoptime' => $now + ($stop * 60 * 60), - 'warningduration' => ($warning * 60 * 60), + 'warntime' => $now - ($warning * 60 * 60), 'title' => 'Test Outage', 'description' => 'Test Outage Description.' ]));