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_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.