From 6a83be960ec751eb42628e92e90b237efcb62a36 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 13 Mar 2018 01:17:22 +0400 Subject: Update function 'local_webhooks_search_record' Signed-off-by: Valentin Popov --- lib.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lib.php b/lib.php index 9bc8389..ba27486 100644 --- a/lib.php +++ b/lib.php @@ -47,27 +47,25 @@ function local_webhooks_change_status($serviceid) { /** * Search for services that contain the specified event. * - * @param string $eventname - * @param boolean $active + * @param string $eventname + * @param number $limitfrom + * @param number $limitnum * @return array */ -function local_webhooks_search_services_by_event($eventname, $active = false) { - $recordlist = local_webhooks_get_list_records(); - $active = boolval($active); - $result = array(); - - foreach ($recordlist as $record) { - if (!empty($record->events[$eventname])) { - if ($active && boolval($record->enable)) { - $result[] = $record; - } - - if (!$active) { - $result[] = $record; - } +function local_webhooks_search_record($eventname, $limitfrom = 0, $limitnum = 0) { + global $DB; + + $rs = $DB->get_recordset(LOCAL_WEBHOOKS_TABLE_EVENTS, array("name" => $eventname, "status" => true), "id", "*", $limitfrom, $limitnum); + $result = array(); + + foreach ($rs as $event) { + if ($record = $DB->get_record(LOCAL_WEBHOOKS_TABLE_SERVICES, array("id" => $event->serviceid, "status" => true), "*", IGNORE_MISSING)) { + $result[] = $record; } } + $rs->close(); + return $result; } -- cgit v1.2.3