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


Reply

13 Posts   1871 Views

Avatar
borriej

4 March 2011 at 6:50am Community Member, 267 Posts

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

4 March 2011 at 8:16am 4085 Posts

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

4 March 2011 at 11:02am Community Member, 267 Posts

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

5 March 2011 at 3:47am 4085 Posts

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

Avatar
borriej

7 March 2011 at 5:22am Community Member, 267 Posts

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);
}