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

get_cattree_node_strings()

Description

This function returns an array of category tree node strings in the hierarchical sequence defined in manage options
The returned strings are i18 translated

True (default) strings are paths to nodes; False strings are the individual node names

Parameters

ColumnTypeDefaultDescription
$nodesordered array - the array of nodes in correct hierarchical order
$strings_are_paths array true - governs the format of the name returned

Return

array $strings - the returned array of node paths or node names

Location

include/node_functions.php lines 2150 to 2195

Definition

 
function get_cattree_node_strings($nodesordered$strings_are_paths=true) {
    
# If names are not to be returned as paths, just return the individual node names 
    
if (!$strings_are_paths) {
        
$strings_as_names=array();
        foreach (
$nodesordered as $node)
            {
            
$strings_as_names[]=i18n_get_translated($node["name"]);
            }
        return 
$strings_as_names
    }
    
# Build a string consisting of a comma separated list of individual nodes and paths of consecutive child nodes
    
$strings_as_paths=array();
    
# Establish a list of parents referenced by the nodes
    
$parents_referenced=array_column($nodesordered,'name','parent');
    
# Establish a list of referenced parents which are in the list
    
$parents_listed=array_intersect_key($nodesordered,$parents_referenced);

    
# Processing is driven by each leaf node (ie. nodes with no selected children)
    
foreach ($nodesordered as $node){
        if(!
array_key_exists($node['ref'],$parents_listed)) {
            
# This selected node is effectively a leaf node because it has no selected children 
            # This leaf node is the first entry in the leafpath
            
$leafpath=array(i18n_get_translated($node["name"]));
            
$parenttofind=$node['parent'];
            
# Append consecutive selected ancestors to the leafpath
            
while (isset($parenttofind)) {
                if(
$parenttofind==0) { # Ignore root node
                    
$parenttofind=null;
                    continue; 
                } 
                
# If current node's parent is listed then append it to the leafpath
                
if (array_key_exists($parenttofind$parents_listed)) {
                    
$leafpath[]=i18n_get_translated($parents_listed[$parenttofind]['name']);
                    
$parenttofind=$parents_listed[$parenttofind]['parent'];
                }
                else {
                    
# Current node's parent is not listed so this leafpath is complete
                    
$parenttofind=null;
                }
            }
            
$leafpathstring=implode("/",array_reverse($leafpath));
            
$strings_as_paths[]=$leafpathstring;
        }
    }
    return 
$strings_as_paths;
}

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