protected function addCollectionNodesIntoGroupsOrNodes($collections, $groups, $nodes)
{
$normalCollections = [];
$groupCollections = [];
// some collections may belong to a group...
foreach ($collections as $collection) {
$group = $collection['group'];
$category = $collection['category'] ?: 'Uncategorized';
$name = $collection['collectionName'];
if ($group) {
if (!isset($groupCollections[$group])) {
$groupCollections[$group] = [];
}
if (!isset($groupCollections[$group][$category])) {
$groupCollections[$group][$category] = [];
}
if (!isset($groupCollections[$group][$category][$name])) {
$groupCollections[$group][$category][$name] = [];
}
$groupCollections[$group][$category][$name][] = $collection;
} else {
$normalCollections = $this->appendToArray($normalCollections, $name, $collection);
}
}
// handle collections as normal
foreach ($normalCollections as $collectionName => $collectionFields) {
$nodes[] = $this->buildCollectionNode($collectionName, $collectionFields);
}
// put the collection node inside of the group/category pair...
foreach ($groupCollections as $groupName => $categories) {
foreach ($categories as $categoryName => $collection) {
foreach ($collection as $collectionName => $collectionFields) {
if (!isset($groups[$groupName])) {
$groups[$groupName] = [];
}
if (!isset($groups[$groupName][$categoryName])) {
$groups[$groupName][$categoryName] = [];
}
$groups[$groupName][$categoryName][] = $this->buildCollectionNode($collectionName, $collectionFields);
}
}
}
return array($groups, $nodes);
}