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:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
  4:  *
  5:  * See the enclosed file COPYING for license information (GPL). If you
  6:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  7:  *
  8:  * @author  Jan Schneider <jan@horde.org>
  9:  * @package Kronolith
 10:  */
 11: class Kronolith_Event_Horde extends Kronolith_Event
 12: {
 13:     /**
 14:      * The type of the calender this event exists on.
 15:      *
 16:      * @var string
 17:      */
 18:     public $calendarType = 'external';
 19: 
 20:     /**
 21:      * The API (application) of this event.
 22:      *
 23:      * @var string
 24:      */
 25:     protected $_api;
 26: 
 27:     /**
 28:      * The link to this event.
 29:      *
 30:      * @var string
 31:      */
 32:     protected $_link;
 33: 
 34:     /**
 35:      * The link to edit this event.
 36:      *
 37:      * @var string
 38:      */
 39:     protected $_editLink;
 40: 
 41:     /**
 42:      * The link to delete this event.
 43:      *
 44:      * @var string
 45:      */
 46:     protected $_deleteLink;
 47: 
 48:     /**
 49:      * The link to this event in the ajax interface.
 50:      *
 51:      * @var string
 52:      */
 53:     protected $_ajaxLink;
 54: 
 55:     /**
 56:      * Any parameters to identify the object in the other Horde application.
 57:      *
 58:      * @var array
 59:      */
 60:     protected $_params;
 61: 
 62:     /**
 63:      * The event's owner.
 64:      *
 65:      * @var string
 66:      */
 67:     protected $_owner;
 68: 
 69:     /**
 70:      * A bitmask of permissions the current user has on this object.
 71:      *
 72:      * @var integer
 73:      */
 74:     protected $_permissions;
 75: 
 76:     /**
 77:      * Whether this event has a variable length.
 78:      *
 79:      * @boolean
 80:      */
 81:     protected $_variableLength;
 82: 
 83:     /**
 84:      * Constructor.
 85:      *
 86:      * @param Kronolith_Driver $driver  The backend driver that this event is
 87:      *                                  stored in.
 88:      * @param mixed $eventObject        Backend specific event object
 89:      *                                  that this will represent.
 90:      */
 91:     public function __construct($driver, $eventObject = null)
 92:     {
 93:         $this->_api = $driver->api;
 94:         parent::__construct($driver, $eventObject);
 95:     }
 96: 
 97:     /**
 98:      * Imports a backend specific event object.
 99:      *
100:      * @param array $event  Backend specific event object that this object
101:      *                      will represent.
102:      */
103:     public function fromDriver($event)
104:     {
105:         $eventStart = new Horde_Date($event['start']);
106:         $eventEnd = new Horde_Date($event['end']);
107:         $this->id = '_' . $this->_api . $event['id'];
108:         $this->icon = !empty($event['icon']) ? $event['icon'] : null;
109:         $this->title = $event['title'];
110:         $this->description = isset($event['description']) ? $event['description'] : '';
111:         if (isset($event['location'])) {
112:             $this->location = $event['location'];
113:         }
114:         $this->start = $eventStart;
115:         $this->end = $eventEnd;
116:         if (isset($event['status'])) {
117:             switch ($event['status']) {
118:             case 'confirmed':
119:                 $this->status = Kronolith::STATUS_CONFIRMED;
120:                 break;
121:             case 'tentative':
122:                 $this->status = Kronolith::STATUS_TENTATIVE;
123:                 break;
124:             default:
125:                 $this->status = Kronolith::STATUS_FREE;
126:             }
127:         } else {
128:             $this->status = Kronolith::STATUS_FREE;
129:         }
130:         if (isset($event['private'])) {
131:             $this->private = $event['private'];
132:         }
133:         $this->_params = $event['params'];
134:         $this->_link = !empty($event['link']) ? $event['link'] : null;
135:         $this->url = !empty($event['url']) ? (string)$event['url'] : null;
136:         $this->_editLink = !empty($event['edit_link']) ? $event['edit_link'] : null;
137:         $this->_deleteLink = !empty($event['delete_link']) ? $event['delete_link'] : null;
138:         $this->_ajaxLink = !empty($event['ajax_link']) ? $event['ajax_link'] : null;
139:         $this->_backgroundColor = Kronolith::backgroundColor($event);
140:         $this->_foregroundColor = Kronolith::foregroundColor($event);
141: 
142:         if (isset($event['recurrence'])) {
143:             $recurrence = new Horde_Date_Recurrence($eventStart);
144: 
145:             $recurrence->setRecurType($event['recurrence']['type']);
146:             if (isset($event['recurrence']['end'])) {
147:                 $recurrence->setRecurEnd(new Horde_Date($event['recurrence']['end']));
148:             }
149:             if (isset($event['recurrence']['interval'])) {
150:                 $recurrence->setRecurInterval($event['recurrence']['interval']);
151:             }
152:             if (isset($event['recurrence']['count'])) {
153:                 $recurrence->setRecurCount($event['recurrence']['count']);
154:             }
155:             if (isset($event['recurrence']['days'])) {
156:                 $recurrence->setRecurOnDay($event['recurrence']['days']);
157:             }
158:             if (isset($event['recurrence']['exceptions'])) {
159:                 foreach ($event['recurrence']['exceptions'] as $exception) {
160:                     $recurrence->addException($exception);
161:                 }
162:             }
163:             $this->recurrence = $recurrence;
164:         }
165: 
166:         if (isset($event['owner'])) {
167:             $this->_owner = $event['owner'];
168:         }
169:         if (isset($event['permissions'])) {
170:             $this->_permissions = $event['permissions'];
171:         }
172:         if (isset($event['variable_length'])) {
173:             $this->_variableLength = $event['variable_length'];
174:         }
175: 
176:         $this->initialized = true;
177:         $this->stored = true;
178:     }
179: 
180:     /**
181:      * Prepares this event to be saved to the backend.
182:      */
183:     public function toTimeobject()
184:     {
185:         $timeobject = array(
186:             'id' => substr($this->id, strlen($this->_api) + 1),
187:             'icon' => $this->icon,
188:             'title' => $this->title,
189:             'description' => $this->description,
190:             'location' => $this->location,
191:             'start' => $this->start->format('Y-m-d\TH:i:s'),
192:             'end' => $this->end->format('Y-m-d\TH:i:s'),
193:             'params' => $this->_params,
194:             'link' => $this->_link,
195:             'ajax_link' => $this->_ajaxLink,
196:             'permissions' => $this->_permissions,
197:             'variable_length' => $this->_variableLength);
198: 
199:         if ($this->recurs()) {
200:             $timeobject['recurrence'] = array('type' => $this->recurrence->getRecurType());
201:             if ($end = $this->recurrence->getRecurEnd()) {
202:                 $timeobject['recurrence']['end'] = $end->format('Y-m-d\TH:i:s');
203:             }
204:             if ($interval = $this->recurrence->getRecurInterval()) {
205:                 $timeobject['recurrence']['interval'] = $interval;
206:             }
207:             if ($count = $this->recurrence->getRecurCount()) {
208:                 $timeobject['recurrence']['count'] = $count;
209:             }
210:             if ($days = $this->recurrence->getRecurOnDays()) {
211:                 $timeobject['recurrence']['days'] = $days;
212:             }
213:             if ($count = $this->recurrence->getRecurCount()) {
214:                 $timeobject['recurrence']['count'] = $count;
215:             }
216:             if ($exceptions = $this->recurrence->getExceptions()) {
217:                 $timeobject['recurrence']['exceptions'] = $exceptions;
218:             }
219:         }
220: 
221:         return $timeobject;
222:     }
223: 
224:     /**
225:      * Encapsulates permissions checking.
226:      *
227:      * @param integer $permission  The permission to check for.
228:      * @param string $user         The user to check permissions for.
229:      *
230:      * @return boolean
231:      */
232:     public function hasPermission($permission, $user = null)
233:     {
234:         if ($user === null) {
235:             $user = $GLOBALS['registry']->getAuth();
236:         }
237: 
238:         if (isset($this->_owner) && $this->_owner == $user) {
239:             return true;
240:         }
241: 
242:         if (isset($this->_permissions)) {
243:             return (bool)($this->_permissions & $permission);
244:         }
245: 
246:         switch ($permission) {
247:         case Horde_Perms::SHOW:
248:         case Horde_Perms::READ:
249:             return true;
250: 
251:         default:
252:             return false;
253:         }
254:     }
255: 
256:     /**
257:      * Returns the title of this event.
258:      *
259:      * @param string $user  The current user.
260:      *
261:      * @return string  The title of this event.
262:      */
263:     public function getTitle($user = null)
264:     {
265:         return !empty($this->title) ? $this->title : _("[Unnamed event]");
266:     }
267: 
268:     /**
269:      * @param array $params
270:      *
271:      * @return Horde_Url
272:      */
273:     public function getViewUrl($params = array(), $full = false, $encoded = true)
274:     {
275:         if (empty($this->_link)) {
276:             return null;
277:         }
278:         $url = clone $this->_link;
279:         return $url->setRaw(!$encoded);
280:     }
281: 
282:     /**
283:      * @param array $params
284:      *
285:      * @return Horde_Url
286:      */
287:     public function getEditUrl($params = array(), $full = false)
288:     {
289:         if (empty($this->_editLink)) {
290:             return null;
291:         }
292:         $url = clone $this->_editLink;
293:         if (isset($params['url'])) {
294:             $url->add('url', $params['url']);
295:         }
296:         return $url->setRaw($full);
297:     }
298: 
299:     /**
300:      * @param array $params
301:      *
302:      * @return Horde_Url
303:      */
304:     public function getDeleteUrl($params = array(), $full = false)
305:     {
306:         if (empty($this->_deleteLink)) {
307:             return null;
308:         }
309:         $url = clone $this->_deleteLink;
310:         if (isset($params['url'])) {
311:             $url->add('url', $params['url']);
312:         }
313:         return $url->setRaw($full);
314:     }
315: 
316:     /**
317:      * Returns a simple object suitable for json transport representing this
318:      * event.
319:      *
320:      * @param boolean $allDay      If not null, overrides whether the event is
321:      *                             an all-day event.
322:      * @param boolean $full        Whether to return all event details.
323:      * @param string $time_format  The date() format to use for time formatting.
324:      *
325:      * @return object  A simple object.
326:      */
327:     public function toJson($allDay = null, $full = false, $time_format = 'H:i')
328:     {
329:         $json = parent::toJson($allDay, $full, $time_format);
330:         if ($this->_ajaxLink) {
331:             $json->aj = $this->_ajaxLink;
332:         } elseif ($link = (string)$this->getViewUrl(array(), true, false)) {
333:             $json->ln = $link;
334:         }
335:         if (isset($this->_variableLength)) {
336:             $json->vl = $this->_variableLength;
337:         }
338:         return $json;
339:     }
340: 
341:     /**
342:      * @return string  A tooltip for quick descriptions of this event.
343:      */
344:     public function getTooltip()
345:     {
346:         return Horde_String::wrap($this->description);
347:     }
348: 
349: }
350: 
API documentation generated by ApiGen