Jump to:

10987 Posts in 2724 Topics by 1817 members

All other Modules

SilverStripe Forums » All other Modules » Event Calendar - Upcoming Events help!

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 401 Views
  • BG
    Community Member
    3 Posts

    Event Calendar - Upcoming Events help! Link to this post

    Hi There,

    I am trying to do a (basic?) thing with UpcomingEvents()...
    I want it to display the current event, followed by 2 next events in the first calendar, although I have noticed that UpcomingEvents() only returns results based on dates rather than times...

    Is there another way to do this? I have tried using ->filter("EndTime:GreaterThan", date("H:m:s")) to no avail, as it seems :GreaterThan doesn't work on time fields???.
    Maybe there is an easier field to be filtering my dates from? (the "dtend" span in the $DateRange template variable would be good if it wasn't wrapped with HTML)

    The end goal is to have a widget displaying "Now", "Next" and "Later" from the calendar.

    I am currently resorting to this function that assumes all items are set to start and finish on the half hour.
    I've made it so it can't collect anything past midnight, as unfortunately the Item List does not get ordered by the order of my $times array.

       public function UpcomingEvents() {
          //Get Current Date/Time
          $now = array(
             'date' => date("Y-m-d"),
             'time' => date("H:i:s"),
          //Split and round up Current Time
          $ts = split(":",$now['time']);
          $ts[2] = "00";
          if($ts[1] < 31){
             $ts[1] = 30;
             $ts[1] = "00";
          //Create a list of half hour blocks in the next 24hrs
          $i = 0;
          $times = array();
          while($i < 48){
             if($ts[0] == 24){
                $ts[0] = "00";
                $i = 47;
             $times[] = $ts[0].":".$ts[1].":".$ts[2];
             $ts[1] = $ts[1]+30;
             if($ts[1] == 60){
                $ts[1] = "00";
          //Return filtered Events
          $all = Calendar::get()->first()->UpcomingEvents(20);
          return $all->filter(array('EndTime' => $times))->limit(3);

    Hope you can help, and thanks

  • BG
    Community Member
    3 Posts

    Re: Event Calendar - Upcoming Events help! Link to this post


Page: 1
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.