Overview

Packages

  • Icalendar

Classes

  • Horde_Icalendar
  • Horde_Icalendar_Daylight
  • Horde_Icalendar_Exception
  • Horde_Icalendar_Standard
  • Horde_Icalendar_Translation
  • Horde_Icalendar_Valarm
  • Horde_Icalendar_Vcard
  • Horde_Icalendar_Vevent
  • Horde_Icalendar_Vfreebusy
  • Horde_Icalendar_Vjournal
  • Horde_Icalendar_Vnote
  • Horde_Icalendar_Vtimezone
  • Horde_Icalendar_Vtodo
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Class representing vEvents.
  4:  *
  5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (LGPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  9:  *
 10:  * @author   Mike Cochrane <mike@graftonhall.co.nz>
 11:  * @category Horde
 12:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 13:  * @package  Icalendar
 14:  */
 15: class Horde_Icalendar_Vevent extends Horde_Icalendar
 16: {
 17:     /**
 18:      * The component type of this class.
 19:      *
 20:      * @var string
 21:      */
 22:     public $type = 'vEvent';
 23: 
 24:     /**
 25:      * TODO
 26:      *
 27:      * @return TODO
 28:      */
 29:     public function exportvCalendar()
 30:     {
 31:         // Default values.
 32:         $requiredAttributes = array(
 33:             'DTSTAMP' => time(),
 34:             'UID' => strval(new Horde_Support_Uuid())
 35:         );
 36: 
 37:         $method = !empty($this->_container)
 38:             ? $this->_container->getAttribute('METHOD')
 39:             : 'PUBLISH';
 40: 
 41:         switch ($method) {
 42:         case 'PUBLISH':
 43:             $requiredAttributes['DTSTART'] = time();
 44:             $requiredAttributes['SUMMARY'] = '';
 45:             break;
 46: 
 47:         case 'REQUEST':
 48:             $requiredAttributes['ATTENDEE'] = '';
 49:             $requiredAttributes['DTSTART'] = time();
 50:             $requiredAttributes['SUMMARY'] = '';
 51:             break;
 52: 
 53:         case 'REPLY':
 54:             $requiredAttributes['ATTENDEE'] = '';
 55:             break;
 56: 
 57:         case 'ADD':
 58:             $requiredAttributes['DTSTART'] = time();
 59:             $requiredAttributes['SEQUENCE'] = 1;
 60:             $requiredAttributes['SUMMARY'] = '';
 61:             break;
 62: 
 63:         case 'CANCEL':
 64:             $requiredAttributes['ATTENDEE'] = '';
 65:             $requiredAttributes['SEQUENCE'] = 1;
 66:             break;
 67: 
 68:         case 'REFRESH':
 69:             $requiredAttributes['ATTENDEE'] = '';
 70:             break;
 71:         }
 72: 
 73:         foreach ($requiredAttributes as $name => $default_value) {
 74:             try {
 75:                 $this->getAttribute($name);
 76:             } catch (Horde_Icalendar_Exception $e) {
 77:                 $this->setAttribute($name, $default_value);
 78:             }
 79:         }
 80: 
 81:         return $this->_exportvData('VEVENT');
 82:     }
 83: 
 84:     /**
 85:      * Update the status of an attendee of an event.
 86:      *
 87:      * @param $email    The email address of the attendee.
 88:      * @param $status   The participant status to set.
 89:      * @param $fullname The full name of the participant to set.
 90:      */
 91:     public function updateAttendee($email, $status, $fullname = '')
 92:     {
 93:         foreach ($this->_attributes as $key => $attribute) {
 94:             if ($attribute['name'] == 'ATTENDEE' &&
 95:                 $attribute['value'] == 'mailto:' . $email) {
 96:                 $this->_attributes[$key]['params']['PARTSTAT'] = $status;
 97:                 if (!empty($fullname)) {
 98:                     $this->_attributes[$key]['params']['CN'] = $fullname;
 99:                 }
100:                 unset($this->_attributes[$key]['params']['RSVP']);
101:                 return;
102:             }
103:         }
104:         $params = array('PARTSTAT' => $status);
105:         if (!empty($fullname)) {
106:             $params['CN'] = $fullname;
107:         }
108:         $this->setAttribute('ATTENDEE', 'mailto:' . $email, $params);
109:     }
110: 
111:     /**
112:      * Return the organizer display name or email.
113:      *
114:      * @return string  The organizer name to display for this event.
115:      */
116:     public function organizerName()
117:     {
118:         try {
119:             $organizer = $this->getAttribute('ORGANIZER', true);
120:         } catch (Horde_Icalendar_Exception $e) {
121:             return Horde_Icalendar_Translation::t("An unknown person");
122:         }
123: 
124:         if (isset($organizer[0]['CN'])) {
125:             return $organizer[0]['CN'];
126:         }
127: 
128:         $organizer = parse_url($this->getAttribute('ORGANIZER'));
129: 
130:         return $organizer['path'];
131:     }
132: 
133:     /**
134:      * Update this event with details from another event.
135:      *
136:      * @param Horde_Icalendar_Vevent $vevent  The vEvent with latest details.
137:      */
138:     public function updateFromvEvent($vevent)
139:     {
140:         $newAttributes = $vevent->getAllAttributes();
141:         foreach ($newAttributes as $newAttribute) {
142:             try {
143:                 $currentValue = $this->getAttribute($newAttribute['name']);
144:             } catch (Horde_Icalendar_Exception $e) {
145:                 // Already exists so just add it.
146:                 $this->setAttribute($newAttribute['name'],
147:                                     $newAttribute['value'],
148:                                     $newAttribute['params']);
149:                 continue;
150:             }
151: 
152:             // Already exists so locate and modify.
153:             $found = false;
154: 
155:             // Try matching the attribte name and value incase
156:             // only the params changed (eg attendee updating
157:             // status).
158:             foreach ($this->_attributes as $id => $attr) {
159:                 if ($attr['name'] == $newAttribute['name'] &&
160:                     $attr['value'] == $newAttribute['value']) {
161:                     // merge the params
162:                     foreach ($newAttribute['params'] as $param_id => $param_name) {
163:                         $this->_attributes[$id]['params'][$param_id] = $param_name;
164:                     }
165:                     $found = true;
166:                     break;
167:                 }
168:             }
169:             if (!$found) {
170:                 // Else match the first attribute with the same
171:                 // name (eg changing start time).
172:                 foreach ($this->_attributes as $id => $attr) {
173:                     if ($attr['name'] == $newAttribute['name']) {
174:                         $this->_attributes[$id]['value'] = $newAttribute['value'];
175:                         // Merge the params.
176:                         foreach ($newAttribute['params'] as $param_id => $param_name) {
177:                             $this->_attributes[$id]['params'][$param_id] = $param_name;
178:                         }
179:                         break;
180:                     }
181:                 }
182:             }
183:         }
184:     }
185: 
186:     /**
187:      * Update just the attendess of event with details from another
188:      * event.
189:      *
190:      * @param Horde_Icalendar_Vevent $vevent  The vEvent with latest details
191:      */
192:     public function updateAttendeesFromvEvent($vevent)
193:     {
194:         $newAttributes = $vevent->getAllAttributes();
195:         foreach ($newAttributes as $newAttribute) {
196:             if ($newAttribute['name'] != 'ATTENDEE') {
197:                 continue;
198:             }
199: 
200:             try {
201:                 $currentValue = $this->getAttribute($newAttribute['name']);
202:             } catch (Horde_Icalendar_Exception $e) {
203:                 // Already exists so just add it.
204:                 $this->setAttribute($newAttribute['name'],
205:                                     $newAttribute['value'],
206:                                     $newAttribute['params']);
207:                 continue;
208:             }
209: 
210:             // Already exists so locate and modify.
211:             $found = false;
212:             // Try matching the attribte name and value incase
213:             // only the params changed (eg attendee updating
214:             // status).
215:             foreach ($this->_attributes as $id => $attr) {
216:                 if ($attr['name'] == $newAttribute['name'] &&
217:                     $attr['value'] == $newAttribute['value']) {
218:                     // Merge the params.
219:                     foreach ($newAttribute['params'] as $param_id => $param_name) {
220:                         $this->_attributes[$id]['params'][$param_id] = $param_name;
221:                     }
222:                     $found = true;
223:                     break;
224:                 }
225:             }
226: 
227:             if (!$found) {
228:                 // Else match the first attribute with the same
229:                 // name (eg changing start time).
230:                 foreach ($this->_attributes as $id => $attr) {
231:                     if ($attr['name'] == $newAttribute['name']) {
232:                         $this->_attributes[$id]['value'] = $newAttribute['value'];
233:                         // Merge the params.
234:                         foreach ($newAttribute['params'] as $param_id => $param_name) {
235:                             $this->_attributes[$id]['params'][$param_id] = $param_name;
236:                         }
237:                         break;
238:                     }
239:                 }
240:             }
241:         }
242:     }
243: 
244: }
245: 
API documentation generated by ApiGen