Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

add_resource_nodes_multi()

Description

Add nodes in array to multiple resources. Changes made using this function will not be logged

Parameters

ColumnTypeDefaultDescription
$resources array array Array of resource IDs to add nodes to
$nodes array array Array of node IDs to add
$checkperms boolean true Check permissions before adding?

Return

boolean

Location

include/node_functions.php lines 1218 to 1257

Definition

 
function add_resource_nodes_multi($resources=array(),$nodes=array(), $checkperms true)
    {
    global 
$userref;
    if((!
is_array($resources) && (string)(int)$resources != $resources) || (!is_array($nodes) && (string)(int)$nodes != $nodes))
        {return 
false;}
    
    if(
$checkperms)
        {
        
// Need to check user has permissions to add nodes
        
foreach($resources as $resourceid)
            {
            
$resourcedata get_resource_data($resourceid);
            
$access get_edit_access($resourceid,$resourcedata["archive"],false,$resourcedata);
            if(!
$access)
                {return 
false;}
            
            if(
$resourcedata["lock_user"] > && $resourcedata["lock_user"] != $userref)
                {
                
$error get_resource_lock_message($resourcedata["lock_user"]);
                return 
false;
                }
            }
        }

    if(!
is_array($nodes))
        {
$nodes=array($nodes);}

    
$nodes_escaped escape_check_array_values($nodes);

    
$sql "INSERT INTO resource_node (resource, node) VALUES ";
    
$nodesql "";
    foreach(
$resources as $resource)
        {
        if(
$nodesql!=""){$nodesql .= ",";}
        
$nodesql .= " ('" escape_check($resource) . "','" implode("'),('" escape_check($resource) . "','",$nodes_escaped) . "') ";
        }
    
$sql "INSERT INTO resource_node (resource, node) VALUES " $nodesql "  ON DUPLICATE KEY UPDATE hit_count=hit_count";
    
sql_query($sql);
    return 
true;
    }

This article was last updated 15th July 2020 05:05 Europe/London time based on the source file dated 6th July 2020 18:09 Europe/London time.