diff options
author | Valentin Popov <info@valentineus.link> | 2017-11-23 16:37:41 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2017-11-23 16:37:41 +0300 |
commit | 5639dc7b0f86eae1bf6828a43c734851ee71c99d (patch) | |
tree | f55f2b21cc91e1df69e217d35fa50c0f1cbbcd9a | |
parent | 1ad4527c1d62dc6df02711d1c1e390f2a9169991 (diff) | |
download | local_webhooks-5639dc7b0f86eae1bf6828a43c734851ee71c99d.tar.xz local_webhooks-5639dc7b0f86eae1bf6828a43c734851ee71c99d.zip |
Refactoring the code of the service editor
-rw-r--r-- | editservice.php | 29 |
1 files 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 <http://www.gnu.org/licenses/>. /** - * Service editor. + * Page for editing the service. * * @package local_webhooks * @copyright 2017 "Valentin Popov" <info@valentineus.link> @@ -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")); } } |