/** * Lists all events in the time range, optionally restricting results to * only events with alarms. * * @param Horde_Date $startDate The start of range date. * @param Horde_Date $endDate The end of date range. * @param array $options Additional options: * - show_recurrence: (boolean) Return every instance of a recurring * event? * DEFAULT: false (Only return recurring events once * inside $startDate - $endDate range) * - has_alarm: (boolean) Only return events with alarms. * DEFAULT: false (Return all events) * - json: (boolean) Store the results of the event's toJson() * method? * DEFAULT: false * - cover_dates: (boolean) Add the events to all days that they * cover? * DEFAULT: true * - hide_exceptions: (boolean) Hide events that represent exceptions to * a recurring event. * DEFAULT: false (Do not hide exception events) * - fetch_tags: (boolean) Fetch tags for all events. * DEFAULT: false (Do not fetch event tags) * * @throws Kronolith_Exception */ protected function _listEvents(Horde_Date $startDate = null, Horde_Date $endDate = null, array $options = array()) { if (!class_exists('Date_Holidays')) { Horde::log('Support for Date_Holidays has been enabled but the package seems to be missing.', 'ERR'); return array(); } if (is_null($startDate) && !is_null($endDate)) { $startDate = clone $endDate; $startDate->year--; } if (is_null($endDate) && !is_null($startDate)) { $endDate = clone $startDate; $endDate->year++; } if ($options['has_alarm'] || is_null($startDate) || is_null($endDate)) { return array(); } $startDate = clone $startDate; $startDate->hour = $startDate->min = $startDate->sec = 0; $endDate = clone $endDate; $endDate->hour = 23; $endDate->min = $endDate->sec = 59; Date_Holidays::staticSetProperty('DIE_ON_MISSING_LOCALE', false); $results = array(); for ($year = $startDate->year; $year <= $endDate->year; $year++) { $dh = Date_Holidays::factory($this->calendar, $year, $this->_params['language']); if (Date_Holidays::isError($dh)) { Horde::log(sprintf('Factory was unable to produce driver object for driver %s in year %s with locale %s', $this->calendar, $year, $this->_params['language']), 'ERR'); continue; } $dh->addTranslation($this->_params['language']); $events = $this->_getEvents($dh, $startDate, $endDate); foreach ($events as $event) { Kronolith::addEvents($results, $event, $startDate, $endDate, $options['show_recurrence'], $options['json'], $options['cover_dates']); } } return $results; }
/** * Factory method that creates a driver-object * * @param string $driverId driver-name * @param string $year year * @param string $locale locale name * @param boolean $external external driver * * @static * @access public * @return object Date_Holidays driver-object on success, * otherwise a PEAR_Error object * @throws object PEAR_Error */ function factory($driverId, $year = null, $locale = null, $external = false) { if (!isset($GLOBALS['_DATE_HOLIDAYS']['DIE_ON_MISSING_LOCALE'])) { Date_Holidays::staticSetProperty('DIE_ON_MISSING_LOCALE', true); } $driverId = basename($driverId); $driverClass = 'Date_Holidays_Driver_' . $driverId; if ($external) { $driverClass = $driverId; } if (!class_exists($driverClass)) { $driverFile = 'Holidays/Driver/' . $driverId . '.php'; if ($external) { $driverFile = str_replace('_', '/', $driverClass) . '.php'; } @(include_once $driverFile); if (!class_exists($driverClass)) { return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Couldn\'t find file of the driver-class, filename: ' . $driverFile); } } $driver = new $driverClass(); if (is_null($year)) { $year = date('Y'); } // sets internal var $_year and performs _buildHolidays() $res = $driver->setYear($year); if (Date_Holidays::isError($res)) { return $res; } if (is_null($locale)) { $locale = setlocale(LC_MESSAGES, 0); //encoding might be appended to the locale, For example en_IE.UTF-8 //so ignore it $tmp = explode(".", $locale); $locale = $tmp[0]; } $driver->setLocale($locale); return $driver; }
/** * Factory method that creates a driver-object * * @static * @access public * @param string $driverId driver-name * @param string $year year * @param string $locale locale name * @return object Date_Holidays driver-object on success, otherwise a PEAR_Error object * @throws object PEAR_Error */ function factory($driverId, $year = null, $locale = null, $external = false) { if (!isset($GLOBALS['_DATE_HOLIDAYS']['DIE_ON_MISSING_LOCALE'])) { Date_Holidays::staticSetProperty('DIE_ON_MISSING_LOCALE', true); } $driverClass = 'Date_Holidays_Driver_' . $driverId; if ($external) { $driverClass = $driverId; } if (!class_exists($driverClass)) { //$driverFile = 'Date' . DIRECTORY_SEPARATOR . 'Holidays' . DIRECTORY_SEPARATOR . // 'Driver' . DIRECTORY_SEPARATOR . $driverId . '.php'; $driverFile = 'Holidays' . DIRECTORY_SEPARATOR . 'Driver' . DIRECTORY_SEPARATOR . $driverId . '.php'; if ($external) { $driverFile = str_replace('_', DIRECTORY_SEPARATOR, $driverClass) . '.php'; } @(include_once $driverFile); if (!class_exists($driverClass)) { return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Couldn\'t find file of the driver-class, filename: ' . $driverFile); } } $driver = new $driverClass(); if (is_null($year)) { $year = date('Y'); } // sets internal var $_year and performs _buildHolidays() $res = $driver->setYear($year); if (Date_Holidays::isError($res)) { return $res; } if (is_null($locale)) { $locale = setlocale(LC_ALL, null); } $driver->setLocale($locale); return $driver; }