From 17b9cfde78bd49ac9fe7c2406945a851400a69bb Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 9 Sep 2018 04:38:27 +0400 Subject: Service search function on the event Signed-off-by: Valentin Popov --- lib.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib.php b/lib.php index 3abd756..3f0865c 100644 --- a/lib.php +++ b/lib.php @@ -85,6 +85,29 @@ class local_webhooks_api { return $services; } + /** + * Get the list of services subscribed to the event. + * + * @param string $eventName + * @return array + */ + public static function get_services_by_event( $eventName = "" ) { + global $DB; + + if ( !is_string( $eventName ) || empty( $eventName ) ) { + print_error( "unknowparamtype", "error", null, "eventName" ); + } + + $events = $DB->get_records( LW_TABLE_EVENTS, array( "name" => $eventName ), "", "*", 0, 0 ); + + $services = array(); + foreach ( $events as $event ) { + $services[] = local_webhooks_api::get_service( $event->serviceid ); + } + + return $services; + } + /** * Create service data in the database. * -- cgit v1.2.3