Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

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 6098 to 6143

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 27th April 2024 18:35 Europe/London time based on the source file dated 25th April 2024 16:25 Europe/London time.