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

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 2153 to 2198

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 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.