Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 7813 to 7862

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))
        || (
$filtercondition == RS_FILTER_NONE && $filtersfailed == count($filterrules) && $filtersok == 0)
    ) {
        return 
true;
    }

    return 
false;
    }

This article was last updated 4th December 2024 09:05 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.