From 97140dccf76f878991853d827449ca608eb91864 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 18 Nov 2017 06:31:25 +0400 Subject: Aesthetics in the code --- classes/editform.php | 6 +++--- classes/event/response_get.php | 4 ++-- classes/handler.php | 9 +++++---- db/events.php | 8 ++++---- editservice.php | 19 +++++++++++-------- managerservice.php | 25 +++++++++++++------------ restorebackup.php | 6 +++--- settings.php | 2 +- 8 files changed, 42 insertions(+), 37 deletions(-) diff --git a/classes/editform.php b/classes/editform.php index 46a8f23..64e1e20 100644 --- a/classes/editform.php +++ b/classes/editform.php @@ -28,9 +28,9 @@ defined("MOODLE_INTERNAL") || die(); require_once($CFG->libdir . "/formslib.php"); -use report_eventlist_list_generator; use lang_string; use moodleform; +use report_eventlist_list_generator; /** * Description editing form definition. @@ -64,7 +64,7 @@ class service_edit_form extends moodleform { */ protected function definition() { $mform =& $this->_form; - $size = array("size" => 60); + $size = array("size" => 60); /* Form heading */ $mform->addElement("header", "editserviceheader", new lang_string("service", "webservice")); @@ -104,7 +104,7 @@ class service_edit_form extends moodleform { /* List of events */ $eventlist = report_eventlist_list_generator::get_all_events_list(true); - $events = array(); + $events = array(); /* Formation of the list of elements */ foreach ($eventlist as $event) { diff --git a/classes/event/response_get.php b/classes/event/response_get.php index d1bbf8b..5e25474 100644 --- a/classes/event/response_get.php +++ b/classes/event/response_get.php @@ -37,9 +37,9 @@ class response_get extends \core\event\base { * Init method. */ protected function init() { - $this->data["crud"] = "u"; + $this->data["crud"] = "r"; + $this->data["edulevel"] = self::LEVEL_OTHER; $this->data["objecttable"] = "local_webhooks_service"; - $this->data["edulevel"] = self::LEVEL_OTHER; } /** diff --git a/classes/handler.php b/classes/handler.php index a9fddf7..ac933a9 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -120,12 +120,13 @@ class handler { $event = \local_webhooks\event\response_get::create( array( - "context" => \context_system::instance(0), + "context" => \context_system::instance(0), "objectid" => $callback->id, - "other" => array( - "status" => $status + "other" => array( + "status" => $status + ) ) - )); + ); $event->trigger(); } diff --git a/db/events.php b/db/events.php index a5d585e..a2313c2 100644 --- a/db/events.php +++ b/db/events.php @@ -26,10 +26,10 @@ defined("MOODLE_INTERNAL") || die(); $observers = array( array( - "eventname" => "*", - "callback" => "\local_webhooks\\handler::events", + "callback" => "\local_webhooks\\handler::events", + "eventname" => "*", "includefile" => null, - "priority" => 200, - "internal" => true + "internal" => true, + "priority" => 200 ) ); \ No newline at end of file diff --git a/editservice.php b/editservice.php index a997928..c97fa22 100644 --- a/editservice.php +++ b/editservice.php @@ -27,15 +27,15 @@ require_once(__DIR__ . "/classes/editform.php"); require_once($CFG->libdir . "/adminlib.php"); admin_externalpage_setup("pluginsoverview"); +require_login(); +/* Optional parameters */ $serviceid = optional_param("serviceid", 0, PARAM_INT); -require_login(); - /* Link generation */ -$urlparameters = array("serviceid" => $serviceid); +$urlparameters = array("serviceid" => $serviceid); $managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters); -$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters); +$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters); $PAGE->set_url($baseurl, $urlparameters); /* Configure the context of the page */ @@ -43,7 +43,7 @@ $context = context_system::instance(); $PAGE->set_context($context); /* Preparing a template for data */ -$titlepage = new lang_string("externalservice", "webservice"); +$titlepage = new lang_string("externalservice", "webservice"); $servicerecord = new stdClass; /* Create an editing form */ @@ -62,10 +62,13 @@ if ($editing = boolval($serviceid)) { /* Processing of received data */ if ($data = $mform->get_data()) { - if (!empty($data->events)) { - $data->events = base64_encode(gzcompress(serialize($data->events), 9)); + if (empty($data->events)) { + $data->events = array(); } + /* Pack the list of events */ + $data->events = base64_encode(gzcompress(serialize($data->events), 9)); + if ($editing) { $data->id = $serviceid; $DB->update_record("local_webhooks_service", $data); @@ -82,7 +85,7 @@ $PAGE->set_heading($titlepage); $PAGE->set_title($titlepage); /* The page title */ -$PAGE->navbar->add(new lang_string("externalservices", "webservice"), $managerservice); +$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"), $managerservice); $PAGE->navbar->add($titlepage); echo $OUTPUT->header(); diff --git a/managerservice.php b/managerservice.php index 48b14a9..066dc99 100644 --- a/managerservice.php +++ b/managerservice.php @@ -27,13 +27,14 @@ require_once($CFG->libdir . "/tablelib.php"); require_once($CFG->libdir . "/adminlib.php"); admin_externalpage_setup("pluginsoverview"); - -$backupservices = optional_param("backup", 0, PARAM_BOOL); -$deleteid = optional_param("deleteid", 0, PARAM_INT); -$hideshowid = optional_param("hideshowid", 0, PARAM_INT); - require_login(); +/* Optional parameters */ +$backupservices = optional_param("getbackup", 0, PARAM_BOOL); +$deleteid = optional_param("deleteid", 0, PARAM_INT); +$hideshowid = optional_param("hideshowid", 0, PARAM_INT); + +/* Used references */ $editservice = "/local/webhooks/editservice.php"; $managerservice = "/local/webhooks/managerservice.php"; $restorebackup = "/local/webhooks/restorebackup.php"; @@ -74,7 +75,7 @@ if (boolval($hideshowid) && confirm_sesskey()) { } /* Page template */ -$titlepage = new lang_string("externalservices", "webservice"); +$titlepage = new lang_string("pluginname", "local_webhooks"); $PAGE->set_pagelayout("admin"); $PAGE->set_title($titlepage); $PAGE->set_heading($titlepage); @@ -95,13 +96,13 @@ $table->setup(); foreach ($callbacks as $callback) { /* Filling of information columns */ $titlecallback = html_writer::div($callback->title, "title"); - $urlcallback = html_writer::div($callback->url, "url"); + $urlcallback = html_writer::div($callback->url, "url"); /* Defining service status */ - $hideshowicon = "t/show"; + $hideshowicon = "t/show"; $hideshowstring = new lang_string("enable", "moodle"); if (boolval($callback->enable)) { - $hideshowicon = "t/hide"; + $hideshowicon = "t/hide"; $hideshowstring = new lang_string("disable", "moodle"); } @@ -125,11 +126,11 @@ foreach ($callbacks as $callback) { $table->print_html(); /* Add service button */ -$addurl = new moodle_url($editservice); -echo $OUTPUT->single_button($addurl, new lang_string("addaservice", "webservice"), "get"); +$addserviceurl = new moodle_url($editservice); +echo $OUTPUT->single_button($addserviceurl, new lang_string("addaservice", "webservice"), "get"); /* Button to get a backup */ -$backupurl = new moodle_url($managerservice, array("backup" => true)); +$backupurl = new moodle_url($managerservice, array("getbackup" => true)); echo $OUTPUT->single_button($backupurl, new lang_string("backup", "moodle"), "get"); /* Button for restoring settings */ diff --git a/restorebackup.php b/restorebackup.php index ee6f48a..69200bc 100644 --- a/restorebackup.php +++ b/restorebackup.php @@ -31,7 +31,7 @@ require_login(); /* Link generation */ $managerservice = new moodle_url("/local/webhooks/managerservice.php"); -$baseurl = new moodle_url("/local/webhooks/restorebackup.php"); +$baseurl = new moodle_url("/local/webhooks/restorebackup.php"); $PAGE->set_url($baseurl); /* Configure the context of the page */ @@ -49,7 +49,7 @@ if ($mform->is_cancelled()) { /* Processing the received file */ $data = $mform->get_data(); if (boolval($data) && confirm_sesskey()) { - $content = $mform->get_file_content("backupfile"); + $content = $mform->get_file_content("backupfile"); $callbacks = unserialize(gzuncompress(base64_decode($content))); $DB->delete_records("local_webhooks_service"); @@ -67,7 +67,7 @@ $PAGE->set_heading($titlepage); $PAGE->set_title($titlepage); /* The page title */ -$PAGE->navbar->add(new lang_string("externalservices", "webservice"), $managerservice); +$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"), $managerservice); $PAGE->navbar->add($titlepage); echo $OUTPUT->header(); diff --git a/settings.php b/settings.php index aeeeeb8..b36c594 100644 --- a/settings.php +++ b/settings.php @@ -26,7 +26,7 @@ defined("MOODLE_INTERNAL") || die(); if ($hassiteconfig) { $ADMIN->add("server", new admin_externalpage("local_webhooks", - new lang_string("externalservices", "webservice"), + new lang_string("pluginname", "local_webhooks"), new moodle_url("/local/webhooks/managerservice.php") )); } \ No newline at end of file -- cgit v1.2.3