Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 2588 to 2621

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" && (string)(int)$filter_rule == (string)$filter_rule && $filter_rule 0)
        {
        
sql_query("DELETE FROM filter_rule_node WHERE filter_rule = '{$filter_rule}'");
        }
    else
        {
        
sql_query("INSERT INTO filter_rule (filter) VALUES ('{$filterid}')");
        
$filter_rule sql_insert_id();
        }    
        
    if(
count($rule_data) > 0)
        {
        
$nodeinsert = 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[] = "('" $filter_rule "','" $nodeid "','" $condition "')";
                }
            }
        
$sql "INSERT INTO filter_rule_node (filter_rule,node,node_condition) VALUES " implode(',',$nodeinsert);
        
sql_query($sql);
        }
    return 
$filter_rule;
    }

This article was last updated 24th November 2020 18:05 Europe/London time based on the source file dated 19th November 2020 14:20 Europe/London time.