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_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 521 to 550

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 13th December 2024 20:35 Europe/London time based on the source file dated 11th December 2024 22:35 Europe/London time.