Skip to content

Commit

Permalink
Added method for getting full paths list
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Jun 13, 2015
1 parent ea9347d commit 001775e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/behaviors/NestedSetsManagementBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,36 @@ public function getHierarchicalArray()

return $result;
}

/**
* @return array
*/
public function getFullPathsList()
{
return $this->fillPath($this->getHierarchicalArray());
}

/**
* @param array $items
* @param array $path
* @param array $result
* @return array
*/
protected function fillPath($items, &$path = [], &$result = [])
{
foreach ($items as $item) {
$result[$item['id']] = implode(' / ', array_merge($path, [$item['text']]));

if (isset($item['children'])) {
$path[] = $item['text'];
$this->fillPath($item['children'], $path, $result);
}

if ($item === end($items)) {
array_pop($path);
}
}

return $result;
}
}

0 comments on commit 001775e

Please sign in to comment.