From 43f0bf98d2297ae3232d7b7dcc6ba2c387add8e0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 19 Feb 2018 13:37:27 +0400 Subject: Added external functions to find services --- externallib.php | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'externallib.php') diff --git a/externallib.php b/externallib.php index aa807a7..0430c40 100644 --- a/externallib.php +++ b/externallib.php @@ -78,6 +78,86 @@ class local_webhooks_external extends external_api { return new external_value(PARAM_BOOL, "The result of the operation."); } + /** + * Returns description of method parameters. + * + * @return external_function_parameters + * @since Moodle 2.9 Options available + * @since Moodle 2.2 + */ + public static function search_services_by_event_parameters() { + return new external_function_parameters( + array( + "eventname" => new external_value(PARAM_TEXT, "The name of the event.") + ) + ); + } + + /** + * Search for services that contain the specified event. + * + * @param string $eventname + * @return array + * @since Moodle 2.9 Options available + * @since Moodle 2.2 + */ + public static function search_services_by_event($eventname = "") { + $parameters = self::validate_parameters(self::search_services_by_event_parameters(), array("eventname" => $eventname)); + + $context = context_system::instance(); + self::validate_context($context); + + $result = array(); + if ($listrecords = local_webhooks_search_services_by_event($parameters["eventname"])) { + foreach ($listrecords as $index => $record) { + $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[$index]["events"] = array(); + foreach ($record->events as $key => $value) { + $result[$index]["events"][] = array("name" => $key, "value" => $value); + } + } + } + + return $result; + } + + /** + * Returns description of method result value. + * + * @return external_description + * @since Moodle 2.2 + */ + public static function search_services_by_event_returns() { + return new external_multiple_structure( + new external_single_structure( + array( + "id" => new external_value(PARAM_INT, "Service identifier."), + "enable" => new external_value(PARAM_INT, "Service status."), + "title" => new external_value(PARAM_TEXT, "Name of the service."), + "url" => new external_value(PARAM_URL, "URL address."), + "type" => new external_value(PARAM_TEXT, "Header type."), + "token" => new external_value(PARAM_TEXT, "Authorization key.", VALUE_OPTIONAL), + "other" => new external_value(PARAM_TEXT, "Additional field.", VALUE_OPTIONAL), + "events" => new external_multiple_structure( + new external_single_structure( + array( + "name" => new external_value(PARAM_TEXT, "Event name."), + "value" => new external_value(PARAM_INT, "Observation status.") + ) + ), "Observed events.", VALUE_OPTIONAL + ) + ), "Record about the service." + ), "List of services." + ); + } + /** * Returns description of method parameters. * -- cgit v1.2.3