get_featured_collections_by_resources()

Description

Get all featured collections branches where the specified resources can be found.

Parameters

ColumnTypeDefaultDescription
$r_refs array List of resource IDs

Return

array Returns list of featured collections (categories included) that contain the specified resource(s).

Location

include/collections_functions.php lines 5626 to 5667

Definition

 
function get_featured_collections_by_resources(array $r_refs)
{
    
$resources array_filter($r_refs"is_numeric");
    if (empty(
$resources)) {
        return array();
    }

    
$featured_type_filter_sql "";
    
$featured_type_filter_sql_params = [];
    
$fcf_sql featured_collections_permissions_filter_sql("AND""c.ref");
    if (
is_array($fcf_sql)) {
        
$featured_type_filter_sql "(c.`type` = ? " $fcf_sql[0] . ")";
        
$featured_type_filter_sql_params array_merge(["i",COLLECTION_TYPE_FEATURED], $fcf_sql[1]);
    }

    
# Add chunking to avoid exceeding MySQL parameter limits
    
$fcs = array();
    foreach (
array_chunk($resources10000) as $resource_chunk) {
        
$sql sprintf(
            
"SELECT c.ref, c.`name`, c.`parent`
            FROM collection_resource AS cr
            JOIN collection AS c ON cr.collection = c.ref AND c.`type` = %s
            WHERE cr.resource IN (%s)
                %s # access control filter (ok if empty - it means we don't want permission checks or there's nothing to filter out)"
,
            
COLLECTION_TYPE_FEATURED,
            
ps_param_insert(count($resource_chunk)),
            
$featured_type_filter_sql
        
);

        
$fcs_chunk ps_query($sqlarray_merge(ps_param_fill($resource_chunk'i'), $featured_type_filter_sql_params));
        
$fcs array_merge($fcs$fcs_chunk);
    }

    
$fcs array_unique($fcsSORT_REGULAR);

    
$results = array();
    foreach (
$fcs as $fc) {
        
$results[] = get_featured_collection_category_branch_by_leaf($fc["ref"], array());
    }

    return 
$results;
}

This article was last updated 10th June 2025 21:35 Europe/London time based on the source file dated 3rd June 2025 16:40 Europe/London time.