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

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.* ";
        }

    
$resources array_filter($resources,"is_int_loose"); // remove non-numeric values
    
$query "SELECT {$sql_select} FROM resource_node rn LEFT JOIN node n ON n.ref = rn.node WHERE rn.resource IN ('" implode("','",$resources) . "')";

    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 ('" implode("','",$fields) . "')";
        }

    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 sql_query($query);
    
$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();
            }

        
$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"],
            );
        }

    return 
$results;
    }

This article was last updated 21st April 2021 18:35 Europe/London time based on the source file dated 29th March 2021 12:15 Europe/London time.