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.

All other Modules /

Discuss all other Modules here.

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

[Solved] Event Calendar - show past events


Go to End


13 Posts   3114 Views

Avatar
borriej

Community Member, 267 Posts

4 March 2011 at 6:50am

Another question:

when using control children, the events aren't sorted by event date, but by pagetree position.

I need a function that gets all events from the past year:


	public function ShowAllEventsPlease() {
		$startdate = date('Y-m-d', strtotime(date('Y-m-d') . " - 1 year")));
		return DataObject::get_one("Calendar")->Events(null, $startdate, null, false, 9999, null);
	}

but now i get a code error, whats the correct code?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 March 2011 at 8:16am

Try this:

$startdate = sfDate::getInstance()->previousYear()->firstDayOfYear();
$enddate = sfDate::getInstance()->previousYear()->finalDayOfYear();
return DataObject::get_one("Calendar")->Events(null, $startdate, $enddate, false, 9999, null);

Avatar
borriej

Community Member, 267 Posts

4 March 2011 at 11:02am

Hmm to bad!

i get error:

Fatal error: Class 'sfDateTimeException' not found in /public/sites/url/event_calendar/code/sfDate.class.php on line 244

Another idea?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

5 March 2011 at 3:47am

Maybe it's subtractYear().. I don't remember. You can look at the API.

Avatar
borriej

Community Member, 267 Posts

7 March 2011 at 5:22am

This works to show all past & future events!

public function ShowAllEventsPlease() {
	$startdate = sfDate::getInstance()->subtractYear(1)->firstDayOfYear();
	$enddate = sfDate::getInstance()->addYear(6)->finalDayOfYear();
	return DataObject::get_one("Calendar")->Events(null, $startdate, $enddate, false, 9999, null);
}

Go to Top