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

get_featured_collection_categ_sub_fcs()

Description

Get a list of featured collections based on a higher level featured collection category. This returns all direct/indirect
collections under that category.

Parameters

ColumnTypeDefaultDescription
$c array Collection data structure
$ctx array array Contextual data (e.g disable access control). This param MUST NOT get exposed over the API

Return

array

Location

include/collections_functions.php lines 3030 to 3099

Definition

 
function get_featured_collection_categ_sub_fcs(array $c, array $ctx = array())
    {
    global 
$CACHE_FC_CATEG_SUB_FCS;
    
$CACHE_FC_CATEG_SUB_FCS = (!is_null($CACHE_FC_CATEG_SUB_FCS) && is_array($CACHE_FC_CATEG_SUB_FCS) ? $CACHE_FC_CATEG_SUB_FCS : array());
    if(isset(
$CACHE_FC_CATEG_SUB_FCS[$c["ref"]]))
        {
        return 
$CACHE_FC_CATEG_SUB_FCS[$c["ref"]];
        }

    
$access_control = (isset($ctx["access_control"]) && is_bool($ctx["access_control"]) ? $ctx["access_control"] : true);
    
$all_fcs = (isset($ctx["all_fcs"]) && is_array($ctx["all_fcs"]) && !empty($ctx["all_fcs"]) ? $ctx["all_fcs"] : get_all_featured_collections());

    
$collections = array();

    
$allowed_fcs = ($access_control compute_featured_collections_access_control() : true);
    if(
$allowed_fcs === false)
        {
        
$CACHE_FC_CATEG_SUB_FCS[$c["ref"]] = $collections;
        return 
$collections;
        }
    elseif(
is_array($allowed_fcs))
        {
        
$allowed_fcs_flipped array_flip($allowed_fcs);
        
        
// Collection is not allowed
        
if(!isset($allowed_fcs_flipped[$c['ref']]))
            {
            
$CACHE_FC_CATEG_SUB_FCS[$c["ref"]] = $collections;
            return 
$collections;
            }
        }

    
$all_fcs_rp reshape_array_by_value_keys($all_fcs'ref''parent');
    
$all_fcs array_flip_by_value_key($all_fcs'ref');

    
$queue = new SplQueue();
    
$queue->setIteratorMode(SplQueue::IT_MODE_DELETE);
    
$queue->enqueue($c['ref']);

    while(!
$queue->isEmpty())
        {
        
$fc $queue->dequeue();
        
$fc_children = array();

        if(
            
$all_fcs[$fc]['has_resources'] > 0
            
&& (
                
$allowed_fcs === true
                
|| (is_array($allowed_fcs) && isset($allowed_fcs_flipped[$fc]))
            )
        )
            {
            
$collections[] = $fc;
            }
        elseif(
$all_fcs[$fc]['has_children'] > 0)
            {
            
$fc_children array_keys($all_fcs_rp$fc);
            }

        foreach(
$fc_children as $fc_child_ref)
            {
            
$queue->enqueue($fc_child_ref);
            }
        }

    
$CACHE_FC_CATEG_SUB_FCS[$c["ref"]] = $collections;

    
debug("get_featured_collection_categ_sub_fcs(ref = {$c["ref"]}): returned collections: " implode(", "$collections));
    return 
$collections;
    }

This article was last updated 19th March 2024 07:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.