Renamed methods, files and language keywords in order to match Moodle style. Issue #16

This commit is contained in:
Daniel Thee Roperto
2016-09-07 11:31:58 +10:00
parent 4ff0e8fbcf
commit 2a120f0ebe
12 changed files with 53 additions and 55 deletions

View File

@@ -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'));
}
/**

View File

@@ -14,20 +14,19 @@
// 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;
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 <daniel.roperto@catalyst-au.net>
* @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) {

View File

@@ -65,7 +65,7 @@ class outagelib {
}
self::$initialized = true;
if (($active = outagedb::getactive()) == null) {
if (($active = outagedb::get_active()) == null) {
return;
}

View File

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

View File

@@ -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();

View File

@@ -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.';

View File

@@ -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();

View File

@@ -33,6 +33,6 @@ $renderer = outagelib::pagesetup();
echo $OUTPUT->header();
echo $renderer->renderoutagelist(outagedb::getall());
echo $renderer->renderoutagelist(outagedb::get_all());
echo $OUTPUT->footer();

View File

@@ -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'));

View File

@@ -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(

View File

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

View File

@@ -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.');
}
/**