Coding standards
Security in ResourceSpace
Developer reference
Database
Mcp browse functions
Mcp report functions

mcp_report_population()

Description

Collect authorised resource references from native search in bounded pages.
Applying effective access in PHP retains custom group, workflow and plugin behaviour.

Parameters

ColumnTypeDefaultDescription
$args array Search and report arguments.
$metadata_dates bool Filter metadata dates rather than download event dates.
$count_only bool Request only the native search total.
array_columnget_resource_types
'ref'

Return

($count_only is true ? int : array) Lightweight rows keyed by resource ID, or the accessible search count.

Location

include/mcp_report_functions.php lines 30 to 78

Definition

 
function mcp_report_population(array $args, bool $metadata_dates, bool $count_only = false): array|int
{
    
$type = $args['resource_type'] ?? 0;
    if (
$type && !in_array($type, array_column(get_resource_types(), 'ref'))) {
        throw new 
DomainException('Resource type unavailable.');
    }
    
$state = $args['workflow_state'] ?? 0;
    if (isset(
$args['workflow_state']) && (!in_array($state, get_workflow_states()) || checkperm('z' . $state))) {
        throw new 
DomainException('Workflow state unavailable.');
    }
    
$query = $args['query'] ?? '';
    
mcp_check_search_source($query);
    
$search_args = $metadata_dates ? $args : array_diff_key($args, array_flip(['date_from', 'date_to']));
    
$query = mcp_search_expression($search_args, null, $query);
    
$population = [];
    
$GLOBALS['pagename'] = 'search';
    foreach (
$GLOBALS['plugins'] as $plugin) {
        
register_plugin($plugin);
    }
    if (
$count_only) {
        
$result = mcp_native_search($query, (string) ($type ?: ''), 'resourceid', $state, 0, 1, 'asc');
        return (int) 
$result['total'];
    }
    for (
$offset = 0; $offset < MCP_REPORT_MAX_RESOURCES; $offset += 250) {
        
$result = mcp_native_search($query, (string) ($type ?: ''), 'resourceid', $state, $offset, 250, 'asc');
        if (
$result['total'] > MCP_REPORT_MAX_RESOURCES) {
            throw new 
DomainException('Narrow the report search or resource type. The report limit is 10000 matching resources.');
        }
        
// Seed the native access cache's resource data for rows without custom access joins.
        
get_resource_data_batch(array_column($result['data'], 'ref'));
        foreach (
$result['data'] as $row) {
            
resource_type_config_override($row['resource_type']);
            
$access = (int) get_resource_access($row);
            if (
checkperm('T' . $row['resource_type']) || !in_array($access, [RESOURCE_ACCESS_FULL, RESOURCE_ACCESS_RESTRICTED], true)) {
                continue;
            }
            
$id = (int) $row['ref'];
            
$population[$id] = [
                
'ref' => $id, 'resource_type' => (int) $row['resource_type'], 'workflow_state' => (int) $row['archive'],
                
'file_extension' => $row['file_extension'], 'creation_month' => substr((string) $row['creation_date'], 0, 7),
                
'access' => $access,
            ];
        }
        if (
$offset + 250 >= $result['total'] || !$result['data']) {
            break;
        }
    }
    return 
$population;
}

This article was last updated 3rd December 2026 16:35 Europe/London time based on the source file dated 3rd December 2026 16:30 Europe/London time.