feat: Add hierarchy endpoint #2

Merged
Rev merged 2 commits from :master into master 2021-10-14 04:34:06 -04:00
Showing only changes of commit 3c4441bd59 - Show all commits

View File

@ -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]);