/** * get the end of this event as a dateTimeObject * * @return Tx_CzSimpleCal_Utility_DateTime */ public function getDateTimeObjectEnd() { if (is_null($this->dateTimeObjectEnd)) { $this->dateTimeObjectEnd = new Tx_CzSimpleCal_Utility_DateTime('@' . $this->end); $this->dateTimeObjectEnd->setTimezone(new DateTimeZone(date_default_timezone_get())); } return $this->dateTimeObjectEnd; }
/** * get a DateTime object of the recurranceUntil feature * * @return DateTime */ public function getDateTimeObjectRecurranceUntil() { if (is_null($this->recurranceUntilDateTime)) { $this->recurranceUntilDateTime = new Tx_CzSimpleCal_Utility_DateTime($this->recurranceUntil > 0 ? '@' . $this->recurranceUntil : Tx_CzSimpleCal_Utility_Config::get('recurrenceEnd')); $this->recurranceUntilDateTime->setTimezone(new DateTimeZone($this->timezone)); $this->recurranceUntilDateTime->setTime(23, 59, 59); } return $this->recurranceUntilDateTime; }
/** * find all events matching some settings and count them * * @param $settings * @ugly doing dozens of database requests * @return array */ protected function doCountAllWithSettings($settings = array()) { if (!isset($settings['groupBy'])) { return $this->setupSettings($settings)->count(); } else { $output = array(); if ($settings['groupBy'] === 'day') { $step = '+1 day'; } elseif ($settings['groupBy'] === 'week') { $step = '+1 week'; } elseif ($settings['groupBy'] === 'month') { $step = '+1 month'; } elseif ($settings['groupBy'] === 'year') { $step = '+1 year'; } else { $step = null; } $startDate = new Tx_CzSimpleCal_Utility_DateTime('@' . $settings['startDate']); $startDate->setTimezone(new DateTimeZone(date_default_timezone_get())); $endDate = $settings['endDate']; while ($startDate->getTimestamp() < $endDate) { if ($step === null) { $tempEndDate = null; } else { $tempEndDate = clone $startDate; $tempEndDate->modify($step . ' -1 second'); } $output[] = array('date' => $startDate->format('c'), 'count' => $this->doCountAllWithSettings(array_merge($settings, array('startDate' => $startDate->format('U'), 'endDate' => $tempEndDate ? $tempEndDate->format('U') : null, 'groupBy' => null)))); if ($step === null) { break; } else { $startDate->modify($step); } } return $output; } }