Skip to content

Commit 001775e

Browse files
committed
Added method for getting full paths list
1 parent ea9347d commit 001775e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/behaviors/NestedSetsManagementBehavior.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,36 @@ public function getHierarchicalArray()
7777

7878
return $result;
7979
}
80+
81+
/**
82+
* @return array
83+
*/
84+
public function getFullPathsList()
85+
{
86+
return $this->fillPath($this->getHierarchicalArray());
87+
}
88+
89+
/**
90+
* @param array $items
91+
* @param array $path
92+
* @param array $result
93+
* @return array
94+
*/
95+
protected function fillPath($items, &$path = [], &$result = [])
96+
{
97+
foreach ($items as $item) {
98+
$result[$item['id']] = implode(' / ', array_merge($path, [$item['text']]));
99+
100+
if (isset($item['children'])) {
101+
$path[] = $item['text'];
102+
$this->fillPath($item['children'], $path, $result);
103+
}
104+
105+
if ($item === end($items)) {
106+
array_pop($path);
107+
}
108+
}
109+
110+
return $result;
111+
}
80112
}

0 commit comments

Comments
 (0)