src/Titon/Db/Behavior/HierarchyBehavior.php
public function mapList(array $nodes, $key, $value, $spacer) {
        $tree = [];
        $stack = [];
        $key = $key ?: $this->getRepository()->getPrimaryKey();
        $value = $value ?: $this->getRepository()->getDisplayField();
        $right = $this->getConfig('rightField');

        foreach ($nodes as $node) {
            $count = count($stack);

            while ($count && $stack[$count - 1] < $node[$right]) {
                array_pop($stack);
                $count--;
            }

            $tree[$node[$key]] = str_repeat($spacer, $count) . $node[$value];

            $stack[] = $node[$right];
        }

        return $tree;
    }
public function mapList(array $nodes, $key, $value, $spacer) {
        $tree = [];
        $stack = [];
        $key = $key ?: $this->getRepository()->getPrimaryKey();
        $value = $value ?: $this->getRepository()->getDisplayField();
        $right = $this->getConfig('rightField');

        foreach ($nodes as $node) {
            $count = count($stack);

            while ($count && $stack[$count - 1] < $node[$right]) {
                array_pop($stack);
                $count--;
            }

            $tree[$node[$key]] = str_repeat($spacer, $count) . $node[$value];

            $stack[] = $node[$right];
        }

        return $tree;
    }
public function mapList ( array $ nodes , $ key , $ value , $ spacer ) { $ tree = [ ] ; $ stack = [ ] ; $ key = $ key ? : $ this -> getRepository ( ) -> getPrimaryKey ( ) ; $ value = $ value ? : $ this -> getRepository ( ) -> getDisplayField ( ) ; $ right = $ this -> getConfig ( 'rightField' ) ; foreach ( $ nodes as $ node ) { $ count = count ( $ stack ) ; while ( $ count && $ stack [ $ count - 1 ] < $ node [ $ right ] ) { array_pop ( $ stack ) ; $ count -- ; } $ tree [ $ node [ $ key ] ] = str_repeat ( $ spacer , $ count ) . $ node [ $ value ] ; $ stack [ ] = $ node [ $ right ] ; } return $ tree ; }
Map a nested tree using the primary key and display field as the values to populate the list.
Nested lists will be prepended with a spacer to indicate indentation.

@param array $nodes
@param string $key
@param string $value
@param string $spacer
@return array
Map a nested tree using the primary key and display field as the values to populate the list . Nested lists will be prepended with a spacer to indicate indentation .