From 5639dc7b0f86eae1bf6828a43c734851ee71c99d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 23 Nov 2017 17:37:41 +0400 Subject: Refactoring the code of the service editor --- editservice.php | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/editservice.php b/editservice.php index 907a41d..0a8aec5 100644 --- a/editservice.php +++ b/editservice.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Service editor. + * Page for editing the service. * * @package local_webhooks * @copyright 2017 "Valentin Popov" @@ -24,6 +24,8 @@ require_once(__DIR__ . "/../../config.php"); require_once(__DIR__ . "/classes/editform.php"); +require_once(__DIR__ . "/lib.php"); + require_once($CFG->libdir . "/adminlib.php"); /* Optional parameters */ @@ -39,7 +41,7 @@ admin_externalpage_setup("local_webhooks", "", null, $baseurl, array()); $context = context_system::instance(); /* Create an editing form */ -$mform = new \local_webhooks\service_edit_form($PAGE->url); +$mform = new local_webhooks\service_edit_form($PAGE->url); /* Cancel processing */ if ($mform->is_cancelled()) { @@ -49,35 +51,18 @@ if ($mform->is_cancelled()) { /* Getting the data */ $servicerecord = new stdClass(); if ($editing = boolval($serviceid)) { - $servicerecord = $DB->get_record("local_webhooks_service", array("id" => $serviceid), "*", MUST_EXIST); + $servicerecord = local_webhooks_get_record($serviceid); $mform->set_data($servicerecord); } /* Processing of received data */ if ($data = $mform->get_data()) { - 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); - - /* Run the event */ - $event = \local_webhooks\event\service_updated::create(array("context" => $context, "objectid" => $data->id)); - $event->trigger(); - + local_webhooks_update_record($data, false); redirect($managerservice, new lang_string("eventwebserviceserviceupdated", "webservice")); } else { - $servicenewid = $DB->insert_record("local_webhooks_service", $data); - - /* Run the event */ - $event = \local_webhooks\event\service_added::create(array("context" => $context, "objectid" => $servicenewid)); - $event->trigger(); - + local_webhooks_update_record($data, true); redirect($managerservice, new lang_string("eventwebserviceservicecreated", "webservice")); } } -- cgit v1.2.3