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:  * Kronolith_Resource implementation to represent a single resource.
  4:  *
  5:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
 11:  * @package Kronolith
 12:  */
 13: class Kronolith_Resource_Single extends Kronolith_Resource_Base
 14: {
 15:     /**
 16:      * Determine if the resource is free during the time period for the
 17:      * supplied event.
 18:      *
 19:      * @param mixed $event  Either a Kronolith_Event object or an array
 20:      *                      containing start and end times.
 21:      *
 22:      *
 23:      * @return boolean
 24:      * @throws Kronolith_Exception
 25:      */
 26:     public function isFree($event)
 27:     {
 28:         if (is_array($event)) {
 29:             $start = $event['start'];
 30:             $end = $event['end'];
 31:         } else {
 32:             $start = $event->start;
 33:             $end = $event->end;
 34:         }
 35: 
 36:         /* Fetch Events */
 37:         $busy = Kronolith::getDriver('Resource', $this->get('calendar'))
 38:             ->listEvents($start, $end, true);
 39: 
 40:         /* No events at all during time period for requested event */
 41:         if (!count($busy)) {
 42:             return true;
 43:         }
 44: 
 45:         /* Check for conflicts, ignoring the conflict if it's for the
 46:          * same event that is passed. */
 47:         if (!is_array($event)) {
 48:             $uid = $event->uid;
 49:         } else {
 50:             $uid = 0;
 51:         }
 52:         foreach ($busy as $events) {
 53:             foreach ($events as $e) {
 54:                 if (!($e->status == Kronolith::STATUS_CANCELLED ||
 55:                       $e->status == Kronolith::STATUS_FREE) &&
 56:                      $e->uid !== $uid) {
 57: 
 58:                      // Comparing to zero allows the events to start at the same
 59:                      // the previous event ends.
 60:                      if (!($e->start->compareDateTime($end) >= 0) &&
 61:                          !($e->end->compareDateTime($start) <= 0)) {
 62: 
 63:                         return false;
 64:                      }
 65:                 }
 66:             }
 67:         }
 68: 
 69:         return true;
 70:     }
 71: 
 72:     /**
 73:      * Adds $event to this resource's calendar or updates the current entry
 74:      * of the event in the calendar.
 75:      *
 76:      * @param $event
 77:      *
 78:      * @throws Kronolith_Exception
 79:      */
 80:     public function addEvent($event)
 81:     {
 82:         /* Get a driver for this resource's calendar */
 83:         $driver = $this->getDriver();
 84: 
 85:         /* Make sure it's not already attached. */
 86:         $uid = $event->uid;
 87:         try {
 88:             $existing = $driver->getByUID($uid, array($this->get('calendar')));
 89:             /* Already attached, just update */
 90:             $this->_copyEvent($event, $existing);
 91:             $result = $existing->save();
 92:         } catch (Horde_Exception_NotFound $ex) {
 93:             /* Create a new event */
 94:             $e = $driver->getEvent();
 95:             $this->_copyEvent($event, $e);
 96:             $result = $e->save();
 97:         }
 98:     }
 99: 
100:     /**
101:      * Remove this event from resource's calendar
102:      *
103:      * @param $event
104:      *
105:      * @throws Kronolith_Exception
106:      * @throws Horde_Exception_NotFound
107:      */
108:     public function removeEvent($event)
109:     {
110:         $driver = Kronolith::getDriver('Resource', $this->get('calendar'));
111:         $re = $driver->getByUID($event->uid, array($this->get('calendar')));
112:         $driver->deleteEvent($re->id);
113:     }
114: 
115:     /**
116:      * Obtain the freebusy information for this resource.
117:      *
118:      * @return unknown_type
119:      */
120:     public function getFreeBusy($startstamp = null, $endstamp = null, $asObject = false)
121:     {
122:         $vfb = Kronolith_Freebusy::generate($this->get('calendar'), $startstamp, $endstamp, $asObject);
123:         $vfb->removeAttribute('ORGANIZER');
124:         $vfb->setAttribute('ORGANIZER', $this->get('name'));
125: 
126:         return $vfb;
127:     }
128: 
129:     public function setId($id)
130:     {
131:         if (empty($this->_id)) {
132:             $this->_id = $id;
133:         } else {
134:             throw new Horde_Exception('Resource already exists. Cannot change the id.');
135:         }
136:     }
137: 
138:     public function getResponseType()
139:     {
140:         return $this->get('response_type');
141:     }
142: 
143:     /**
144:      * Utility function to copy select event properties from $from to $to in
145:      * order to add an event to the resource calendar.
146:      *
147:      * @param Kronolith_Event $from
148:      * @param Kronolith_Event $to
149:      *
150:      * @return void
151:      */
152:     private function _copyEvent($from, &$to)
153:     {
154:         $to->uid = $from->uid;
155:         $to->title = $from->title;
156:         $to->location = $from->location;
157:         $to->status = $from->status;
158:         $to->description = $from->description;
159:         $to->url = $from->url;
160:         $to->tags = $from->tags;
161:         $to->geoLocation = $from->geoLocation;
162:         $to->first = $from ->first;
163:         $to->last = $from->last;
164:         $to->start = $from->start;
165:         $to->end = $from->end;
166:         $to->durMin = $from->durMin;
167:         $to->allday = $from->allday;
168:         $to->recurrence = $from->recurrence;
169:         $to->initialized = true;
170:     }
171: 
172: }
API documentation generated by ApiGen