From 85bcb64e37128e07273d20252c86bc284b44a799 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 22 Feb 2018 12:44:50 +0400 Subject: Added general list functions --- externallib.php | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'externallib.php') diff --git a/externallib.php b/externallib.php index 246419f..e064c03 100644 --- a/externallib.php +++ b/externallib.php @@ -35,6 +35,29 @@ 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. + * + * @param array $listrecords + * @return array + */ + private static function formation_list($listrecords) { + $result = array(); + + 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; + $result[$index]["title"] = $record->title; + $result[$index]["token"] = $record->token; + $result[$index]["type"] = $record->type; + $result[$index]["url"] = $record->url; + } + + return $result; + } + /** * Formation of the final list of events. * @@ -126,16 +149,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; - $result[$index]["title"] = $record->title; - $result[$index]["token"] = $record->token; - $result[$index]["type"] = $record->type; - $result[$index]["url"] = $record->url; - } + $result = self::formation_list($listrecords); } return $result; @@ -267,16 +281,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; - $result[$index]["title"] = $record->title; - $result[$index]["token"] = $record->token; - $result[$index]["type"] = $record->type; - $result[$index]["url"] = $record->url; - } + $result = self::formation_list($listrecords); } return $result; -- cgit v1.2.3