Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 2388 to 2466

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, n.`active`';
        }

    
$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"]][] = [
                
"ref"                   => $noderow["ref"],
                
"resource_type_field"   => $noderow["resource_type_field"],
                
"name"                  => $noderow["name"],
                
"parent"                => $noderow["parent"],
                
"order_by"              => $noderow["order_by"],
                
'active'                => $noderow['active'],
            ];
            }
        else
            {
            
$results[$noderow["resource"]][$noderow["resource_type_field"]][] = $noderow["ref"];
            }
        }

    return 
$results;
    }

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.