Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

filter_featured_collections_by_root()

Description

Filter out featured collections that have a different root path. The function builds internally the path to the root from
the provided featured collection ref and then filters out any featured collections that have a different root path.

Parameters

ColumnTypeDefaultDescription
$fcs array List of featured collections refs to filter out
$c_ref int A root featured collection ref
$ctx array array Contextual data

Return

array

Location

include/collections_functions.php lines 5163 to 5194

Definition

 
function filter_featured_collections_by_root(array $fcsint $c_ref, array $ctx = array())
    {
    if(empty(
$fcs))
        {
        return array();
        }

    global 
$CACHE_FCS_BY_ROOT;
    
$CACHE_FCS_BY_ROOT = (!is_null($CACHE_FCS_BY_ROOT) && is_array($CACHE_FCS_BY_ROOT) ? $CACHE_FCS_BY_ROOT : array());
    
$cache_id $c_ref md5(json_encode($fcs));
    if(isset(
$CACHE_FCS_BY_ROOT[$cache_id][$c_ref]))
        {
        return 
$CACHE_FCS_BY_ROOT[$cache_id][$c_ref];
        }

    
$all_fcs = (isset($ctx["all_fcs"]) && is_array($ctx["all_fcs"]) ? $ctx["all_fcs"] : array());
    
$branch_path_fct = function($carry$item) { return "{$carry}/{$item["ref"]}"; };

    
$category_branch_path get_featured_collection_category_branch_by_leaf($c_ref$all_fcs);
    
$category_branch_path_str array_reduce($category_branch_path$branch_path_fct"");

    
$collections array_filter($fcs, function(int $ref) use ($branch_path_fct$category_branch_path_str$all_fcs)
        {
        
$branch_path get_featured_collection_category_branch_by_leaf($ref$all_fcs);
        
$branch_path_str array_reduce($branch_path$branch_path_fct"");
        return (
substr($branch_path_str0strlen($category_branch_path_str)) == $category_branch_path_str);
        });

    
$CACHE_FCS_BY_ROOT[$cache_id][$c_ref] = $collections;

    return 
array_values($collections);
    }

This article was last updated 21st April 2021 17:35 Europe/London time based on the source file dated 19th April 2021 16:50 Europe/London time.