function isHoliday($date = 0) { // Query database for settings $holiday_manual = db_loadResult('SELECT holiday_manual FROM holiday_settings'); $holiday_auto = db_loadResult('SELECT holiday_auto FROM holiday_settings'); $holiday_driver = db_loadResult('SELECT holiday_driver FROM holiday_settings'); if (!$date) { $date = new CDate(); } if ($holiday_manual) { // Check whether the date is blacklisted $sql = "SELECT * FROM holiday "; $sql .= "WHERE ( date(holiday_start_date) <= '"; $sql .= $date->format('%Y-%m-%d'); $sql .= "' AND date(holiday_end_date) >= '"; $sql .= $date->format('%Y-%m-%d'); $sql .= "' AND holiday_white=0 ) "; $sql .= "OR ( "; $sql .= " DATE_FORMAT(holiday_start_date, '%m-%d') <= '"; $sql .= $date->format('%m-%d'); $sql .= "' AND DATE_FORMAT(holiday_end_date, '%m-%d') >= '"; $sql .= $date->format('%m-%d'); $sql .= "' AND holiday_annual=1"; $sql .= " AND holiday_white=0 ) "; if (db_loadResult($sql)) { return 0; } // Check if we have a whitelist item for this date $sql = "SELECT * FROM holiday "; $sql .= "WHERE ( date(holiday_start_date) <= '"; $sql .= $date->format('%Y-%m-%d'); $sql .= "' AND date(holiday_end_date) >= '"; $sql .= $date->format('%Y-%m-%d'); $sql .= "' AND holiday_white=1 ) "; $sql .= "OR ( "; $sql .= " DATE_FORMAT(holiday_start_date, '%m-%d') <= '"; $sql .= $date->format('%m-%d'); $sql .= "' AND DATE_FORMAT(holiday_end_date, '%m-%d') >= '"; $sql .= $date->format('%m-%d'); $sql .= "' AND holiday_annual=1"; $sql .= " AND holiday_white=1 ) "; if (db_loadResult($sql)) { return 1; } } if ($holiday_auto) { // Still here? Ok, lets poll the automatic system $drivers_alloc = Date_Holidays::getInstalledDrivers(); $driver_object = Date_Holidays::factory($drivers_alloc[$holiday_driver]['title'], $date->getYear(), 'en_EN'); if (!Date_Holidays::isError($driver_object)) { if ($driver_object->getHolidayForDate($date)) { return 1; } } } // No hits, must be a working day return 0; }
/** * 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; }
private function _getEvents($dh, $startDate, $endDate) { $events = array(); for ($date = new Horde_Date($startDate); $date->compareDate($endDate) <= 0; $date->mday++) { $holidays = $dh->getHolidayForDate($date->format('Y-m-d'), null, true); if (Date_Holidays::isError($holidays)) { Horde::log(sprintf('Unable to retrieve list of holidays from %s to %s', (string) $startDate, (string) $endDate), __FILE__, __LINE__); continue; } if (is_null($holidays)) { continue; } foreach ($holidays as $holiday) { $event = new Kronolith_Event_Holidays($this, $holiday); $events[] = $event; } } return $events; }
/** * Returns dates of all holidays or those accepted by the applied filter. * * Structure of the returned array: * <pre> * array( * 'internalNameFoo' => object of type date, * 'internalNameBar' => object of type date * ) * </pre> * * @param Date_Holidays_Filter $filter filter-object (or an array !DEPRECATED!) * * @access public * @return array with holidays' dates on success, otherwise a PEAR_Error object * @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME * @uses getHolidayDate() */ function getHolidayDates($filter = null) { if (is_null($filter)) { $filter = new Date_Holidays_Filter_Blacklist(array()); } elseif (is_array($filter)) { $filter = new Date_Holidays_Filter_Whitelist($filter); } $dates = array(); foreach ($this->_internalNames as $internalName) { if ($filter->accept($internalName)) { $date = $this->getHolidayDate($internalName); if (Date_Holidays::isError($date)) { return $date; } $dates[$internalName] = $this->getHolidayDate($internalName); } } return $dates; }
/** * 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; }
public static function getHolidayTitle($date = 0, $userid = 0) { global $AppUI; self::loadHolidaysSettings(); if (!$date) { $date = new w2p_Utilities_Date(); } if (self::$holiday_manual) { $q = new w2p_Database_Query(); // Check if we have a whitelist item for this date $q->addTable("holiday"); $q->addQuery("holiday_description"); $where = "( date(holiday_start_date) <= '"; $where .= $date->format('%Y-%m-%d'); $where .= "' AND date(holiday_end_date) >= '"; $where .= $date->format('%Y-%m-%d'); if ($userid > 0) { $where .= "' AND ("; $where .= "(holiday_user=0 AND holiday_type=" . HOLIDAY_TYPE_COMPANY_HOLIDAY . ")"; $where .= " OR "; $where .= "(holiday_user="******" AND holiday_type=" . HOLIDAY_TYPE_USER_HOLIDAY . ")"; $where .= ")"; } else { $where .= "' AND holiday_type=" . HOLIDAY_TYPE_COMPANY_HOLIDAY; } $where .= " ) OR ( "; $where .= " DATE_FORMAT(holiday_start_date, '%m-%d') <= '"; $where .= $date->format('%m-%d'); $where .= "' AND DATE_FORMAT(holiday_end_date, '%m-%d') >= '"; $where .= $date->format('%m-%d'); $where .= "' AND holiday_annual=1"; $where .= " AND holiday_type=" . HOLIDAY_TYPE_COMPANY_HOLIDAY . " )"; $q->addWhere($where); $holiday_description = $q->loadResult(); if ($holiday_description !== false) { return $holiday_description; } } if (self::$holiday_auto && self::$holiday_driver >= 0) { // Still here? Ok, lets poll the automatic system if (self::$holiday_driver_instance->getYear() != $date->getYear()) { self::$holiday_driver_instance->setYear($date->getYear()); self::$holiday_driver_instance->setLocale($AppUI->user_locale); } if (!Date_Holidays::isError(self::$holiday_driver_instance)) { $holidays = self::$holiday_driver_instance->getHolidayForDate($date, null, true); if (!is_null($holidays)) { $titles = array(); foreach ($holidays as $holiday) { if (is_null(self::$holiday_filter_instance) || self::$holiday_filter_instance->accept($holiday->getInternalName())) { $title = $holiday->getTitle(); if (!in_array($title, $titles)) { $titles[] = gettype($title) == 'object' ? $title->getMessage() : $title; } } } return implode("/", $titles); } } } return ""; }
/** * Returns localized titles of all holidays or those specififed in * $restrict array * * @param Date_Holidays_Filter $filter filter-object * (or an array !DEPRECATED!) * @param string $locale locale setting that shall be used by * this method * * @access public * @return array array with localized holiday titles on success, * otherwise a PEAR_Error object * @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME */ function getHolidayTitles($filter = null, $locale = null) { if (is_null($filter)) { $filter = new Date_Holidays_Filter_Blacklist(array()); } elseif (is_array($filter)) { $filter = new Date_Holidays_Filter_Whitelist($filter); } $errorStack =& Date_Holidays::getErrorStack(); $titles = array(); $notFound = array(); foreach ($this->_internalNames as $internalName) { // check if the filter permits further processing if (!$filter->accept($internalName)) { continue; } foreach ($this->_driverIds as $id) { $title = $this->_drivers[$id]->getHolidayTitle($internalName, $locale); if (Date_Holidays::isError($title)) { /** * current driver doesn't have this internalName, trying next * driver */ array_push($notFound, $internalName); continue; } /** * internal name found in highest priorized driver, stepping to * next internal name checks if internal name is existent in * $notFound array and unsets this entry as it has been found now */ $notFound = array_unique($notFound); if (in_array($internalName, $notFound)) { unset($notFound[array_search($internalName, $notFound)]); } $titles[$internalName] = $title; continue 2; } } if (!empty($notFound)) { foreach ($notFound as $internalName) { $errorStack->push(DATE_HOLIDAYS_INVALID_INTERNAL_NAME, 'error', array(), 'Invalid internal name: ' . $internalName, false, debug_backtrace()); } } if ($errorStack->hasErrors() && !empty($notFound)) { return $errorStack; } return $titles; }