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.

All other Modules /

Discuss all other Modules here.

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

[Solved] Event Calendar - show past events


Go to End
Reply


13 Posts   1966 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, 4096 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, 4096 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