Overview

Packages

  • Kronolith
  • None

Classes

  • Kronolith
  • Kronolith_Ajax_Application
  • Kronolith_Ajax_Imple_ContactAutoCompleter
  • Kronolith_Ajax_Imple_Embed
  • Kronolith_Ajax_Imple_TagActions
  • Kronolith_Ajax_Imple_TagAutoCompleter
  • Kronolith_Api
  • Kronolith_Calendar
  • Kronolith_Calendar_External
  • Kronolith_Calendar_External_Tasks
  • Kronolith_Calendar_Holiday
  • Kronolith_Calendar_Internal
  • Kronolith_Calendar_Remote
  • Kronolith_Calendar_Resource
  • Kronolith_Calendars_Base
  • Kronolith_Calendars_Default
  • Kronolith_Calendars_Kolab
  • Kronolith_Day
  • Kronolith_Driver
  • Kronolith_Driver_Holidays
  • Kronolith_Driver_Horde
  • Kronolith_Driver_Ical
  • Kronolith_Driver_Kolab
  • Kronolith_Driver_Mock
  • Kronolith_Driver_Resource
  • Kronolith_Driver_Sql
  • Kronolith_Event
  • Kronolith_Event_Holidays
  • Kronolith_Event_Horde
  • Kronolith_Event_Ical
  • Kronolith_Event_Kolab
  • Kronolith_Event_Resource
  • Kronolith_Event_Sql
  • Kronolith_Exception
  • Kronolith_Factory_Calendars
  • Kronolith_Factory_Geo
  • Kronolith_Form_CreateCalendar
  • Kronolith_Form_CreateResource
  • Kronolith_Form_CreateResourceGroup
  • Kronolith_Form_DeleteCalendar
  • Kronolith_Form_DeleteResource
  • Kronolith_Form_DeleteResourceGroup
  • Kronolith_Form_EditCalendar
  • Kronolith_Form_EditRemoteCalendar
  • Kronolith_Form_EditResource
  • Kronolith_Form_EditResourceGroup
  • Kronolith_Form_SubscribeRemoteCalendar
  • Kronolith_Form_UnsubscribeRemoteCalendar
  • Kronolith_FreeBusy
  • Kronolith_FreeBusy_View
  • Kronolith_FreeBusy_View_Day
  • Kronolith_FreeBusy_View_Month
  • Kronolith_FreeBusy_View_Week
  • Kronolith_FreeBusy_View_Workweek
  • Kronolith_Geo_Base
  • Kronolith_Geo_Mysql
  • Kronolith_Geo_Sql
  • Kronolith_LoginTasks_SystemTask_Upgrade
  • Kronolith_LoginTasks_Task_PurgeEvents
  • Kronolith_Notification_Listener_AjaxStatus
  • Kronolith_Resource
  • Kronolith_Resource_Base
  • Kronolith_Resource_Group
  • Kronolith_Resource_Single
  • Kronolith_Storage
  • Kronolith_Storage_Kolab
  • Kronolith_Storage_Sql
  • Kronolith_Tagger
  • Kronolith_Test
  • Kronolith_View_Day
  • Kronolith_View_DeleteEvent
  • Kronolith_View_EditEvent
  • Kronolith_View_Event
  • Kronolith_View_ExportEvent
  • Kronolith_View_Month
  • Kronolith_View_Week
  • Kronolith_View_WorkWeek
  • Kronolith_View_Year
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Kronolith_Driver_Holidays implements support for the PEAR package
  4:  * Date_Holidays.
  5:  *
  6:  * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @see     http://pear.php.net/packages/Date_Holidays
 12:  * @author  Stephan Hohmann <webmaster@dasourcerer.net>
 13:  * @package Kronolith
 14:  */
 15: class Kronolith_Driver_Holidays extends Kronolith_Driver
 16: {
 17:     public function listAlarms($date, $fullevent = false)
 18:     {
 19:         return array();
 20:     }
 21: 
 22:     /**
 23:      * Lists all events in the time range, optionally restricting results to
 24:      * only events with alarms.
 25:      *
 26:      * @param Horde_Date $startInterval  Start of range date object.
 27:      * @param Horde_Date $endInterval    End of range data object.
 28:      * @param boolean $showRecurrence    Return every instance of a recurring
 29:      *                                   event? If false, will only return
 30:      *                                   recurring events once inside the
 31:      *                                   $startDate - $endDate range.
 32:      * @param boolean $hasAlarm          Only return events with alarms? Has no
 33:      *                                   effect in this driver.
 34:      * @param boolean $json              Store the results of the events'
 35:      *                                   toJson() method?
 36:      * @param boolean $coverDates        Whether to add the events to all days
 37:      *                                   that they cover.
 38:      *
 39:      * @return array  Events in the given time range.
 40:      */
 41:     public function listEvents($startDate = null, $endDate = null,
 42:                                $showRecurrence = false, $hasAlarm = false,
 43:                                $json = false, $coverDates = true)
 44:     {
 45:         if (!class_exists('Date_Holidays')) {
 46:             Horde::logMessage('Support for Date_Holidays has been enabled but the package seems to be missing.', 'ERR');
 47:             return array();
 48:         }
 49: 
 50:         if (is_null($startDate) && !is_null($endDate)) {
 51:             $startDate = clone $endDate;
 52:             $startDate->year--;
 53:         }
 54:         if (is_null($endDate) && !is_null($startDate)) {
 55:             $endDate = clone $startDate;
 56:             $endDate->year++;
 57:         }
 58:         if ($hasAlarm || is_null($startDate) || is_null($endDate)) {
 59:             return array();
 60:         }
 61: 
 62:         $startDate = clone $startDate;
 63:         $startDate->hour = $startDate->min = $startDate->sec = 0;
 64:         $endDate = clone $endDate;
 65:         $endDate->hour = 23;
 66:         $endDate->min = $endDate->sec = 59;
 67: 
 68:         Date_Holidays::staticSetProperty('DIE_ON_MISSING_LOCALE', false);
 69: 
 70:         $results = array();
 71:         for ($year = $startDate->year; $year <= $endDate->year; $year++) {
 72:             $dh = Date_Holidays::factory($this->calendar, $year, $this->_params['language']);
 73:             if (Date_Holidays::isError($dh)) {
 74:                 Horde::logMessage(sprintf('Factory was unable to produce driver object for driver %s in year %s with locale %s',
 75:                                           $this->calendar, $year, $this->_params['language']), 'ERR');
 76:                 continue;
 77:             }
 78:             $dh->addTranslation($this->_params['language']);
 79:             $events = $this->_getEvents($dh, $startDate, $endDate);
 80:             foreach ($events as $event) {
 81:                 Kronolith::addEvents($results, $event, $startDate, $endDate,
 82:                                      $showRecurrence, $json, $coverDates);
 83:             }
 84:         }
 85: 
 86:         return $results;
 87:     }
 88: 
 89:     /**
 90:      * @throws Kronolith_Exception
 91:      * @throws Horde_Exception_NotFound
 92:      */
 93:     public function getEvent($eventId = null)
 94:     {
 95:         if (!$eventId) {
 96:             $date = new Date();
 97:             return new Kronolith_Event_Holidays($this, new Date_Holidays_Holiday(null, null, $date, null));
 98:         }
 99: 
100:         list($id, $date) = explode('-', $eventId, 2);
101:         $year = substr($date, 0, 4);
102: 
103:         $dh = Date_Holidays::factory($this->calendar, $year, $this->_params['language']);
104:         if (Date_Holidays::isError($dh)) {
105:             Horde::logMessage(sprintf('Factory was unable to produce driver object for driver %s in year %s with locale %s',
106:                                       $this->calendar, $year, $this->_params['language']), 'ERR');
107:             return false;
108:         }
109:         $dh->addTranslation($this->_params['language']);
110: 
111:         $event = $dh->getHoliday($id);
112:         if ($event instanceof PEAR_Error) {
113:             throw new Horde_Exception_NotFound($event);
114:         }
115: 
116:         return new Kronolith_Event_Holidays($this, $event);
117:     }
118: 
119:     private function _getEvents($dh, $startDate, $endDate)
120:     {
121:         $events = array();
122:         for ($date = new Horde_Date($startDate);
123:              $date->compareDate($endDate) <= 0;
124:              $date->mday++) {
125:             $holidays = $dh->getHolidayForDate($date->format('Y-m-d'), null, true);
126:             if (Date_Holidays::isError($holidays)) {
127:                 Horde::logMessage(sprintf('Unable to retrieve list of holidays from %s to %s',
128:                                           (string)$startDate, (string)$endDate), __FILE__, __LINE__);
129:                 continue;
130:             }
131: 
132:             if (is_null($holidays)) {
133:                 continue;
134:             }
135: 
136:             foreach ($holidays as $holiday) {
137:                 $event = new Kronolith_Event_Holidays($this, $holiday);
138:                 $events[] = $event;
139:             }
140:         }
141:         return $events;
142:     }
143: 
144:     private function _getTranslationFile($driver)
145:     {
146:         static $data_dir;
147:         if (!isset($data_dir)) {
148:             $pear_config = new PEAR_Config();
149:             $data_dir = $pear_config->get('data_dir');
150:         }
151:         if (empty($data_dir)) {
152:             return;
153:         }
154: 
155:         foreach (array('', '_' . $driver) as $pkg_ext) {
156:             foreach (array('ser', 'xml') as $format) {
157:                 $location = $data_dir . '/Date_Holidays' . $pkg_ext . '/lang/'
158:                     . $driver . '/' . $this->_params['language'] . '.' . $format;
159:                 if (file_exists($location)) {
160:                     return array($format, $location);
161:                 }
162:             }
163:         }
164: 
165:         return array(null, null);
166:     }
167: 
168: }
169: 
API documentation generated by ApiGen