Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » Event Calendar Upcoming Events issue with multiple day recurrences

Discuss all other Modules here.

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

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

    Event Calendar Upcoming Events issue with multiple day recurrences Link to this post

    Hey there, I've made a small function for a radio program guide to figure out what's on "now, next and later" in the calendar based on the time - not just the day as the upcoming events function does.
    My problem lies with events that have more than one RecurringDaysOfWeek (e.g. Monday to Friday - 6am to 9am).
    They show up fine in UpcomingEvents, but when I try to filter them by times, these "multiple days per week" events do not show. Events that only have one day per week work fine.
    Can anyone shed some light as to why it's only problematic with these "multiple days per week" events?
    Here is my function to filter by time (it's in 30 min blocks because that is the absolute minimum length of a show)

    class NowOnWidget_Controller extends Widget_Controller {
       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;
          }else{
             $ts[0]++;
             $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[0]++;
                $ts[1] = "00";
             }
             $i++;
          }
          //print_r($times);

          //Return filtered Events
          $all = Calendar::get()->first()->UpcomingEvents(9);
          $uc = $all->filter(array('EndTime' => $times))->limit(3);
          
          return $uc;
       }
    }

    I'm using SS 3.0.5

    175 Views
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.