From 816110da62fccf0a71c961b583decb54a3ac7244 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 8 Sep 2018 15:38:03 +0400 Subject: Basic function of obtaining data about the service Signed-off-by: Valentin Popov --- lib.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib.php') diff --git a/lib.php b/lib.php index af72826..556bf13 100644 --- a/lib.php +++ b/lib.php @@ -35,6 +35,30 @@ define( "LW_TABLE_EVENTS", "local_webhooks_events" ); * @package local_webhooks */ class local_webhooks_api { + /** + * Get information about the service. + * + * @param int $serviceId Service ID + * @return array Service data + */ + public static function get_service( $serviceId = 0 ) { + global $DB; + + if ( !is_numeric( $serviceId ) || empty( $serviceId ) ) { + print_error( "unknowparamtype", "error", null, "serviceId" ); + } + + $service = $DB->get_record( LW_TABLE_SERVICES, array( "id" => $serviceId ), "*", MUST_EXIST ); + $events = $DB->get_records( LW_TABLE_EVENTS, array( "serviceid" => $serviceId ), "", "*", 0, 0 ); + + $service->events = array(); + foreach ( $events as $event ) { + $service->events[] = $event->name; + } + + return (array) $service; + } + /** * Create service data in the database. * -- cgit v1.2.3