Compare commits

..
21 Commits
Author SHA1 Message Date
Valentin Popov 2744e4fb80 Change version 2017-10-26 09:49:40 +04:00
Valentin Popov 5179a7ec05 Header type processing 2017-10-26 09:48:08 +04:00
Valentin Popov 18a5d23d07 Correction of transmitted parameters 2017-10-26 09:44:44 +04:00
Valentin Popov f43b3f2fd3 Adding an additional field to the database 2017-10-26 09:37:10 +04:00
Valentin Popov ea30d3ca56 Adding the field 'Content type' 2017-10-26 09:35:56 +04:00
Valentin Popov e86542d8f7 Fix for errors with empty values 2017-10-26 09:21:52 +04:00
Valentin Popov dab55b9562 Change the variable 2017-10-26 09:20:32 +04:00
Valentin Popov c2cd361171 We save even more memory 2017-10-26 08:38:08 +04:00
Valentin Popov eaee6b7c81 Change version 2017-10-26 08:02:33 +04:00
Valentin Popov 282e3bcaf1 Add a token to the request 2017-10-26 08:01:16 +04:00
Valentin Popov c037edbc58 Added a field to the database for the security key 2017-10-26 07:51:42 +04:00
Valentin Popov 2c4c05acd6 The form for the security key has been added 2017-10-26 07:50:30 +04:00
Valentin Popov 39fa71faba Change version 2017-10-26 07:39:48 +04:00
Valentin PopovandGitHub 9ecf83b1d6 Merge pull request #2 from valentineus/list-events
List events
2017-10-26 07:35:52 +04:00
Valentin Popov 54d1d030ec Correcting the style of the code 2017-10-26 06:49:33 +04:00
Valentin Popov 8651e6a157 The event handler for sending 2017-10-26 06:45:53 +04:00
Valentin Popov 28632834af Additional field in the database 2017-10-26 06:27:50 +04:00
Valentin Popov a19031d444 Packer of the received data 2017-10-26 06:27:04 +04:00
Valentin Popov bae23caa87 The generator of the list of registered events 2017-10-26 06:25:48 +04:00
Valentin Popov 0d8cb8688d Displays the list of events 2017-10-25 12:09:23 +04:00
Valentin Popov 430c9fa09a Edit the title 2017-10-25 10:33:23 +04:00
7 changed files with 88 additions and 20 deletions
+3 -3
View File
@@ -33,14 +33,14 @@ class curl {
}
}
public static function request($url, $data) {
$ch = curl_init($url);
public static function request($callback, $data) {
$ch = curl_init($callback->url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
"Content-Type: application/json",
"Content-Type: application/" . $callback->type,
"Content-Length: " . strlen($data))
);
+29 -8
View File
@@ -39,9 +39,9 @@ class events {
* @param object $event
*/
public static function handler($event) {
$config = get_config("local_webhooks");
$enable = get_config("local_webhooks", "enable");
if (boolval($config->enable)) {
if (boolval($enable)) {
$data = $event->get_data();
self::transmitter($data);
}
@@ -59,13 +59,36 @@ 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) {
if (!empty($callback->events)) {
$events = unserialize(gzuncompress(base64_decode($callback->events)));
}
if (boolval($events[$data["eventname"]])) {
/* Adding to the data token */
if (boolval($callback->token)) {
$data["token"] = $callback->token;
}
self::send($data, $callback);
}
}
}
/**
* Sending data to the node.
*
@@ -73,11 +96,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, $package);
}
/**
+44 -1
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.
*/
@@ -70,12 +81,44 @@ class service_edit_form extends moodleform {
$mform->addRule("url", null, "required");
/* Enabling the service */
$mform->addElement("checkbox", "enable",
$mform->addElement("advcheckbox", "enable",
new lang_string("enable", "moodle"));
$mform->setType("enable", PARAM_BOOL);
$mform->setDefault("enable", 1);
$mform->setAdvanced("enable");
/* Token */
$mform->addElement("text", "token",
new lang_string("token", "webservice"),
array("size" => 60));
$mform->setType("token", PARAM_NOTAGS);
/* Content type */
$mform->addElement("select", "type", "Content type",
array(
"json" => "application/json",
"x-www-form-urlencoded" => "application/x-www-form-urlencoded"));
$mform->setAdvanced("type");
/* 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("checkbox", $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);
}
+4 -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="20171026" 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,9 @@
<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="type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="token" 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 -3
View File
@@ -59,8 +59,9 @@ if ($idediting = boolval($idservice)) {
/* Processing of received data */
if ($data = $mform->get_data()) {
if (empty($data->enable)) {
$data->enable = 0;
/* Packing of data */
if (!empty($data->events)) {
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
}
if ($idediting) {
@@ -79,7 +80,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.4.0 (Build: 2017102620)";
$plugin->version = 2017102620;
$plugin->requires = 2016112900;
$plugin->component = "local_webhooks";
$plugin->maturity = MATURITY_ALPHA;
$plugin->maturity = MATURITY_BETA;