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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Event Calendar Upcoming Events issue with multiple day recurrences


Go to End


919 Views

Avatar
BG

Community Member, 3 Posts

24 February 2014 at 5:28pm

Edited: 24/02/2014 5:58pm

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