Collections functions
General functions
Render functions
Theme permission functions
Resource functions

save_filter_rule()

Description

Save filter rule, will return existing rule ID if text matches already migrated

Parameters

ColumnTypeDefaultDescription
$filter_rule int - ID of filter_rule
$filterid int - ID of associated filter
$rule_data
$ruledata array|string - Details of associated rule nodes (as JSON if submitted from rule edit page)

Return

boolean | integer - false, or ID of filter_rule

Location

include/search_functions.php lines 2728 to 2765

Definition

 
function save_filter_rule($filter_rule$filterid$rule_data)
    {
    if(!
is_array($rule_data))
        {
        
$rule_data json_decode($rule_data);
        }
        
    if(
$filter_rule != "new" && is_int_loose($filter_rule) && $filter_rule 0)
        {
        
ps_query("DELETE FROM filter_rule_node WHERE filter_rule = ?",array("i",$filter_rule));
        }
    else
        {
        
ps_query("INSERT INTO filter_rule (filter) VALUES (?)",array("i",$filterid));
        
$filter_rule sql_insert_id();
        }    
        
    if(
count($rule_data) > 0)
        {
        
$nodeinsert = array();
        
$params=array();
        for(
$n=0;$n<count($rule_data);$n++)
            {
            
$condition $rule_data[$n][0];
            for(
$rd=0;$rd<count($rule_data[$n][1]);$rd++)
                {
                
$nodeid $rule_data[$n][1][$rd];
                
$nodeinsert[] = "(?,?,?)";
                
$params[]="i";$params[]=$filter_rule;
                
$params[]="i";$params[]=$nodeid;
                
$params[]="i";$params[]=$condition;
                }
            }
        
$sql "INSERT INTO filter_rule_node (filter_rule,node,node_condition) VALUES " implode(',',$nodeinsert);
        
ps_query($sql,$params);
        }
    return 
$filter_rule;
    }

This article was last updated 2nd October 2022 17:35 Europe/London time based on the source file dated 13th September 2022 17:55 Europe/London time.