aboutsummaryrefslogtreecommitdiff
path: root/lib.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-09-08 14:38:03 +0300
committerValentin Popov <info@valentineus.link>2018-09-08 14:46:57 +0300
commit816110da62fccf0a71c961b583decb54a3ac7244 (patch)
tree40bd07ceaa6380fb256800b64b7d1ca24c4d67e3 /lib.php
parent295da67a0ace2bbdf78f9f69bacc0b00fec31b22 (diff)
downloadlocal_webhooks-816110da62fccf0a71c961b583decb54a3ac7244.tar.xz
local_webhooks-816110da62fccf0a71c961b583decb54a3ac7244.zip
Basic function of obtaining data about the service
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'lib.php')
-rw-r--r--lib.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib.php b/lib.php
index af72826..556bf13 100644
--- a/lib.php
+++ b/lib.php
@@ -36,6 +36,30 @@ define( "LW_TABLE_EVENTS", "local_webhooks_events" );
*/
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.
*
* @param array $service Data to the service