Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

get_resource_nodes_batch()

Description

Get all nodes for given resources and fields. Returns a multidimensional array wth resource IDs as top level indexes and field IDs as second level indexes

Parameters

ColumnTypeDefaultDescription
$resources array
$resource_type_fields array array
$detailed boolean false Set to true to return full node details (as get_node() does)
$node_sort boolean null Set to SORT_ASC to sort nodes ascending, SORT_DESC sort nodes descending, null means do not sort

Return

array

Location

include/node_functions.php lines 2371 to 2448

Definition

 
function get_resource_nodes_batch(array $resources, array $resource_type_fields = array(), bool $detailed false$node_sort null)
    {
    
$sql_select "rn.resource, n.ref, n.resource_type_field ";

    if(
$detailed)
        {
        
$sql_select .= ", n.`name`, n.parent, n.order_by";
        }

    
$resources array_filter($resources,"is_int_loose");
    if(empty(
$resources))
        {
        return [];
        }

    
$chunks array_chunk($resources,SYSTEM_DATABASE_IDS_CHUNK_SIZE);
    
$noderows = [];
    foreach(
$chunks as $chunk)
        {
        
$query "SELECT {$sql_select} FROM resource_node rn LEFT JOIN node n ON n.ref = rn.node WHERE rn.resource IN (" ps_param_insert(count($chunk)) . ")";
        
$query_params ps_param_fill($chunk"i");

        if(
is_array($resource_type_fields) && count($resource_type_fields) > 0)
            {
            
$fields array_filter($resource_type_fields,"is_int_loose");
            if (
count($fields) > 0)
                {
                
$query .= " AND n.resource_type_field IN (" ps_param_insert(count($fields)) . ")";
                
$query_params array_merge($query_paramsps_param_fill($fields"i"));
                }
            }

        if(!
is_null($node_sort))
            {
            if(
$node_sort == SORT_ASC)
                {
                
$query .= " ORDER BY n.ref ASC";
                }
            if(
$node_sort == SORT_DESC)
                {
                
$query .= " ORDER BY n.ref DESC";
                }
            }

        
$newnoderows ps_query($query$query_params);
        
$noderows array_merge($noderows,$newnoderows);
        }

    
$results = array();
    foreach(
$noderows as $noderow)
        {
        if(!isset(
$results[$noderow["resource"]]))
            {
            
$results[$noderow["resource"]] = array();
            }
        if(!isset(
$results[$noderow["resource"]][$noderow["resource_type_field"]]))
            {
            
$results[$noderow["resource"]][$noderow["resource_type_field"]] = array();
            }

        if(
$detailed)
            {
            
$results[$noderow["resource"]][$noderow["resource_type_field"]][] = array(
                
"ref"                   => $noderow["ref"],
                
"resource_type_field"   => $noderow["resource_type_field"],
                
"name"                  => $noderow["name"],
                
"parent"                => $noderow["parent"],
                
"order_by"              => $noderow["order_by"],
                );
            }
        else
            {
            
$results[$noderow["resource"]][$noderow["resource_type_field"]][] = $noderow["ref"];
            }
        }

    return 
$results;
    }

This article was last updated 19th March 2024 09:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.