Oihana PHP Arango

buildTreeAlter.php

Table of Contents

Functions

buildTreeAlter()  : callable
Builds an {@see \oihana\models\enums\Alter::MAP} callback that reshapes a flat hierarchy projection into a nested `children[]` tree via {@see buildTree()}.

Functions

buildTreeAlter()

Builds an {@see \oihana\models\enums\Alter::MAP} callback that reshapes a flat hierarchy projection into a nested `children[]` tree via {@see buildTree()}.

buildTreeAlter([string $parentSource = AQL::_PARENT ][, string $childrenKey = AQL::CHILDREN ][, string $keyField = Schema::_KEY ]) : callable

Declare it on the field that carries the depth-ranged projection:

use oihana\arango\models\enums\Alter ;
use function oihana\arango\models\helpers\buildTreeAlter ;

AQL::FIELDS =>
[
    Prop::DESCENDANTS =>
    [
        Field::FILTER => Filter::EDGES ,
        Field::ALTERS => [ [ Alter::MAP , buildTreeAlter() ] ] ,
    ],
],
AQL::EDGES =>
[
    Prop::DESCENDANTS =>
    [
        AQL::MODEL     => 'concept_links' ,
        AQL::DIRECTION => Traversal::OUTBOUND ,
        AQL::MAX_DEPTH => 5 ,
        AQL::WITH_PATH => true , // provides the `_parent` used to rebuild the tree
    ],
],

At map time the callback:

  • leaves the value untouched when it is not an array (an absent/scalar relation),
  • reads the root from the enclosing document's $keyField (the traversal start vertex — its own _key),
  • returns the nested tree built by buildTree().

The parent link source defaults to AQL::_PARENT (_parent, injected by AQL::WITH_PATH); pass a stored field name instead (e.g. 'broader') when the document already carries its parent.

Parameters
$parentSource : string = AQL::_PARENT

The key holding each node's parent key (default AQL::_PARENT).

$childrenKey : string = AQL::CHILDREN

The key under which children are nested (default children).

$keyField : string = Schema::_KEY

The identity key of a node and of the enclosing document (default Schema::_KEY).

Tags
author

Marc Alcaraz

since
1.5.0
Return values
callable

A callback matching the Alter::MAP signature ( array|object $document, ?Container $container, string $key, mixed $value, array $params, array $context ): mixed.

On this page

Search results