diff options
author | Valentin Popov <info@valentineus.link> | 2018-02-19 12:37:27 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2018-02-19 12:37:27 +0300 |
commit | 43f0bf98d2297ae3232d7b7dcc6ba2c387add8e0 (patch) | |
tree | 647bd36935b87e0ae2df8c6482fe0a68ccbdbff8 /externallib.php | |
parent | 95c4cf061ab67f28a12e34c0c7098ef5a73d353a (diff) | |
download | local_webhooks-43f0bf98d2297ae3232d7b7dcc6ba2c387add8e0.tar.xz local_webhooks-43f0bf98d2297ae3232d7b7dcc6ba2c387add8e0.zip |
Added external functions to find services
Diffstat (limited to 'externallib.php')
-rw-r--r-- | externallib.php | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/externallib.php b/externallib.php index aa807a7..0430c40 100644 --- a/externallib.php +++ b/externallib.php @@ -85,6 +85,86 @@ class local_webhooks_external extends external_api { * @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. + * + * @return external_function_parameters + * @since Moodle 2.9 Options available + * @since Moodle 2.2 + */ public static function get_record_parameters() { return new external_function_parameters( array( |