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:  * Base class for Kronolith resources. Partially presents a Horde_Share_Object
  4:  * interface.
  5:  *
  6:  * Copyright 2009-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:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
 12:  * @package Kronolith
 13:  */
 14: abstract class Kronolith_Resource_Base
 15: {
 16:     /**
 17:      * Instance copy of parameters
 18:      *
 19:      *   name        - Display name of resource.
 20:      *   calendar    - The calendar associated with this resource.
 21:      *   description -
 22:      *   email       -
 23:      *   response_type - a RESPONSETYPE_* constant
 24:      *
 25:      * @var array
 26:      */
 27:     protected $_params = array();
 28: 
 29:     /**
 30:      * Resource's internal id
 31:      *
 32:      * @var integer
 33:      */
 34:     protected $_id = '';
 35: 
 36:     /**
 37:      * Const'r
 38:      *
 39:      * @param array $params
 40:      *
 41:      * @return Kronolith_Resource object
 42:      */
 43:     public function __construct($params = array())
 44:     {
 45:         if (!empty($params['id'])) {
 46:             // Existing resource
 47:             $this->_id = $params['id'];
 48:         }
 49: 
 50:         // Names are required.
 51:         if (empty($params['name'])) {
 52:             throw new Horde_Exception('Required \'name\' attribute missing from resource calendar');
 53:         }
 54:         $this->_params = array_merge(
 55:             array('description' => '',
 56:                   'response_type' => Kronolith_Resource::RESPONSETYPE_MANUAL,
 57:                   'members' => '',
 58:                   'calendar' => '',
 59:                   'email' => ''
 60:             ),
 61:             $params
 62:         );
 63:     }
 64: 
 65:     /**
 66:      * Obtain the resource's internal identifier.
 67:      *
 68:      * @return mixed The id.
 69:      */
 70:     public function getId()
 71:     {
 72:         return $this->_id;
 73:     }
 74: 
 75:     /**
 76:      * Allow setting of properties
 77:      *
 78:      * @param string $property  The property to set
 79:      * @param mixed $value      The value to set to
 80:      *
 81:      * @return void
 82:      */
 83:     public function set($property, $value)
 84:     {
 85:         $this->_params[$property] = $value;
 86:     }
 87: 
 88:     /**
 89:      * @TODO: need to fine tune this
 90:      *
 91:      * @param $user
 92:      * @param $permission
 93:      * @param $restrict
 94:      * @return unknown_type
 95:      */
 96:     public function hasPermission($user, $permission = Horde_Perms::READ, $restrict = null)
 97:     {
 98:         if (($permission & (Horde_Perms::EDIT | Horde_Perms::DELETE)) &&
 99:             !$GLOBALS['registry']->isAdmin()) {
100:             return false;
101:         }
102: 
103:         return true;
104:     }
105: 
106:     /**
107:      * Implemented to stand in as a share object.
108:      *
109:      * @param $property
110:      * @return unknown_type
111:      */
112:     public function get($property)
113:     {
114:         $property = str_replace('resource_', '', $property);
115:         if ($property == 'type' && empty($this->_params['type'])) {
116:             return ($this instanceof Kronolith_Resource_Single) ? 'Single' : 'Group';
117:         }
118:         if (!array_key_exists($property, $this->_params)) {
119:             throw new Horde_Exception(sprintf('The property \'%s\' does not exist', $property));
120:         }
121:         return $this->_params[$property];
122:     }
123: 
124:     /**
125:      * Save resource to storage.
126:      *
127:      * @return Kronolith_Resource object
128:      * @throws Kronolith_Exception
129:      */
130:     public function save()
131:     {
132:         return $this->getDriver()->save($this);
133:     }
134: 
135:     /**
136:      * Get a storage driver instance for the resource. For now, just instantiate
137:      * it here, in future, probably inject it in the const'r.
138:      *
139:      * @return Kronolith_Driver_Resource
140:      */
141:     public function getDriver()
142:     {
143:         if (!$this->get('calendar')) {
144:             return Kronolith::getDriver('Resource');
145:         } else {
146:             return Kronolith::getDriver('Resource', $this->get('calendar'));
147:         }
148:     }
149: 
150:     /**
151:      * Check availability and return an appropriate Kronolith response code.
152:      *
153:      * @param Kronolith_Event $event  The event to check on
154:      *
155:      * @return integer Kronolith::RESPONSE* constant
156:      */
157:     public function getResponse($event)
158:     {
159:         switch($this->getResponseType()) {
160:         case Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT:
161:             return Kronolith::RESPONSE_ACCEPTED;
162:         case Kronolith_Resource::RESPONSETYPE_AUTO:
163:             if ($this->isFree($event)) {
164:                 return Kronolith::RESPONSE_ACCEPTED;
165:             } else {
166:                 return Kronolith::RESPONSE_DECLINED;
167:             }
168:         case Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE:
169:             return Kronolith::RESPONSE_DECLINED;
170:         case Kronolith_Resource::RESPONSETYPE_NONE:
171:         case Kronolith_Resource::RESPONSETYPE_MANUAL:
172:             return Kronolith::RESPONSE_NONE;
173:         }
174:     }
175: 
176:     /**
177:      * Determine if event is free for specified time
178:      *
179:      * @param $startTime
180:      * @param $endTime
181:      * @return unknown_type
182:      */
183:     abstract public function isFree($event);
184: 
185:     /**
186:      * Adds $event to this resource's calendar - thus blocking the time
187:      * for any other event.
188:      *
189:      * @param $event
190:      * @return unknown_type
191:      */
192:     abstract public function addEvent($event);
193: 
194:     /**
195:      * Remove this event from resource's calendar
196:      *
197:      * @param $event
198:      * @return unknown_type
199:      */
200:     abstract public function removeEvent($event);
201: 
202:     /**
203:      * Obtain the freebusy information for this resource.  Takes into account
204:      * if this is a group of resources or not. (Returns the cumulative FB info
205:      * for all the resources in the group.
206:      * @return unknown_type
207:      */
208:     abstract public function getFreeBusy();
209: 
210:     /**
211:      * Sets the current resource's id. Must not be an existing resource.
212:      *
213:      * @param int $id  The id for this resource
214:      *
215:      * @return unknown_type
216:      */
217:     abstract public function setId($id);
218: 
219:     /**
220:      * Get ResponseType for this resource.
221:      * @return unknown_type
222:      */
223:     abstract public function getResponseType();
224: 
225: }
226: 
API documentation generated by ApiGen