Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

add_resource_nodes()

Description

Add nodes in array to resource

Parameters

ColumnTypeDefaultDescription
$resourceid integer Resource ID to add nodes to
$nodes array array Array of node IDs to add
$checkperms boolean true Check permissions before adding?
$logthis boolean true Log this? Log entries are ideally added when more data on all the changes made is available to make reverts easier.

Return

boolean

Location

include/node_functions.php lines 1165 to 1207

Definition

 
function add_resource_nodes($resourceid,$nodes=array(), $checkperms true$logthis=true)
    {
    global 
$userref;
    if(!
is_array($nodes) && (string)(int)$nodes != $nodes)
        {return 
false;}

    if(
$checkperms && (PHP_SAPI != 'cli' || defined("RS_TEST_MODE")))
        {
        
// Need to check user has permissions to add nodes (unless running from any CLI script other than unit tests)
        
$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);}

    
sql_query("insert into resource_node (resource, node) values ('" escape_check($resourceid) . "','" implode("'),('" escape_check($resourceid) . "','",$nodes) . "') ON DUPLICATE KEY UPDATE hit_count=hit_count");

    if(
$logthis)
        {
        
$field_nodes_arr = array();
        foreach (
$nodes as $node)
            {
            
$nodedata = array();
            
get_node($node$nodedata);
            
$field_nodes_arr[$nodedata["resource_type_field"]][] = $nodedata["name"];
            }
        
        foreach (
$field_nodes_arr as $key => $value)
            {
            
resource_log($resourceid,"e",$key,"","","," implode(",",$value));
            }
        }

    return 
true;
    }

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