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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Adding a value to DataObject Set


Go to End


3 Posts   2073 Views

Avatar
iON creative

Community Member, 42 Posts

31 May 2010 at 10:06pm

Hi all

I've been wracking my brain over something I'm sure is very simple, but it's driving me mad! I need to iterate through a DataObjectSet to find any results that fall within a specific date range so that I can highlight a current event. I think I'm close to the result, but I just can't figure out how to add a value to my DataObjectSet to flag this result in my template.

Here's my code - any advice most welcome!

function ExhibitionSydney() {
		$now = date("Y-m-d",time());

	//	Retrieve all Exhibitions 
		$exhibitions = DataObject::get('Exhibition', '','DateFrom DESC');

	//	Iterate through Exhibitions to find any that fall on the current date
			foreach($exhibitions as $exhibition){
					if ( $now >= $exhibition->DateFrom && $now <= $exhibition->DateTo )	{
				//	if the result falls within the current date, add Current=>true to the dataobjectset
					???????
				}	
			}
		
		return $exhibitions;
	} 

I'm running SS 2.3.7

Thanks for any assistance in advance,

Y

Avatar
Jedateach

Forum Moderator, 238 Posts

31 May 2010 at 10:23pm

$exhibition->Current = true;

Avatar
iON creative

Community Member, 42 Posts

31 May 2010 at 10:30pm

Oh man was I overthinking that one. Thanks heaps it's done the trick.

Cheers, Y