Jump to:

10848 Posts in 2516 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » [Solved] Event Calendar - show past events

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 1705 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    Re: [Solved] Event Calendar - show past events Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: [Solved] Event Calendar - show past events Link to this post

    Try this:

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

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: [Solved] Event Calendar - show past events Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: [Solved] Event Calendar - show past events Link to this post

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

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: [Solved] Event Calendar - show past events Link to this post

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

    1705 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.