Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 6104 to 6135

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 17th November 2024 15:35 Europe/London time based on the source file dated 13th November 2024 15:50 Europe/London time.