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

mcp_download_report()

Description

Report recorded downloads on an authorised resource population, without user identities.

Parameters

ColumnTypeDefaultDescription
$args array
$population: array

Location

include/mcp_report_functions.php lines 135 to 157

Definition

 
function mcp_download_report(array $args, array $population): array
{
    
$refs = array_keys($population);
    
$range = mcp_event_dates($args);
    if (!
$refs) {
        return 
mcp_result(['total' => 0, 'groups' => []]);
    }
    
$group = match ($args['group_by'] ?? 'resource') {
        
'day' => 'DATE(r.date)',
        
'month' => "DATE_FORMAT(r.date, '%Y-%m')",
        default => 
'r.resource',
    };
    
$where = ' FROM resource_log r WHERE r.resource IN (' . ps_param_insert(count($refs)) . ')
        AND BINARY r.type = ? AND ' 
. $range->sql;
    
$params = [...ps_param_fill($refs, 'i'), 's', LOG_CODE_DOWNLOADED, ...$range->parameters];
    
$total = ps_value('SELECT COUNT(*) AS value' . $where, $params, 0);
    
$rows = ps_query("SELECT $group AS value, COUNT(*) AS downloads" . $where
        
. " GROUP BY $group ORDER BY downloads DESC, value LIMIT ?, ?", [...$params, 'i', $args['offset'] ?? 0, 'i', $args['limit'] ?? 25]);
    foreach (
$rows as &$row) {
        
$row['downloads'] = (int) $row['downloads'];
    }
    return 
mcp_result(['total' => (int) $total, 'groups' => $rows]);
}

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.