public function recursionHappensOn($ts) { $objTestDate = new sfDate($ts); $objStartDate = new sfDate($this->ts); // Current date is before the recurring event begins. if ($objTestDate->get() < $objStartDate->get()) { return false; } elseif (in_array($objTestDate->date(), $this->exceptions)) { return false; } switch ($this->event->CustomRecursionType) { // Daily case 1: return $this->event->DailyInterval ? ($ts - $this->ts) / self::DAY % $this->event->DailyInterval == 0 : false; break; // Weekly // Weekly case 2: return ($objTestDate->firstDayOfWeek()->get() - $objStartDate->firstDayOfWeek()->get()) / self::WEEK % $this->event->WeeklyInterval == 0 && in_array($objTestDate->reset()->format('w'), $this->allowedDaysOfWeek); break; // Monthly // Monthly case 3: if (self::difference_in_months($objTestDate, $objStartDate) % $this->event->MonthlyInterval == 0) { // A given set of dates in the month e.g. 2 and 15. if ($this->event->MonthlyRecursionType1 == 1) { return in_array($objTestDate->reset()->format('j'), $this->allowedDaysOfMonth); } elseif ($this->event->MonthlyRecursionType2 == 1) { // Last day of the month? if ($this->event->MonthlyIndex == 5) { $targetDate = $objTestDate->addMonth()->firstDayOfMonth()->previousDay($this->event->MonthlyDayOfWeek)->dump(); } else { $objTestDate->subtractMonth()->finalDayOfMonth(); for ($i = 0; $i < $this->event->MonthlyIndex; $i++) { $objTestDate->nextDay($this->event->MonthlyDayOfWeek)->dump(); } $targetDate = $objTestDate->dump(); } return $objTestDate->reset()->dump() == $targetDate; } } return false; } }
protected function getWeeks() { $weeks = new DataObjectSet(); $today = new sfDate(); $today->clearTime(); $this->date_counter->firstDayOfMonth()->firstDayOfWeek(); $view_start = new sfDate($this->date_counter->get()); $view_end = new sfDate($view_start->addDay($this->rows * 7)->subtractDay()->get()); $view_start->reset(); $this->start_date->reset(); $event_map = $this->getEventsFor($view_start, $view_end); for ($i = 0; $i < $this->rows; $i++) { $days = new DataObjectSet(); $week_range_start = $this->date_counter->format('Ymd'); for ($j = 0; $j < 7; $j++) { $current_day = ""; if (!$this->default_view) { if ($this->date_counter->get() >= $this->anchor_start->get() && $this->date_counter->get() <= $this->anchor_end->get()) { $current_day = "currentDay"; } } $days->push(new ArrayData(array('Today' => $this->date_counter->get() == $today->get() ? "calendarToday" : "", 'OutOfMonth' => $this->date_counter->format('m') != $this->start_date->format('m') ? "calendarOutOfMonth" : "", 'CurrentDay' => $current_day, 'HasEvent' => in_array($this->date_counter->date(), $event_map) ? "hasEvent" : "", 'ShowDayLink' => $this->calendar->Link('view') . "/" . $this->date_counter->format('Ymd'), 'Number' => $this->date_counter->format('d')))); $this->date_counter->addDay(); } $week_range_end = $this->date_counter->subtractDay()->format('Ymd'); $this->date_counter->addDay(); $weeks->push(new ArrayData(array('Days' => $days, 'ShowWeekLink' => $this->calendar->Link('view') . "/" . $week_range_start . "/" . $week_range_end))); } return $weeks; }