5

I'm trying to return a single GroupedList which holds information from both pages and dataobjects. Is there an easy way to merge the two lists together?

public function getGroupedContent()
{
    $dataobjects = GroupedList::create(FileNetObject::get());
    $pages = GroupedList::create($this->Children());

    $result = ??;


    return $result;
}

The ArrayList merge fails as does a standard array_merge - Would I be best merging the results from the queries together before putting it into a single GroupedList?

Bruce
  • 1,647
  • 4
  • 20
  • 22
Chris
  • 3,437
  • 6
  • 40
  • 73
  • do FileNetObject and $this->Children() have anything in common? both are pages? or can you group them by some common fields or getters? – wmk Aug 13 '15 at 11:42
  • @wmk both contain title fields which I'm using to group on. – Chris Aug 13 '15 at 20:47

1 Answers1

1

Without knowing more about your situation, the simplest way to do this is:

return array_merge($dataobjects->toArray(), $pages->toArray());

To display the above in a template you would of course need to wrap that in another ArrayList.

Updated: If you want to group the lists (which of course is why you were using a GroupedList in the first place) you would need to do it before merging the arrays. More like:

return array_merge($dataobjects->GroupBy('Author')->toArray(), $page->GroupBy('Author')->toArray());
Mark Guinn
  • 619
  • 3
  • 8
  • Following above, and then placing the results of the array_merge into another ArrayList, would I need to modify the template to anything other than looping the children of the groupedlist? (currently renders nothing) – Chris Aug 13 '15 at 20:50
  • Sorry, I just noticed your comment. Without seeing your template it's hard to say. If you still have $GroupBy in your template you would want to remove that bit. Otherwise if you post your code I can try to look further. – Mark Guinn Sep 11 '15 at 10:57