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

get_resource_data_batch()

Description

get_resource_data_batch - get data from resource table for all resource IDs

Parameters

ColumnTypeDefaultDescription
$refs mixed - array of resource IDs

Return

array

Location

include/resource_functions.php lines 477 to 512

Definition

 
function get_resource_data_batch($refs)
{
    global 
$get_resource_data_cache;
    
truncate_cache_arrays();

    
$resids array_values(array_unique(array_filter($refs'is_int_loose')));
    if (
count($resids) === 0) {
        return array();
    }
    
$resids_chunked count($resids) <= SYSTEM_DATABASE_IDS_CHUNK_SIZE
        
? [$resids]
        : 
array_chunk($residsSYSTEM_DATABASE_IDS_CHUNK_SIZE);

    
# Build a string that will return the 'join' columns (not actually joins but cached truncated metadata stored at the resource level)
    
$joins get_resource_table_joins();
    
$join_fields = empty($joins) ? '' ',' implode(','array_map(prefix_value('field'), $joins));

    
$resource_data = array();
    foreach (
$resids_chunked as $resids_cnk) {
        
$resdata ps_query(
            
sprintf(
                
'SELECT %s%s FROM `resource` WHERE ref IN (%s)',
                
columns_in('resource'),
                
$join_fields,
                
ps_param_insert(count($resids_cnk))
            ),
            
ps_param_fill($resids_cnk'i')
        );
        foreach (
$resdata as $resdatarow) {
            
$resource_data[$resdatarow["ref"]] = $resdatarow;
            
$get_resource_data_cache[$resdatarow["ref"]] = $resdatarow;
        }
    }

    return 
$resource_data;
}

This article was last updated 22nd July 2024 21:35 Europe/London time based on the source file dated 10th July 2024 11:30 Europe/London time.