Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

How to merge two DataObjectSets


Reply

3 Posts   1615 Views

Avatar
novaweb

16 April 2010 at 9:25am (Last edited: 16 April 2010 9:26am), Community Member, 115 Posts

Hey guys,

Really simple one here. I'm wondering if one can take two DataObjectSets (from two separate DataObject::get requests) and join them together.

I have two different DataObjects, Module.php and Course.php. I want to call both of them using one function, so I can order both Modules AND Courses by Title ASC using a control block.

Currently the code I have is:

function Modules(){
return DataObject::get("Module");
}

function Courses(){
return DataObject::get("Course");
}

Can I do what i'm trying to achieve in it's own function? Or can I reference the above functions in another function to achieve the join?

Cheers,
Josh

Avatar
dayer

17 August 2010 at 5:01am Community Member, 11 Posts

I have the same doubt.

Avatar
swaiba

17 August 2010 at 9:01am Forum Moderator, 1796 Posts

how about...

function Composite()
{    
   $dosComposite = new DataObjectSet();
   $dosComposite->merge($this->Modules());      
   $dosComposite->merge($this->Courses());      
   $dosComposite->sort('FieldName','ASC');
   
   return $dosComposite;
}