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

mcp_collections()

Description

Search the user's own/shared collections and the public collection catalogue without creating default collections.

Parameters

ColumnTypeDefaultDescription
$name string
$args: array

Location

include/mcp_browse_functions.php lines 193 to 238

Definition

 
function mcp_collections(string $name, array $args): array
{
    if (
checkperm('b') && $name === 'search_collections') {
        throw new 
DomainException('Collections unavailable.');
    }
    if (
$name === 'get_featured_collections' && !$GLOBALS['enable_themes']) {
        throw new 
DomainException('Featured collections unavailable.');
    }
    
$parent = $args['parent'] ?? (int) $GLOBALS['featured_collections_root_collection'];
    if (
$name === 'get_featured_collections') {
        if (
            
$parent && (!featured_collection_check_access_control($parent)
            || (int) (
get_collection($parent)['type'] ?? -1) !== COLLECTION_TYPE_FEATURED)
        ) {
            throw new 
DomainException('Collection unavailable.');
        }
        
$rows = get_featured_collections($parent, []);
    } else {
        
$rows = get_user_collections($GLOBALS['userref'], auto_create: false);
        if (
$GLOBALS['enable_public_collections']) {
            
$rows = array_merge($rows, search_public_collections());
        }
    }
    
$collections = [];
    
$query = $args['query'] ?? '';
    foreach (
$rows as $row) {
        
$id = (int) $row['ref'];
        if (isset(
$collections[$id]) || ($row['type'] == COLLECTION_TYPE_FEATURED && (!$GLOBALS['enable_themes'] || !featured_collection_check_access_control($id)))) {
            continue;
        }
        
$row['name'] = i18n_get_translated($row['name']);
        
$haystack = implode(' ', [$row['name'], $row['description'] ?? '', $row['keywords'] ?? '']);
        if (
$query === '' || mb_stripos($haystack, $query) !== false) {
            
$collections[$id] = ['ref' => $id, 'type' => (int) $row['type'],
                
'parent' => isset($row['parent']) ? (int) $row['parent'] : null,
                
'name' => $row['name'], 'description' => $row['description'] ?? null];
        }
    }
    
$page = array_slice(array_values($collections), $args['offset'] ?? 0, $args['limit'] ?? 25);
    
$GLOBALS['allow_smart_collections'] = false;
    foreach (
$page as &$collection) {
        
$count = mcp_native_search('!collection' . $collection['ref'], '', 'resourceid', 0, 0, 1, 'asc');
        
$collection['resource_count'] = (int) ($count['total'] ?? 0);
    }
    return 
mcp_result(['collections' => $page, 'total' => count($collections)]);
}

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.