From 1736128dbf3be7fd83e6b3aa9088266aa8b490e6 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 22 Feb 2018 10:45:18 +0400 Subject: Adding the function of forming events --- externallib.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/externallib.php b/externallib.php index 9f0b877..246419f 100644 --- a/externallib.php +++ b/externallib.php @@ -35,6 +35,22 @@ require_once($CFG->libdir . "/externallib.php"); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ 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. * @@ -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); - } } } -- cgit v1.2.3