mcp_collections()
Description
Search the user's own/shared collections and the public collection catalogue without creating default collections.Parameters
| Column | Type | Default | Description |
|---|---|---|---|
| $name | string | ||
| $args: | array |
Location
include/mcp_browse_functions.php lines 237 to 298
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());
}
}
$memberships = null;
if (isset($args['ref'])) {
mcp_visible_resource($args['ref']);
$memberships = array_flip(ps_array('SELECT collection AS value FROM collection_resource WHERE resource = ?', ['i', $args['ref']]));
}
if (isset($args['date_from']) || isset($args['date_to'])) {
mcp_event_dates($args);
}
$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;
}
$created = substr((string) ($row['created'] ?? ''), 0, 10);
if (
($memberships !== null && !isset($memberships[$id])) || (isset($args['date_from']) && $created < $args['date_from'])
|| (isset($args['date_to']) && ($created === '' || $created > $args['date_to']))
) {
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, 'created' => $row['created'] ?? null,
'smart' => !empty($row['savedsearch'])];
}
}
$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 4th December 2026 20:35 Europe/London time based on the source file dated 4th December 2026 14:10 Europe/London time.