summaryrefslogtreecommitdiff
path: root/externallib.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-02-22 09:45:18 +0300
committerValentin Popov <info@valentineus.link>2018-02-22 11:37:59 +0300
commit1736128dbf3be7fd83e6b3aa9088266aa8b490e6 (patch)
tree6865703698d445e492ff1e49bab5b1b18915d10b /externallib.php
parent5cdd8de9e31e999c25f6279edabd507ad5d15409 (diff)
downloadlocal_webhooks-1736128dbf3be7fd83e6b3aa9088266aa8b490e6.tar.xz
local_webhooks-1736128dbf3be7fd83e6b3aa9088266aa8b490e6.zip
Adding the function of forming events
Diffstat (limited to 'externallib.php')
-rw-r--r--externallib.php34
1 files changed, 19 insertions, 15 deletions
diff --git a/externallib.php b/externallib.php
index 9f0b877..246419f 100644
--- a/externallib.php
+++ b/externallib.php
@@ -36,6 +36,22 @@ require_once($CFG->libdir . "/externallib.php");
*/
class local_webhooks_external extends external_api {
/**
+ * Formation of the final list of events.
+ *
+ * @param array $listevents
+ * @return array
+ */
+ private static function formation_events($listevents) {
+ $result = array();
+
+ foreach ($listevents as $key => $value) {
+ $result[] = array("name" => $key, "value" => $value);
+ }
+
+ return $result;
+ }
+
+ /**
* Returns description of method parameters.
*
* @return external_function_parameters
@@ -111,6 +127,7 @@ class local_webhooks_external extends external_api {
$result = array();
if ($listrecords = local_webhooks_search_services_by_event($parameters["eventname"], $parameters["active"])) {
foreach ($listrecords as $index => $record) {
+ $result[$index]["events"] = self::formation_events($record->events);
$result[$index]["enable"] = $record->enable;
$result[$index]["id"] = $record->id;
$result[$index]["other"] = $record->other;
@@ -118,11 +135,6 @@ class local_webhooks_external extends external_api {
$result[$index]["token"] = $record->token;
$result[$index]["type"] = $record->type;
$result[$index]["url"] = $record->url;
-
- $result[$index]["events"] = array();
- foreach ($record->events as $key => $value) {
- $result[$index]["events"][] = array("name" => $key, "value" => $value);
- }
}
}
@@ -190,6 +202,7 @@ class local_webhooks_external extends external_api {
$service = array();
if ($record = local_webhooks_get_record($parameters["serviceid"])) {
+ $service["events"] = self::formation_events($record->events);
$service["enable"] = $record->enable;
$service["id"] = $record->id;
$service["other"] = $record->other;
@@ -197,11 +210,6 @@ class local_webhooks_external extends external_api {
$service["token"] = $record->token;
$service["type"] = $record->type;
$service["url"] = $record->url;
-
- $service["events"] = array();
- foreach ($record->events as $key => $value) {
- $service["events"][] = array("name" => $key, "value" => $value);
- }
}
return $service;
@@ -260,6 +268,7 @@ class local_webhooks_external extends external_api {
$result = array();
if ($listrecords = local_webhooks_get_list_records()) {
foreach ($listrecords as $index => $record) {
+ $result[$index]["events"] = self::formation_events($record->events);
$result[$index]["enable"] = $record->enable;
$result[$index]["id"] = $record->id;
$result[$index]["other"] = $record->other;
@@ -267,11 +276,6 @@ class local_webhooks_external extends external_api {
$result[$index]["token"] = $record->token;
$result[$index]["type"] = $record->type;
$result[$index]["url"] = $record->url;
-
- $result[$index]["events"] = array();
- foreach ($record->events as $key => $value) {
- $result[$index]["events"][] = array("name" => $key, "value" => $value);
- }
}
}