Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

filter_check()

Description

Check if a given set of nodes meets the conditions set for the provided filter
NOte that all resource_nodes for a resource should be passed to check if a filter is matched

Parameters

ColumnTypeDefaultDescription
$filterid
$nodes array Array of nodes
$ref integer Filter ID

Return

boolean

Location

include/resource_functions.php lines 7567 to 7614

Definition

 
function filter_check($filterid,$nodes)
    {
    
$filterdata         get_filter($filterid);
    
$filterrules        get_filter_rules($filterid);
    
$filtercondition    $filterdata["filter_condition"];

    
// Used for RS_FILTER_ALL type
    
$filtersfailed  0;
    
$filtersok      0;

    foreach(
$filterrules as $filterrule)
        {
        
// Check if any nodes are present that shouldn't be, or nodes not present that need to be
        
$badnodes   array_intersect($filterrule["nodes_off"],$nodes);
        
$goodnodes  array_intersect($filterrule["nodes_on"],$nodes);
        
$rulemet    count($badnodes) == && (count($filterrule["nodes_on"]) == || count($goodnodes) > 0);
        
// Can return now if filter successfully matched and RS_FILTER_ANY or RS_FILTER_NONE,
        // or if filter not matched and RS_FILTER_ALL
        
if($rulemet)
            {
            if(
$filtercondition == RS_FILTER_ANY)
                {
                return 
true;
                }
            elseif(
$filtercondition == RS_FILTER_NONE)
                {
                return 
false;
                }
            
$filtersok++;
            }
        else
            {
            if(
$filtercondition == RS_FILTER_ALL)
                {
                return 
false;
                }
            
$filtersfailed++;
            }
        
// Need to check subsequent rules if RS_FILTER_ALL and filter rule met
        
}

    if(
$filtercondition == RS_FILTER_ALL && $filtersfailed == && $filtersok == count($filterrules))
        {
        return 
true;
        }

    return 
false;
    }

This article was last updated 19th March 2024 09:05 Europe/London time based on the source file dated 11th March 2024 14:25 Europe/London time.