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

get_all_parents_by_leaf()

Description

Build a row consisting of all parents of a given leaf node
Example:
1
2
2.3
2.7
2.8.4
2.8.5
2.8.6
2.9
3
Passing in node 5 will return nodes 8,2 in one row

Parameters

ColumnTypeDefaultDescription
$ref integer Node ID of tree leaf
$level integer Node depth level (as returned by get_tree_node_level())

Return

integer|boolean

Location

include/node_functions.php lines 542 to 571

Definition

 
function get_all_parents_by_leaf(int $refint $level)
    {
    if(
>= $level)
        {
        return 
false;
        }

    
$querycolumns = array();
    
$query " FROM node AS n{$level}";

    
$from_level $level;
    
$level--;

    while(
<= $level)
        {
        
$query .= " LEFT JOIN node AS n{$level} ON n" . ($level 1) . ".parent = n{$level}.ref";
        
$querycolumns[] = "n{$level}.ref n{$level}ref";

        if(
=== $level)
            {
            
$query .= " WHERE n{$from_level}.ref = ?";
            
$placeholders = ['i'$ref];
            }

        
$level--;
        }
    
    
$query "SELECT "implode(",",$querycolumns) . $query;
    return 
ps_query($query$placeholders);
    }

This article was last updated 17th October 2023 09:35 Europe/London time based on the source file dated 16th October 2023 15:50 Europe/London time.