Update function 'local_webhooks_search_record'

Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
Valentin Popov 2018-03-13 01:17:22 +04:00
parent 82842e5ed8
commit 6a83be960e
Signed by: Valentin Popov
GPG Key ID: 269A00ACA90A8EA3

26
lib.php
View File

@ -47,27 +47,25 @@ function local_webhooks_change_status($serviceid) {
/** /**
* Search for services that contain the specified event. * Search for services that contain the specified event.
* *
* @param string $eventname * @param string $eventname
* @param boolean $active * @param number $limitfrom
* @param number $limitnum
* @return array * @return array
*/ */
function local_webhooks_search_services_by_event($eventname, $active = false) { function local_webhooks_search_record($eventname, $limitfrom = 0, $limitnum = 0) {
$recordlist = local_webhooks_get_list_records(); global $DB;
$active = boolval($active);
$result = array();
foreach ($recordlist as $record) { $rs = $DB->get_recordset(LOCAL_WEBHOOKS_TABLE_EVENTS, array("name" => $eventname, "status" => true), "id", "*", $limitfrom, $limitnum);
if (!empty($record->events[$eventname])) { $result = array();
if ($active && boolval($record->enable)) {
$result[] = $record;
}
if (!$active) { foreach ($rs as $event) {
$result[] = $record; if ($record = $DB->get_record(LOCAL_WEBHOOKS_TABLE_SERVICES, array("id" => $event->serviceid, "status" => true), "*", IGNORE_MISSING)) {
} $result[] = $record;
} }
} }
$rs->close();
return $result; return $result;
} }