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

Definition

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

    
# check $nodes array values are positive integers and valid for int type node db field
    
$options_db_int = [ 'options' => [ 'min_range' => 1,   'max_range' => 2147483647] ];
    foreach(
$nodes as $node)
        {
        if (!
filter_var($nodeFILTER_VALIDATE_INT$options_db_int))
            {
            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);

        if (!
$resourcedata)
            {
            return 
false;
            }
        
        
$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);
            if (
$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 24th November 2020 06:35 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.