summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-10-26 06:35:52 +0300
committerGitHub <noreply@github.com>2017-10-26 06:35:52 +0300
commit9ecf83b1d66aed22b12f7de2fd9bdbf0015226b6 (patch)
tree4f04b51fde3990f3d633b7b8b5f34339f6c84b37
parent430c9fa09a4fc1995b8b7751f7b41aeec18298b4 (diff)
parent54d1d030ec3e604cb2dd63819664d05677befe16 (diff)
downloadlocal_webhooks-9ecf83b1d66aed22b12f7de2fd9bdbf0015226b6.tar.xz
local_webhooks-9ecf83b1d66aed22b12f7de2fd9bdbf0015226b6.zip
Merge pull request #2 from valentineus/list-events
List events
-rw-r--r--classes/events.php26
-rw-r--r--classes/forms.php30
-rw-r--r--db/install.xml3
-rw-r--r--editservice.php3
4 files changed, 55 insertions, 7 deletions
diff --git a/classes/events.php b/classes/events.php
index 5dfb0cf..33e278b 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::handler_callback($data, $callback);
}
}
@@ -67,20 +67,34 @@ 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 handler_callback($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.
*
* @param array $data
diff --git a/classes/forms.php b/classes/forms.php
index c95b280..d6402cc 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;
@@ -46,6 +47,16 @@ class service_edit_form extends moodleform {
}
/**
+ * 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.
*/
protected function definition() {
@@ -76,6 +87,25 @@ 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);
+ $events = array();
+
+ /* Formation of the list of elements */
+ foreach ($eventlist as $event) {
+ $events[$event["component"]][] =&
+ $mform->createElement("advcheckbox", $event["eventname"], $event["eventname"]);
+ }
+
+ /* Displays groups of items */
+ foreach ($events as $key => $event) {
+ $mform->addGroup($event, "events", $key, "<br />", true);
+ }
+
/* Control Panel */
$this->add_action_buttons(true);
}
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 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171022" COMMENT="XMLDB file for Moodle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
+<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171025" COMMENT="XMLDB file for Moodle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
<TABLES>
<TABLE NAME="local_webhooks_service" COMMENT="A table for storing callback services.">
<FIELDS>
@@ -7,6 +7,7 @@
<FIELD NAME="enable" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
<FIELD NAME="title" TYPE="text" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
+ <FIELD NAME="events" TYPE="text" NOTNULL="true" SEQUENCE="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
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);