From 0d8cb8688d1aedf5498b08863f271ce8f77f8912 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Oct 2017 11:32:28 +0400 Subject: Displays the list of events --- classes/forms.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/classes/forms.php b/classes/forms.php index c95b280..2fbd8cc 100644 --- a/classes/forms.php +++ b/classes/forms.php @@ -28,6 +28,7 @@ defined("MOODLE_INTERNAL") || die(); require_once($CFG->libdir . "/formslib.php"); +use report_eventlist_list_generator; use lang_string; use moodleform; @@ -76,6 +77,21 @@ class service_edit_form extends moodleform { $mform->setDefault("enable", 1); $mform->setAdvanced("enable"); + /* Form heading */ + $mform->addElement("header", "editserviceheaderevent", + new lang_string("edulevel", "moodle")); + + /* List of events */ + $eventlist = report_eventlist_list_generator::get_all_events_list(true); + foreach ($eventlist as $event) { + $eventname = $event["eventname"]; + $mform->addElement("advcheckbox", "events[$eventname]", + $eventname, $event["component"], + array("group" => "events")); + $mform->setType($eventname, PARAM_BOOL); + } + $this->add_checkbox_controller("events", null, null, 1); + /* Control Panel */ $this->add_action_buttons(true); } -- cgit v1.2.3 From bae23caa877e592e33f02fe17c93f7931257b796 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Oct 2017 06:25:48 +0400 Subject: The generator of the list of registered events --- classes/forms.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/classes/forms.php b/classes/forms.php index 2fbd8cc..d6402cc 100644 --- a/classes/forms.php +++ b/classes/forms.php @@ -46,6 +46,16 @@ class service_edit_form extends moodleform { parent::__construct($baseurl); } + /** + * Unpacks data for display. + * + * @param object $record + */ + public function set_data($record) { + $record->events = unserialize(gzuncompress(base64_decode($record->events))); + return parent::set_data($record); + } + /** * Defines the standard structure of the form. */ @@ -83,14 +93,18 @@ class service_edit_form extends moodleform { /* List of events */ $eventlist = report_eventlist_list_generator::get_all_events_list(true); + $events = array(); + + /* Formation of the list of elements */ foreach ($eventlist as $event) { - $eventname = $event["eventname"]; - $mform->addElement("advcheckbox", "events[$eventname]", - $eventname, $event["component"], - array("group" => "events")); - $mform->setType($eventname, PARAM_BOOL); + $events[$event["component"]][] =& + $mform->createElement("advcheckbox", $event["eventname"], $event["eventname"]); + } + + /* Displays groups of items */ + foreach ($events as $key => $event) { + $mform->addGroup($event, "events", $key, "
", true); } - $this->add_checkbox_controller("events", null, null, 1); /* Control Panel */ $this->add_action_buttons(true); -- cgit v1.2.3 From a19031d444a984dc844a01febd3bacfcc6f7b6fc Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Oct 2017 06:27:04 +0400 Subject: Packer of the received data --- editservice.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/editservice.php b/editservice.php index e9c053c..427332c 100644 --- a/editservice.php +++ b/editservice.php @@ -63,6 +63,9 @@ if ($data = $mform->get_data()) { $data->enable = 0; } + /* Packing of data */ + $data->events = base64_encode(gzcompress(serialize($data->events), 9)); + if ($idediting) { $data->id = $idservice; $DB->update_record("local_webhooks_service", $data); -- cgit v1.2.3 From 28632834afba8385fe4082add80bb7438f17a7a0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Oct 2017 06:27:50 +0400 Subject: Additional field in the database --- db/install.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/install.xml b/db/install.xml index b152933..f2e5b05 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - + @@ -7,6 +7,7 @@ + -- cgit v1.2.3 From 8651e6a1571fd99c4adedf3a0310e8a4fca957e3 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Oct 2017 06:45:53 +0400 Subject: The event handler for sending --- classes/events.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/classes/events.php b/classes/events.php index 5dfb0cf..5b93a9c 100644 --- a/classes/events.php +++ b/classes/events.php @@ -59,7 +59,7 @@ class events { if ($callbacks->valid()) { foreach ($callbacks as $callback) { - self::send($data, $callback); + self::handlerCallback($data, $callback); } } @@ -67,19 +67,33 @@ class events { } /** - * Sending data to the node. + * Processes each callback. * * @param array $data * @param object $callback */ - private static function send($data, $callback) { + private static function handlerCallback($data, $callback) { if ($callback->enable) { - $curl = new curl(); - $package = self::packup($data); - $curl::request($callback->url, $package); + $events = unserialize(gzuncompress(base64_decode($callback->events))); + + if (boolval($events[$data["eventname"]])) { + self::send($data, $callback); + } } } + /** + * Sending data to the node. + * + * @param array $data + * @param object $callback + */ + private static function send($data, $callback) { + $curl = new curl(); + $package = self::packup($data); + $curl::request($callback->url, $package); + } + /** * Packs the data for transmission. * -- cgit v1.2.3 From 54d1d030ec3e604cb2dd63819664d05677befe16 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Oct 2017 06:49:33 +0400 Subject: Correcting the style of the code --- classes/events.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/events.php b/classes/events.php index 5b93a9c..33e278b 100644 --- a/classes/events.php +++ b/classes/events.php @@ -59,7 +59,7 @@ class events { if ($callbacks->valid()) { foreach ($callbacks as $callback) { - self::handlerCallback($data, $callback); + self::handler_callback($data, $callback); } } @@ -72,7 +72,7 @@ class events { * @param array $data * @param object $callback */ - private static function handlerCallback($data, $callback) { + private static function handler_callback($data, $callback) { if ($callback->enable) { $events = unserialize(gzuncompress(base64_decode($callback->events))); -- cgit v1.2.3