Collections functions
General functions
Render functions
Theme permission 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 2343 to 2410

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 [];
        }

    
$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($resources)) . ")";
    
$query_params ps_param_fill($resources"i");

    if(
is_array($resource_type_fields) && count($resource_type_fields) > 0)
        {
        
$fields array_filter($resource_type_fields,"is_int_loose");
        
$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";
            }
        }

    
$noderows ps_query($query$query_params);
    
$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 4th October 2022 11:35 Europe/London time based on the source file dated 3rd October 2022 13:50 Europe/London time.