aboutsummaryrefslogtreecommitdiff
path: root/lib.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-09-08 15:06:39 +0300
committerValentin Popov <info@valentineus.link>2018-09-08 15:06:39 +0300
commit472f85850ac4694b7127b389d31e5ee97aa5f037 (patch)
tree56c607bea0b575538763c06bf06162024e08107a /lib.php
parent816110da62fccf0a71c961b583decb54a3ac7244 (diff)
downloadlocal_webhooks-472f85850ac4694b7127b389d31e5ee97aa5f037.tar.xz
local_webhooks-472f85850ac4694b7127b389d31e5ee97aa5f037.zip
Basic function of getting a list of all services
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'lib.php')
-rw-r--r--lib.php49
1 files changed, 38 insertions, 11 deletions
diff --git a/lib.php b/lib.php
index 556bf13..e30595f 100644
--- a/lib.php
+++ b/lib.php
@@ -38,8 +38,8 @@ class local_webhooks_api {
/**
* Get information about the service.
*
- * @param int $serviceId Service ID
- * @return array Service data
+ * @param int $serviceId
+ * @return object
*/
public static function get_service( $serviceId = 0 ) {
global $DB;
@@ -56,14 +56,41 @@ class local_webhooks_api {
$service->events[] = $event->name;
}
- return (array) $service;
+ return $service;
+ }
+
+ /**
+ * Get a list of services.
+ * By default, the entire list of services is given.
+ *
+ * @param array $conditions
+ * @param string $sort
+ * @param int $limitFrom
+ * @param int $limitNum
+ * @return array
+ */
+ public static function get_services( $conditions = array(), $sort = "", $limitFrom = 0, $limitNum = 0 ) {
+ global $DB;
+
+ $services = $DB->get_records( LW_TABLE_SERVICES, $conditions, $sort, "*", $limitFrom, $limitNum );
+
+ foreach ( $services as $key => $service ) {
+ $events = $DB->get_records( LW_TABLE_EVENTS, array( "serviceid" => $service->id ), "", "*", 0, 0 );
+
+ $service->events = array();
+ foreach ( $events as $event ) {
+ $service->events[] = $event->name;
+ }
+ }
+
+ return $services;
}
/**
* Create service data in the database.
*
- * @param array $service Data to the service
- * @return int Service ID
+ * @param array $service
+ * @return int
*/
public static function create_service( $service = array() ) {
global $DB;
@@ -83,8 +110,8 @@ class local_webhooks_api {
/**
* Delete the service data from the database.
*
- * @param int $serviceId Service ID
- * @return bool Execution result
+ * @param int $serviceId
+ * @return bool
*/
public static function delete_service( $serviceId = 0 ) {
global $DB;
@@ -100,8 +127,8 @@ class local_webhooks_api {
/**
* Update the service data in the database.
*
- * @param array $service Data to the service
- * @return bool Execution result
+ * @param array $service
+ * @return bool
*/
public static function update_service( $service = array() ) {
global $DB;
@@ -122,8 +149,8 @@ class local_webhooks_api {
/**
* Save the list of events to the database.
*
- * @param array $events List of events
- * @param int $serviceId Service ID
+ * @param array $events
+ * @param int $serviceId
*/
private static function insert_events( $events = array(), $serviceId = 0 ) {
global $DB;