Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 2342 to 2413

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;
        }
    else if(
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_parent = ($all_fcs[$fc]['parent'] > $all_fcs[$fc]['parent'] : 0);
        
$fc_children = array();

        if(
            
$all_fcs[$fc]['has_resources'] > 0
            
&& (
                
$allowed_fcs === true
                
|| (is_array($allowed_fcs) && isset($allowed_fcs_flipped[$fc]))
            )
        )
            {
            
$collections[] = $fc;
            }
        else if(
$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 21st April 2021 18:35 Europe/London time based on the source file dated 19th April 2021 16:50 Europe/London time.