Update function 'local_webhooks_search_record'
Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
		
							
								
								
									
										22
									
								
								lib.php
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								lib.php
									
									
									
									
									
								
							@@ -48,25 +48,23 @@ function local_webhooks_change_status($serviceid) {
 | 
			
		||||
 * Search for services that contain the specified event.
 | 
			
		||||
 *
 | 
			
		||||
 * @param  string $eventname
 | 
			
		||||
 * @param  boolean $active
 | 
			
		||||
 * @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);
 | 
			
		||||
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 ($recordlist as $record) {
 | 
			
		||||
        if (!empty($record->events[$eventname])) {
 | 
			
		||||
            if ($active && boolval($record->enable)) {
 | 
			
		||||
    foreach ($rs as $event) {
 | 
			
		||||
        if ($record = $DB->get_record(LOCAL_WEBHOOKS_TABLE_SERVICES, array("id" => $event->serviceid, "status" => true), "*", IGNORE_MISSING)) {
 | 
			
		||||
            $result[] = $record;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
            if (!$active) {
 | 
			
		||||
                $result[] = $record;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    $rs->close();
 | 
			
		||||
 | 
			
		||||
    return $result;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user