feat: Add hierarchy endpoint #2
@ -141,21 +141,25 @@ class ItemsCollection
|
|||||||
|
|
||||||
// Initialize the hierarchy with the current item
|
// Initialize the hierarchy with the current item
|
||||||
$item = [
|
$item = [
|
||||||
'_id' => $itemData['_id'],
|
'item'=> [
|
||||||
'_name' => $itemData['_name'],
|
'_id' => $itemData['_id'],
|
||||||
'_parent' => $itemData['_parent'],
|
'_name' => $itemData['_name'],
|
||||||
|
'_parent' => $itemData['_parent']
|
||||||
|
],
|
||||||
'locale' => $this->locales[$locale][$id] ?? ''
|
'locale' => $this->locales[$locale][$id] ?? ''
|
||||||
];
|
];
|
||||||
$hierarchy = collect([$id => $item]);
|
$hierarchy = collect([$id => $item]);
|
||||||
|
|
||||||
// Check the whole hierarchy and merge into the return variable
|
// Check the whole hierarchy and merge into the return variable
|
||||||
while (!empty($item['_parent'] ?? '')) {
|
while (!empty($item['item']['_parent'] ?? '')) {
|
||||||
$itemtId = $item['_parent'];
|
$itemtId = $item['item']['_parent'];
|
||||||
$itemData = $this->items[$itemtId] ?? null;
|
$itemData = $this->items[$itemtId] ?? null;
|
||||||
$item = [
|
$item = [
|
||||||
'_id' => $itemData['_id'],
|
'item'=> [
|
||||||
'_name' => $itemData['_name'],
|
'_id' => $itemData['_id'],
|
||||||
'_parent' => $itemData['_parent'],
|
'_name' => $itemData['_name'],
|
||||||
|
'_parent' => $itemData['_parent']
|
||||||
|
],
|
||||||
'locale' => $this->locales[$locale][$itemtId] ?? ''
|
'locale' => $this->locales[$locale][$itemtId] ?? ''
|
||||||
];
|
];
|
||||||
$hierarchy = $hierarchy->merge([$itemtId => $item]);
|
$hierarchy = $hierarchy->merge([$itemtId => $item]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user