[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /** 3 * Class representing vEvents. 4 * 5 * $Horde: framework/iCalendar/iCalendar/vevent.php,v 1.31 2004/08/18 03:16:24 chuck Exp $ 6 * 7 * Copyright 2003-2004 Mike Cochrane <mike@graftonhall.co.nz> 8 * 9 * See the enclosed file COPYING for license information (LGPL). If you 10 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 11 * 12 * @author Mike Cochrane <mike@graftonhall.co.nz> 13 * @version $Revision: 18927 $ 14 * @since Horde 3.0 15 * @package Horde_iCalendar 16 */ 17 class Horde_iCalendar_vevent extends Horde_iCalendar { 18 19 function getType() 20 { 21 return 'vEvent'; 22 } 23 24 function parsevCalendar($data) 25 { 26 parent::parsevCalendar($data, 'VEVENT'); 27 } 28 29 function exportvCalendar() 30 { 31 // Default values. 32 $requiredAttributes = array(); 33 $requiredAttributes['DTSTAMP'] = time(); 34 #$requiredAttributes['ORGANIZER'] = 'Unknown Organizer'; 35 $requiredAttributes['UID'] = $this->_exportDateTime(time()) . '@' . $_SERVER['SERVER_NAME']; 36 37 $method = !empty($this->_container) ? 38 $this->_container->getAttribute('METHOD') : 'PUBLISH'; 39 40 switch ($method) { 41 case 'PUBLISH': 42 $requiredAttributes['DTSTART'] = time(); 43 $requiredAttributes['SUMMARY'] = ''; 44 break; 45 46 case 'REQUEST': 47 $requiredAttributes['ATTENDEE'] = ''; 48 $requiredAttributes['DTSTART'] = time(); 49 $requiredAttributes['SUMMARY'] = ''; 50 break; 51 52 case 'REPLY': 53 $requiredAttributes['ATTENDEE'] = ''; 54 break; 55 56 case 'ADD': 57 $requiredAttributes['DTSTART'] = time(); 58 $requiredAttributes['SEQUENCE'] = 1; 59 $requiredAttributes['SUMMARY'] = ''; 60 break; 61 62 case 'CANCEL': 63 $requiredAttributes['ATTENDEE'] = ''; 64 $requiredAttributes['SEQUENCE'] = 1; 65 break; 66 67 case 'REFRESH': 68 $requiredAttributes['ATTENDEE'] = ''; 69 break; 70 } 71 72 foreach ($requiredAttributes as $name => $default_value) { 73 if (is_a($this->getAttribute($name), 'PEAR_Error')) { 74 $this->setAttribute($name, $default_value); 75 } 76 } 77 78 return parent::_exportvData('VEVENT'); 79 } 80 81 /** 82 * Update the status of an attendee of an event. 83 * 84 * @param $email The email address of the attendee. 85 * @param $status The participant status to set. 86 * @param $fullname The full name of the participant to set. 87 */ 88 function updateAttendee($email, $status, $fullname = '') 89 { 90 foreach ($this->_attributes as $key => $attribute) { 91 if ($attribute['name'] == 'ATTENDEE' && $attribute['value'] == 'MAILTO:' . $email) { 92 $this->_attributes[$key]['params']['PARTSTAT'] = $status; 93 if (!empty($fullname)) { 94 $this->_attributes[$key]['params']['CN'] = $fullname; 95 } 96 unset($this->_attributes[$key]['params']['RSVP']); 97 return; 98 } 99 } 100 $params = array('PARTSTAT' => $status); 101 if (!empty($fullname)) { 102 $params['CN'] = $fullname; 103 } 104 $this->setAttribute('ATTENDEE', 'MAILTO:' . $email, $params); 105 } 106 107 /** 108 * Return the organizer display name or email. 109 * 110 * @return string The organizer name to display for this event. 111 */ 112 function organizerName() 113 { 114 $organizer = $this->getAttribute('ORGANIZER', true); 115 if (is_a($organizer, 'PEAR_Error')) { 116 return null; 117 } 118 119 if (isset($organizer[0]['CN'])) { 120 return $organizer[0]['CN']; 121 } 122 123 $organizer = parse_url($this->getAttribute('ORGANIZER')); 124 125 return $organizer['path']; 126 } 127 128 /** 129 * Update this event with details from another event. 130 * 131 * @param object Horde_iCalendar_vEvent $vevent The vEvent with latest details. 132 */ 133 function updateFromvEvent($vevent) 134 { 135 $newAttributes = $vevent->getAllAttributes(); 136 foreach ($newAttributes as $newAttribute) { 137 $currentValue = $this->getAttribute($newAttribute['name']); 138 if (is_a($currentValue, 'PEAR_error')) { 139 // Already exists so just add it. 140 $this->setAttribute($newAttribute['name'], $newAttribute['value'], $newAttribute['params']); 141 } else { 142 // Already exists so locate and modify. 143 $found = false; 144 145 // Try matching the attribte name and value incase 146 // only the params changed (eg attendee updating 147 // status). 148 foreach ($this->_attributes as $id => $attr) { 149 if ($attr['name'] == $newAttribute['name'] && 150 $attr['value'] == $newAttribute['value']) { 151 // merge the params 152 foreach ($newAttribute['params'] as $param_id => $param_name) { 153 $this->_attributes[$id]['params'][$param_id] = $param_name; 154 } 155 $found = true; 156 break; 157 } 158 } 159 if (!$found) { 160 // Else match the first attribute with the same 161 // name (eg changing start time). 162 foreach ($this->_attributes as $id => $attr) { 163 if ($attr['name'] == $newAttribute['name']) { 164 $this->_attributes[$id]['value'] = $newAttribute['value']; 165 // Merge the params. 166 foreach ($newAttribute['params'] as $param_id => $param_name) { 167 $this->_attributes[$id]['params'][$param_id] = $param_name; 168 } 169 break; 170 } 171 } 172 } 173 } 174 } 175 } 176 177 /** 178 * Update just the attendess of event with details from another 179 * event. 180 * 181 * @param object Horde_iCalendar_vEvent $vevent The vEvent with latest details 182 */ 183 function updateAttendeesFromvEvent($vevent) 184 { 185 $newAttributes = $vevent->getAllAttributes(); 186 foreach ($newAttributes as $newAttribute) { 187 if (!$newAttribute['name'] == 'ATTENDEE') { 188 continue; 189 } 190 $currentValue = $this->getAttribute($newAttribute['name']); 191 if (is_a($currentValue, 'PEAR_error')) { 192 // Already exists so just add it. 193 $this->setAttribute($newAttribute['name'], $newAttribute['value'], $newAttribute['params']); 194 } else { 195 // Already exists so locate and modify. 196 $found = false; 197 // Try matching the attribte name and value incase 198 // only the params changed (eg attendee updating 199 // status). 200 foreach ($this->_attributes as $id => $attr) { 201 if ($attr['name'] == $newAttribute['name'] && 202 $attr['value'] == $newAttribute['value']) { 203 // Merge the params. 204 foreach ($newAttribute['params'] as $param_id => $param_name) { 205 $this->_attributes[$id]['params'][$param_id] = $param_name; 206 } 207 $found = true; 208 break; 209 } 210 } 211 212 if (!$found) { 213 // Else match the first attribute with the same 214 // name (eg changing start time). 215 foreach ($this->_attributes as $id => $attr) { 216 if ($attr['name'] == $newAttribute['name']) { 217 $this->_attributes[$id]['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 break; 223 } 224 } 225 } 226 } 227 } 228 } 229 230 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |