I have expanded Zend_View_Helper_Navigation_Menuand it uses RecursiveIteratorIteratormenus to iterate through the tree. What I want is to determine if I am on the first or last element for the branch level in the tree.
Here is an example of what I'm looking for:
- Nav 1 (first)
- Nav 1.1 (first and last)
- Nav 1.1.1 (first)
- Nav 1.1.2
- Nav 1.1.3 (last)
- Nav 2
- Nav 2.1 (first)
- Nav 2.2 (last)
- Nav 3 (last)
- Nav 3.1 (first)
- Nav 3.2 (last)
Additional Information
Decision
In a loop, foreach ($iterator as $page)you can use two variables, $depthand , to track depths $prevDepth. A simple example of comparison can then identify the first element at threads: if ($depth > $prevDepth).
RecursiveCachingIterator Zend_Navigation_Container, RecursiveIteratorIterator hasNext().
$rci = new RecursiveCachingIterator($container, CachingIterator::FULL_CACHE);
$iterator = new RecursiveIteratorIterator($rci,
RecursiveIteratorIterator::SELF_FIRST);
$prevDepth = -1;
foreach ($iterator as $page) {
$depth = $iterator->getDepth();
if ($depth > $prevDepth) {
}
if (!$iterator->hasNext()) {
}
$prevDepth = $depth;
}