ibexa

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

tree

Summary

Fetches the children of a node recursively.

Usage

fetch( 'content', 'tree',
       hash( 'parent_node_id',     parent_node_id,
           [ 'sort_by',                    sort_by,                   ]
           [ 'offset',                     offset,                    ]
           [ 'limit',                      limit,                     ]
           [ 'attribute_filter',           attribute_filter,          ]
           [ 'extended_attribute_filter',  extended_attribute_filter, ]
           [ 'class_filter_type',          class_filter_type,         ]
           [ 'class_filter_array',         class_filter_array,        ]
           [ 'only_translated',            only_translated,           ]
           [ 'language',                   language,                  ]
           [ 'main_node_only',             main_node_only,            ]
           [ 'as_object',                  as_object,                 ]
           [ 'depth',                      depth,                     ]
           [ 'depth_operator',             depth_operator             ]
           [ 'limitation',                 limitation                 ]
           [ 'ignore_visibility',          ignore_visibility          ] ) )

Parameters

NameTypeDescriptionRequired
parent_node_id integer The ID number of the parent node. Yes.
sort_by array The sorting mechanism that should be used. No.
offset integer The offset to start at. No.
limit integer The maximum number of nodes that should be fetched. No.
attribute_filter mixed Filter logic for attribute level filtering. No.
class_filter_type string The type of class filtering (include/exclude). No.
class_filter_array array The type of nodes that should be filtered. No.
only_translated boolean Translation filtering (on/off). No.
language string The language that should be filtered. No.
main_node_only boolean Type of nodes that should be fetched (all or main nodes only). No.
depth integer The maximum level of depth that should be explored. No.
depth_operator string The logic to use when checking the depth. No.
extended_attribute_filter mixed The extended attribute level filter logic. No.
as_object boolean If TRUE (or omitted), an array of "ezcontentobjecttreenode" objects will be fetched. Otherwise, an array of arrays will be returned. No.
limitation array Limitation array (emtpy array = access override). No.
ignore_visibility boolean Makes it possible to fetch hidden nodes. No.

Description

The "tree" function is very similar to the "list" fetch function. The only difference is that the tree function fetches child nodes recursively. The recursion depth can be controlled by the "depth" and "depth_operator" parameters. The rest of the parameters behave exactly in the same way as they do for the "list" function. Please refer to the documentation page of the "list" function for a complete explanation of the parameters.

Depth

The depth parameter can be used to specify the level of depth (within the branch) that the function should explore when it is running. If the depth is set to one, this function will simply act as the list function. If the depth is greater than one, the function will fetch nodes further down in the branch. The default value is unlimited.

Depth operator

The depth operator can be set to either "lt", "eq" or "gt" - meaning "less than", "equal to" and "greather than". For example, if it is set to 'eq', only nodes with the depth that was specified using the depth parameter will be fetched.

Examples

Example 1

{def $nodes=fetch( 'content', 'tree',
                   hash( 'parent_node_id', 42 ) )}
 
{foreach $nodes as $node}
    {$node.name|wash} <br />
{/foreach}

This example demonstrates how to fetch all the nodes that are under node number 42 recursively (all children, grand-children, etc. will be fetched). The names of the nodes are displayed.

Balazs Halasy (06/02/2004 12:15 pm)

Svitlana Shatokhina (25/10/2006 9:35 am)

Balazs Halasy, Svitlana Shatokhina


Comments

  • How to use depth_operator

    'depth', 3,
    'depth_operator', "lt",
    

    This means that you fetch all nodes with a depth less than 3