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

get_all_ancestors_for_node()

Description

Return a row consisting of all ancestor nodes of a given 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 A tree node
$level integer Node depth level (as returned by get_tree_node_level())

Return

array|boolean

Location

include/node_functions.php lines 502 to 531

Definition

 
function get_all_ancestors_for_node(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 24th May 2024 11:05 Europe/London time based on the source file dated 14th May 2024 18:25 Europe/London time.