Compare commits

...
9 Commits
6 changed files with 60 additions and 12 deletions
+20 -6
View File
@@ -59,13 +59,29 @@ class events {
if ($callbacks->valid()) {
foreach ($callbacks as $callback) {
self::send($data, $callback);
self::handler_callback($data, $callback);
}
}
$callbacks->close();
}
/**
* Processes each callback.
*
* @param array $data
* @param object $callback
*/
private static function handler_callback($data, $callback) {
if ($callback->enable) {
$events = unserialize(gzuncompress(base64_decode($callback->events)));
if (boolval($events[$data["eventname"]])) {
self::send($data, $callback);
}
}
}
/**
* Sending data to the node.
*
@@ -73,11 +89,9 @@ class events {
* @param object $callback
*/
private static function send($data, $callback) {
if ($callback->enable) {
$curl = new curl();
$package = self::packup($data);
$curl::request($callback->url, $package);
}
$curl = new curl();
$package = self::packup($data);
$curl::request($callback->url, $package);
}
/**
+30
View File
@@ -28,6 +28,7 @@ defined("MOODLE_INTERNAL") || die();
require_once($CFG->libdir . "/formslib.php");
use report_eventlist_list_generator;
use lang_string;
use moodleform;
@@ -45,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.
*/
@@ -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);
}
+2 -1
View File
@@ -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" />
+4 -1
View File
@@ -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);
@@ -79,7 +82,7 @@ $PAGE->set_heading($titlepage);
$PAGE->set_title($titlepage);
/* The page title */
$PAGE->navbar->add(new lang_string("local", "moodle"));
$PAGE->navbar->add(new lang_string("localplugins", "moodle"));
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
$PAGE->navbar->add(new lang_string("managerservice", "local_webhooks"), $managerservice);
$PAGE->navbar->add($titlepage);
+1 -1
View File
@@ -56,7 +56,7 @@ $PAGE->set_title($titlepage);
$PAGE->set_heading($titlepage);
/* The page title */
$PAGE->navbar->add(new lang_string("local", "moodle"));
$PAGE->navbar->add(new lang_string("localplugins", "moodle"));
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
$PAGE->navbar->add($titlepage, $baseurl);
echo $OUTPUT->header();
+3 -3
View File
@@ -23,8 +23,8 @@
*/
defined("MOODLE_INTERNAL") || die();
$plugin->release = "0.1.0 (Build: 2017102500)";
$plugin->version = 2017102500;
$plugin->release = "0.2.0 (Build: 2017102600)";
$plugin->version = 2017102600;
$plugin->requires = 2016112900;
$plugin->component = "local_webhooks";
$plugin->maturity = MATURITY_ALPHA;
$plugin->maturity = MATURITY_BETA;