Overview

Packages

  • Kolab
    • FreeBusy

Classes

  • Horde_Kolab_FreeBusy
  • Horde_Kolab_FreeBusy_Cache
  • Horde_Kolab_FreeBusy_Cache_Base
  • Horde_Kolab_FreeBusy_Cache_DB
  • Horde_Kolab_FreeBusy_Cache_DB_acl
  • Horde_Kolab_FreeBusy_Cache_DB_xacl
  • Horde_Kolab_FreeBusy_Cache_File
  • Horde_Kolab_FreeBusy_Cache_File_acl
  • Horde_Kolab_FreeBusy_Cache_File_pvcal
  • Horde_Kolab_FreeBusy_Cache_File_vcal
  • Horde_Kolab_FreeBusy_Cache_File_xacl
  • Horde_Kolab_FreeBusy_Controller_Base
  • Horde_Kolab_FreeBusy_Controller_MatchDict
  • Horde_Kolab_FreeBusy_Controller_NotFound
  • Horde_Kolab_FreeBusy_Controller_RequestConfiguration
  • Horde_Kolab_FreeBusy_Driver_Base
  • Horde_Kolab_FreeBusy_Driver_Freebusy_Base
  • Horde_Kolab_FreeBusy_Driver_Freebusy_Kolab
  • Horde_Kolab_FreeBusy_Exception
  • Horde_Kolab_FreeBusy_Exception_NotFound
  • Horde_Kolab_FreeBusy_Exception_Unauthorized
  • Horde_Kolab_FreeBusy_Export_Freebusy_Backend_Kolab
  • Horde_Kolab_FreeBusy_Export_Freebusy_Base
  • Horde_Kolab_FreeBusy_Export_Freebusy_Decorator_Log
  • Horde_Kolab_FreeBusy_Factory_Base
  • Horde_Kolab_FreeBusy_Freebusy_Controller_Freebusy
  • Horde_Kolab_FreeBusy_Freebusy_Factory_Base
  • Horde_Kolab_FreeBusy_Freebusy_Factory_Kolab
  • Horde_Kolab_FreeBusy_Freebusy_Helper_Owa
  • Horde_Kolab_FreeBusy_Freebusy_Helper_StatusMap_Config
  • Horde_Kolab_FreeBusy_Freebusy_Helper_StatusMap_Default
  • Horde_Kolab_FreeBusy_Freebusy_Owner_Kolab
  • Horde_Kolab_FreeBusy_Freebusy_Params_Folder
  • Horde_Kolab_FreeBusy_Freebusy_UserDb_Kolab
  • Horde_Kolab_FreeBusy_Object_Event
  • Horde_Kolab_FreeBusy_Owner_Kolab
  • Horde_Kolab_FreeBusy_Params_Freebusy_Resource_Kolab
  • Horde_Kolab_FreeBusy_Params_User
  • Horde_Kolab_FreeBusy_Provider_Local
  • Horde_Kolab_FreeBusy_Provider_Remote
  • Horde_Kolab_FreeBusy_Provider_Remote_PassThrough
  • Horde_Kolab_FreeBusy_Provider_Remote_Redirect
  • Horde_Kolab_FreeBusy_Report
  • Horde_Kolab_FreeBusy_Resource_Decorator_Log
  • Horde_Kolab_FreeBusy_Resource_Decorator_Mcache
  • Horde_Kolab_FreeBusy_Resource_Event_Decorator_Log
  • Horde_Kolab_FreeBusy_Resource_Event_Decorator_Mcache
  • Horde_Kolab_FreeBusy_Resource_Event_Kolab
  • Horde_Kolab_FreeBusy_Resource_Event_Owa
  • Horde_Kolab_FreeBusy_Resource_Kolab
  • Horde_Kolab_FreeBusy_Translation
  • Horde_Kolab_FreeBusy_User_Anonymous
  • Horde_Kolab_FreeBusy_User_Decorator_Log
  • Horde_Kolab_FreeBusy_User_Kolab
  • Horde_Kolab_FreeBusy_UserDb_Kolab
  • Horde_Kolab_FreeBusy_UserDb_User_Kolab
  • Horde_Kolab_FreeBusy_View
  • Horde_Kolab_FreeBusy_View_error
  • Horde_Kolab_FreeBusy_View_vfb

Interfaces

  • Horde_Kolab_FreeBusy_Driver_Freebusy_Interface
  • Horde_Kolab_FreeBusy_Driver_Interface
  • Horde_Kolab_FreeBusy_Export_Freebusy
  • Horde_Kolab_FreeBusy_Export_Freebusy_Backend
  • Horde_Kolab_FreeBusy_Factory
  • Horde_Kolab_FreeBusy_Freebusy_Helper_StatusMap
  • Horde_Kolab_FreeBusy_Freebusy_Owner
  • Horde_Kolab_FreeBusy_Owner
  • Horde_Kolab_FreeBusy_Params_Owner
  • Horde_Kolab_FreeBusy_Params_Resource
  • Horde_Kolab_FreeBusy_Provider
  • Horde_Kolab_FreeBusy_Resource
  • Horde_Kolab_FreeBusy_Resource_Event
  • Horde_Kolab_FreeBusy_User
  • Horde_Kolab_FreeBusy_UserDb
  • Horde_Kolab_FreeBusy_UserDb_User
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Converts the data from the free/busy resource into a free/busy iCal object,
  4:  *
  5:  * PHP version 5
  6:  *
  7:  * @category Kolab
  8:  * @package  Kolab_FreeBusy
  9:  * @author   Chuck Hagenbuch <chuck@horde.org>
 10:  * @author   Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
 11:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 12:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 13:  * @link     http://pear.horde.org/index.php?package=Kolab_FreeBusy
 14:  */
 15: 
 16: /**
 17:  * Converts the data from the free/busy resource into a free/busy iCal object,
 18:  *
 19:  * Copyright 2004-2010 Klarälvdalens Datakonsult AB
 20:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
 21:  * Copyright 2011 Kolab Systems AG
 22:  *
 23:  * See the enclosed file COPYING for license information (LGPL). If
 24:  * you did not receive this file, see
 25:  * http://www.horde.org/licenses/lgpl21.
 26:  *
 27:  * @category Kolab
 28:  * @package  Kolab_FreeBusy
 29:  * @author   Chuck Hagenbuch <chuck@horde.org>
 30:  * @author   Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
 31:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 32:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 33:  * @link     http://pear.horde.org/index.php?package=Kolab_FreeBusy
 34:  */
 35: class Horde_Kolab_FreeBusy_Export_Freebusy_Base
 36: implements Horde_Kolab_FreeBusy_Export_Freebusy
 37: {
 38:     /**
 39:      * The resource to export.
 40:      *
 41:      * @var Horde_Kolab_FreeBusy_Resource
 42:      */
 43:     private $_resource;
 44: 
 45:     /**
 46:      * The backend definition.
 47:      *
 48:      * @var Horde_Kolab_FreeBusy_Export_Freebusy_Backend
 49:      */
 50:     private $_backend;
 51: 
 52:     /**
 53:      * Additional parameters.
 54:      *
 55:      * @var array
 56:      */
 57:     private $_params;
 58: 
 59:     /**
 60:      * The event status to free/busy status mapper.
 61:      *
 62:      * @var Horde_Kolab_FreeBusy_Helper_StatusMap
 63:      */
 64:     private $_status_map;
 65: 
 66:     /**
 67:      * Constructor.
 68:      *
 69:      * @param Horde_Kolab_FreeBusy_Export_Freebusy_Backend $backend  The export backend.
 70:      * @param Horde_Kolab_FreeBusy_Resource                $resource The resource to export.
 71:      * @param array                                        $params   Additional parameters.
 72:      */
 73:     public function __construct(
 74:         Horde_Kolab_FreeBusy_Export_Freebusy_Backend $backend,
 75:         Horde_Kolab_FreeBusy_Resource $resource,
 76:         $params
 77:     ) {
 78:         if (!isset($params['future_days'])) {
 79:             $params['future_days'] = 60;
 80:         }
 81:         if (!isset($params['past_days'])) {
 82:             $params['past_days'] = 0;
 83:         }
 84:         if (!isset($params['request_time'])) {
 85:             $params['request_time'] = (string) new Horde_Date();
 86:         }
 87:         if (!isset($params['status_map'])) {
 88:             $this->_status_map = new Horde_Kolab_FreeBusy_Helper_Freebusy_StatusMap_Default();
 89:         } else {
 90:             $this->_status_map = $params['status_map'];
 91:         }
 92:         $this->_resource = $resource;
 93:         $this->_backend  = $backend;
 94:         $this->_params   = $params;
 95:     }
 96: 
 97:     /**
 98:      * Return today as Horde_Date.
 99:      *
100:      * @return Horde_Date Today.
101:      */
102:     private function _today()
103:     {
104:         return new Horde_Date(
105:             array(
106:                 'year' => date('Y'),
107:                 'month' => date('n'),
108:                 'mday' => date('j')
109:             )
110:         );
111:     }
112: 
113:     /**
114:      * Get the start timestamp for the export.
115:      *
116:      * @return Horde_Date The start timestamp for the export.
117:      */
118:     public function getStart()
119:     {
120:         try {
121:             $past = $this->_resource->getOwner()->getFreeBusyPast();
122:         } catch (Horde_Kolab_FreeBusy_Exception $e) {
123:             $past = $this->_params['past_days'];
124:         }
125:         $start = $this->_today();
126:         $start->mday = $start->mday - $past;
127:         return $start;
128:     }
129: 
130:     /**
131:      * Get the end timestamp for the export.
132:      *
133:      * @return Horde_Date The end timestamp for the export.
134:      */
135:     public function getEnd()
136:     {
137:         try {
138:             $future = $this->_resource->getOwner()->getFreeBusyFuture();
139:         } catch (Horde_Kolab_FreeBusy_Exception $e) {
140:             $future = $this->_params['future_days'];
141:         }
142:         $end = $this->_today();
143:         $end->mday = $end->mday + $future;
144:         return $end;
145:     }
146: 
147:     /**
148:      * Get the name of the resource.
149:      *
150:      * @return string The name of the resource.
151:      */
152:     public function getResourceName()
153:     {
154:         return $this->_resource->getName();
155:     }
156: 
157:     /**
158:      * Return the organizer mail for the export.
159:      *
160:      * @return string The organizer mail.
161:      */
162:     public function getOrganizerMail()
163:     {
164:         return 'MAILTO:' . $this->_resource->getOwner()->getMail();
165:     }
166: 
167:     /**
168:      * Return the organizer name for the export.
169:      *
170:      * @return string The organizer name.
171:      */
172:     public function getOrganizerName()
173:     {
174:         $params = array();
175:         $name = $this->_resource->getOwner()->getName();
176:         if (!empty($name)) {
177:             $params['cn'] = $name;
178:         }
179:         return $params;
180:     }
181: 
182:     /**
183:      * Return the timestamp for the export.
184:      *
185:      * @return string The timestamp.
186:      */
187:     public function getDateStamp()
188:     {
189:         if (isset($this->_params['request_time'])) {
190:             return $this->_params['request_time'];
191:         } else {
192:             return (string) new Horde_Date();
193:         }
194:     }
195: 
196:     /**
197:      * Generates the free/busy export.
198:      *
199:      * @return Horde_iCalendar  The iCal object.
200:      */
201:     public function export()
202:     {
203:         /* Create the new iCalendar. */
204:         $vCal = new Horde_iCalendar();
205:         $vCal->setAttribute('PRODID', $this->_backend->getProductId());
206:         $vCal->setAttribute('METHOD', 'PUBLISH');
207: 
208:         /* Create the new vFreebusy component. */
209:         $vFb = &Horde_iCalendar::newComponent('vfreebusy', $vCal);
210: 
211:         $vFb->setAttribute(
212:             'ORGANIZER', $this->getOrganizerMail(), $this->getOrganizerName()
213:         );
214:         $vFb->setAttribute('DTSTAMP', $this->getDateStamp());
215:         $vFb->setAttribute('DTSTART', $this->getStart()->timestamp());
216:         $vFb->setAttribute('DTEND', $this->getEnd()->timestamp());
217:         $url = $this->_backend->getUrl();
218:         if (!empty($url)) {
219:             $vFb->setAttribute('URL', $this->getUrl());
220:         }
221: 
222:         /* Add all the busy periods. */
223:         foreach (
224:             $this->_resource->listEvents($this->getStart(), $this->getEnd())
225:             as $event
226:         ) {
227:             $status = $this->_status_map->map($event->getStatus());
228:             $duration = $event->duration();
229:             $extra = $event->getEncodedInformation();
230:             foreach (
231:                 $event->getBusyTimes($this->getStart(), $this->getEnd())
232:                 as $busy
233:             ) {
234:                 $vFb->addBusyPeriod($status, $busy, null, $duration, $extra);
235:             }
236:         }
237: 
238:         /* Remove the overlaps. */
239:         $vFb->simplify();
240: 
241:         /* Combine and return. */
242:         $vCal->addComponent($vFb);
243:         return $vCal;
244:     }
245: }
246: 
API documentation generated by ApiGen