Collections functions
General functions
Render functions
Theme permission functions
Resource functions

get_cattree_nodes_ordered()

Description

This function returns an array of category tree nodes in the hierarchical sequence defined in manage options

Parameters

ColumnTypeDefaultDescription
$treefield array - the category tree field to be processed
$resource integer null - the resource against which to check for selected nodes - optional
$allnodes array false - is true if all nodes in the structure are returned, false if only selected nodes are returned

Return

array $flatnodes - the array of nodes returned in correct hierarchical order

Location

include/node_functions.php lines 2038 to 2086

Definition

 
function get_cattree_nodes_ordered($treefield$resource=null$allnodes=false) {

    
$nodeentries ps_query("SELECT n.ref, n.resource_type_field, n.name, coalesce(n.parent, 0) parent, n.order_by, rn.resource 
                            FROM node n
                            LEFT OUTER JOIN resource_node rn on rn.resource = ? and rn.node = n.ref  
                            WHERE n.resource_type_field=? order by n.parent, n.order_by"
,array("i",(int)$resource"i",(int)$treefield));

    
# Category trees have no container root, so create one to carry all top level category tree nodes which don't have a parent
    
$rootnode cattree_node_creator(00"ROOT"null0null, array());                                               

    
$nodeswithpointers = array(=> &$rootnode);

    foreach(
$nodeentries as $nodeentry) {
        
$ref $nodeentry['ref'];
        
$resource_type_field $nodeentry['resource_type_field'];
        
$name $nodeentry['name'];
        
$parent $nodeentry['parent'];
        
$order_by $nodeentry['order_by'];
        
$resource $nodeentry['resource'];

        
# Save the current node prior to establishing the pointer which can null the current node
        
$savednode=null;
        if (isset(
$nodeswithpointers[$ref])) {
            
$savednode $nodeswithpointers[$ref];
        }
        
        
# Establish a pointer so that this node will be a child of its parent node
        #  This means that the current node entry will be "added" to the children of the parent entry
        
$nodeswithpointers[$ref] = &$nodeswithpointers[$parent]['children'][];
        
        
# Create an entry for the current node with any existing children at this point 
        
$existingchildren = array();
        if (
$savednode && isset($savednode['children'])) {
            
$existingchildren $savednode['children'];
        }   
        
$nodeswithpointers[$ref] = cattree_node_creator($ref$resource_type_field$name$parent$order_by$resource$existingchildren);
    }

    
# Flatten the tree starting at the root                                                          
    
$flatnodes cattree_node_flatten($rootnode);

    
$returned_nodes=array();
    foreach(
$flatnodes as $flatnode) {
        If (
$allnodes || $flatnode['resource']!='') {
            
$returned_nodes[$flatnode['ref']]=$flatnode;
        }
    }
    return 
$returned_nodes;
}

This article was last updated 2nd December 2022 19:35 Europe/London time based on the source file dated 25th November 2022 11:35 Europe/London time.