Skip to content

Commit

Permalink
Merge pull request #46 from mattcockayne/RecurringEventsForMultipleDa…
Browse files Browse the repository at this point in the history
…teTimes

Recurring events for multiple date times
  • Loading branch information
unclecheese committed Apr 29, 2014
2 parents eda2689 + 37b6161 commit 0acc856
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions code/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public function getEventList($start, $end, $filter = null, $limit = null, $annou
"CalendarID" => $calendar->ID
))
->exclude(array(
"StartDate:LessThan" => $end,
"EndDate:GreaterThan" => $start,
"StartDate:LessThan" => $start,
"EndDate:GreaterThan" => $end,
));
if($announcement_filter) {
$announcements = $announcements->where($announcement_filter);
Expand Down Expand Up @@ -294,12 +294,22 @@ protected function addRecurringEvents($start_date, $end_date, $recurring_events,
$relation = $recurring_event->getReverseAssociation($this->getDateTimeClass());
if(!$relation) continue;

if($recurring_event_datetime = $recurring_event->$relation()->first()) {
$recurring_event_datetimes = $recurring_event->$relation()->filter(array(
'StartDate:LessThanOrEqual' => $end->date(),
'EndDate:GreaterThanOrEqual' => $date_counter->date(),
));

foreach ($recurring_event_datetimes as $recurring_event_datetime) {
$date_counter = sfDate::getInstance($start_date);
$start = sfDate::getInstance($recurring_event_datetime->StartDate);
if ($start->get() > $date_counter->get()) {
$date_counter = $start;
}
while($date_counter->get() <= $end->get()){
// check the end date
if($recurring_event_datetime->EndDate) {
$end_stamp = strtotime($recurring_event_datetime->EndDate);
if($end_stamp > 0 && $end_stamp < $date_counter->get()) {
if($end_stamp > 0 && $end_stamp < $date_counter->get()) {
break;
}
}
Expand Down

0 comments on commit 0acc856

Please sign in to comment.