Changeset 5344 for trunk/prototype/services
- Timestamp:
- 01/10/12 14:03:05 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/services/iCal.php
r5341 r5344 142 142 break; 143 143 144 default: 144 default: 145 $veventID = mt_rand().'1(Formatter)'; 146 145 147 if($exists !== false) 146 148 { … … 155 157 $calendarToSchedulable['schedulable'] = $exists['id']; 156 158 $interation['calendarToSchedulable://'.mt_rand().'(Formatter)'] = $calendarToSchedulable; 159 continue; 157 160 } 158 161 // Codigo para atualizar status do importador. não nescessario pois sera enviado um email de configmação para o organizador. … … 160 163 // if($participant['user']['id'] == Config::me('uidNumber')) 161 164 // $interation['participant://'.$participant['id']] = array( 'id' => $participant['id'], 'status' => STATUS_CONFIRMED); 162 165 166 $veventID = $exists['id']; 167 $vevent = $exists; 163 168 } 164 else 165 { 166 /* Gera um randon id para o contexto formater */ 167 $veventID = mt_rand().'1(Formatter)'; 168 169 /* Data de Inicio*/ 170 $startTime = $component->getProperty( 'dtstart', false , true ); 171 172 /* Tiem zone do evento*/ 173 if(isset($startTime['params']['TZID'])) 174 $vevent['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); 175 else 176 $vevent['timezone'] = $params['calendar_timezone'] ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 177 178 if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) 179 { 180 $vevent['allDay'] = 1; 181 $vevent['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$params['calendar_timezone']) . '000'; 182 } 183 elseif(isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 184 $vevent['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000'; 185 else 186 $vevent['startTime'] = self::date2timestamp($startTime['value']) . '000'; 187 188 /* Data de Termino*/ 189 $endTime = $component->getProperty( 'dtend', false , true ); 190 191 if($endTime['params']['VALUE'] === 'DATE') 192 $vevent['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$params['calendar_timezone']) . '000'; 193 else if(isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 194 $vevent['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; 195 else 196 $vevent['endTime'] = self::date2timestamp($endTime['value']) . '000'; 197 198 $vevent['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1'); 199 200 /* Definindo Description */ 201 if($desc = $component->getProperty( 'description' , false , false )) 202 $vevent['description'] = mb_convert_encoding (str_ireplace ('\n', "\n", $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1'); 203 204 /* Definindo location */ 205 if($location = $component->getProperty( 'location' , false , false )) 206 $vevent['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ; 207 208 209 /* Definindo Class */ 210 $class = $component->getProperty( 'class' , false , false ); 211 if( $class && defined(constant(strtoupper('CLASS_'.$class))) ) 212 $vevent['class'] = constant(strtoupper('CLASS_'.$class)); 213 else if( !isset($exists['class']) ) 214 $vevent['class'] = CLASS_PRIVATE ; // padrão classe private 215 216 /* Definindo RRULE */ 217 if( $rrule = $component->getProperty( 'rrule' , false , false )) 218 { 219 /* Gera um randon id para o contexto formater */ 220 $repeatID = mt_rand().'3(Formatter)'; 221 222 $repeat = array(); 223 $repeat['schedulable'] = $veventID; 224 foreach($rrule as $i => $v) 225 $repeat[strtolower($i)] = $v; 226 227 $interation['repeat://'.$repeatID] = $repeat; 228 } 229 230 231 $vevent['calendar'] = $params['calendar']; 232 233 $participantsInEvent = array(); 234 235 //TODO: Participants com delegated não estao sendo levados em conta 236 while($property = $component->getProperty('attendee',FALSE , TRUE)) 169 170 /* Data de Inicio*/ 171 $startTime = $component->getProperty( 'dtstart', false , true ); 172 173 /* Tiem zone do evento*/ 174 if(isset($startTime['params']['TZID'])) 175 $vevent['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); 176 else 177 $vevent['timezone'] = $params['calendar_timezone'] ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 178 179 if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) 237 180 { 238 $participant = array(); 239 240 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 241 181 $vevent['allDay'] = 1; 182 $vevent['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$params['calendar_timezone']) . '000'; 183 } 184 elseif(isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 185 $vevent['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000'; 186 else 187 $vevent['startTime'] = self::date2timestamp($startTime['value']) . '000'; 188 189 /* Data de Termino*/ 190 $endTime = $component->getProperty( 'dtend', false , true ); 191 192 if($endTime['params']['VALUE'] === 'DATE') 193 $vevent['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$params['calendar_timezone']) . '000'; 194 else if(isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 195 $vevent['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; 196 else 197 $vevent['endTime'] = self::date2timestamp($endTime['value']) . '000'; 198 199 $vevent['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1'); 200 201 /* Definindo Description */ 202 if($desc = $component->getProperty( 'description' , false , false )) 203 $vevent['description'] = mb_convert_encoding (str_ireplace ('\n', "\n", $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1'); 204 205 /* Definindo location */ 206 if($location = $component->getProperty( 'location' , false , false )) 207 $vevent['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ; 208 209 210 /* Definindo Class */ 211 $class = $component->getProperty( 'class' , false , false ); 212 if( $class && defined(constant(strtoupper('CLASS_'.$class))) ) 213 $vevent['class'] = constant(strtoupper('CLASS_'.$class)); 214 else if( !isset($exists['class']) ) 215 $vevent['class'] = CLASS_PRIVATE ; // padrão classe private 216 217 /* Definindo RRULE */ 218 if( $rrule = $component->getProperty( 'rrule' , false , false )) 219 { 220 /* Gera um randon id para o contexto formater */ 221 $repeatID = mt_rand().'3(Formatter)'; 222 223 $repeat = array(); 224 $repeat['schedulable'] = $veventID; 225 foreach($rrule as $i => $v) 226 $repeat[strtolower($i)] = $v; 227 228 $interation['repeat://'.$repeatID] = $repeat; 229 } 230 231 232 $vevent['calendar'] = $params['calendar']; 233 234 $participantsInEvent = array(); 235 236 //TODO: Participants com delegated não estao sendo levados em conta 237 while($property = $component->getProperty('attendee',FALSE , TRUE)) 238 { 239 $participant = array(); 240 241 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 242 243 $participantID = mt_rand().'2(Formatter)'; 244 $participant['schedulable'] = $veventID; 245 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 246 $participant['isOrganizer'] = '0'; 247 248 /* Verifica se este usuario é um usuario interno do ldap */ 249 $intUser = Controller::find( array( 'concept' => 'user', 'service' => 'OpenLDAP' ) , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); 250 251 if( !is_array($intUser) || count($intUser) < 1 ) 252 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' , $mailUser )) ); 253 254 255 $user = null; 256 if( $intUser && count($intUser) > 0 ) 257 { 258 $participant['isExternal'] = 0; 259 $participant['user'] = $intUser[0]['id']; 260 } 261 else 262 { 263 $participant['isExternal'] = 1; 264 /* Gera um randon id para o contexto formater */ 265 $userID = mt_rand().'4(Formatter)'; 266 267 $user['mail'] = $mailUser; 268 $user['isExternal'] = '1'; 269 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 270 $user['participants'] = array($participantID); 271 $participant['user'] = $userID; 272 $interation['user://'.$userID] = $user; 273 } 274 275 $interation['participant://'.$participantID] = $participant; 276 $vevent['participants'][] = $participantID; 277 278 }; 279 280 if($property = $component->getProperty('organizer',FALSE , TRUE)) 281 { 282 $participant = array(); 283 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 284 285 $participantID = mt_rand().'2(Formatter)'; 286 287 $participant['schedulable'] = $veventID; 288 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 289 $participant['isOrganizer'] = '1'; 290 291 /* Verifica se este usuario é um usuario interno do ldap */ 292 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'OpenLDAP') , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); 293 294 if( !is_array($intUser) || count($intUser) < 1 ) 295 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' , $mailUser )) ); 296 297 298 299 $user = null; 300 if( $intUser && count($intUser) > 0 ) 301 { 302 $participant['isExternal'] = 0; 303 $participant['user'] = $intUser[0]['id']; 304 } 305 else 306 { 307 $participant['isExternal'] = 1; 308 /* Gera um randon id para o contexto formater */ 309 $userID = mt_rand().'4(Formatter)'; 310 311 $user['mail'] = $mailUser; 312 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 313 $user['participants'] = array($participantID); 314 $user['isExternal'] = '1'; 315 $participant['user'] = $userID; 316 $interation['user://'.$userID] = $user; 317 } 318 319 $interation['participant://'.$participantID] = $participant; 320 $vevent['participants'][] = $participantID; 321 322 } 323 else //caso não tenha organizador o usuario se torna organizador 324 { 325 $user = Controller::read( array( 'concept' => 'user', 'id' => $params['owner'] ) , array('mail')); 326 327 if(!self::_getParticipantByMail($user['mail'] , $exists['participants'])) 328 { 242 329 $participantID = mt_rand().'2(Formatter)'; 243 $participant['schedulable'] = $veventID; 244 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 245 $participant['isOrganizer'] = '0'; 246 247 /* Verifica se este usuario é um usuario interno do ldap */ 248 $intUser = Controller::find( array( 'concept' => 'user', 'service' => 'OpenLDAP' ) , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); 249 250 if( !is_array($intUser) || count($intUser) < 1 ) 251 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' , $mailUser )) ); 252 253 254 $user = null; 255 if( $intUser && count($intUser) > 0 ) 256 { 257 $participant['isExternal'] = 0; 258 $participant['user'] = $intUser[0]['id']; 259 } 260 else 261 { 262 $participant['isExternal'] = 1; 263 /* Gera um randon id para o contexto formater */ 264 $userID = mt_rand().'4(Formatter)'; 265 266 $user['mail'] = $mailUser; 267 $user['isExternal'] = '1'; 268 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 269 $user['participants'] = array($participantID); 270 $participant['user'] = $userID; 271 $interation['user://'.$userID] = $user; 272 } 273 330 331 $participant['schedulable'] = $veventID; 332 $participant['status'] = STATUS_CONFIRMED; 333 $participant['isOrganizer'] = '1'; 334 $participant['isExternal'] = 0; 335 $participant['user'] = $params['owner']; 274 336 $interation['participant://'.$participantID] = $participant; 275 337 $vevent['participants'][] = $participantID; 276 277 }; 278 279 if($property = $component->getProperty('organizer',FALSE , TRUE)) 280 { 281 $participant = array(); 282 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 283 284 $participantID = mt_rand().'2(Formatter)'; 285 286 $participant['schedulable'] = $veventID; 287 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 288 $participant['isOrganizer'] = '1'; 289 290 /* Verifica se este usuario é um usuario interno do ldap */ 291 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'OpenLDAP') , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); 292 293 if( !is_array($intUser) || count($intUser) < 1 ) 294 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' , $mailUser )) ); 295 296 297 298 $user = null; 299 if( $intUser && count($intUser) > 0 ) 300 { 301 $participant['isExternal'] = 0; 302 $participant['user'] = $intUser[0]['id']; 303 } 304 else 305 { 306 $participant['isExternal'] = 1; 307 /* Gera um randon id para o contexto formater */ 308 $userID = mt_rand().'4(Formatter)'; 309 310 $user['mail'] = $mailUser; 311 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 312 $user['participants'] = array($participantID); 313 $user['isExternal'] = '1'; 314 $participant['user'] = $userID; 315 $interation['user://'.$userID] = $user; 316 } 317 318 $interation['participant://'.$participantID] = $participant; 319 $vevent['participants'][] = $participantID; 320 321 } 322 else //caso não tenha organizador o usuario se torna organizador 323 { 324 $user = Controller::read( array( 'concept' => 'user', 'id' => $params['owner'] ) , array('mail')); 325 326 if(!self::_getParticipantByMail($user['mail'] , $exists['participants'])) 327 { 328 $participantID = mt_rand().'2(Formatter)'; 329 330 $participant['schedulable'] = $veventID; 331 $participant['status'] = STATUS_CONFIRMED; 332 $participant['isOrganizer'] = '1'; 333 $participant['isExternal'] = 0; 334 $participant['user'] = $params['owner']; 335 $interation['participant://'.$participantID] = $participant; 336 $vevent['participants'][] = $participantID; 337 } 338 } 339 340 /* Definindo DTSTAMP */ 341 if($dtstamp = $component->getProperty( 'dtstamp', false , true )) 342 { 343 if(isset($dtstamp['params']['TZID']) && !isset($dtstamp['value']['tz'])) 344 $vevent['dtstamp'] = self::date2timestamp($dtstamp['value']) - self::_getTzOffset('UTC',$dtstamp['params']['TZID']) . '000'; 345 else 346 $vevent['dtstamp'] = self::date2timestamp($dtstamp['value']) . '000'; 347 } 348 349 /* Definindo TRANSP */ 350 if(($tranp = $component->getProperty( 'transp', false , true )) && strtoupper($tranp) == 'OPAQUE') 351 $vevent['transparent'] = 1; 352 353 /* Definindo last_update */ 354 if($lastUpdate = $component->getProperty( 'LAST-MODIFIED', false , true )) 355 { 356 if(isset($lastUpdate['params']['TZID']) && !isset($lastUpdate['value']['tz'])) 357 $vevent['lasUpdate'] = self::date2timestamp($lastUpdate['value']) - self::_getTzOffset('UTC',$lastUpdate['params']['TZID']) . '000'; 358 else 359 $vevent['lastUpdate'] = self::date2timestamp($lastUpdate['value']) . '000'; 360 } 361 362 $interation['schedulable://'.$veventID] = $vevent; 363 364 } 338 } 339 } 340 341 /* Definindo DTSTAMP */ 342 if($dtstamp = $component->getProperty( 'dtstamp', false , true )) 343 { 344 if(isset($dtstamp['params']['TZID']) && !isset($dtstamp['value']['tz'])) 345 $vevent['dtstamp'] = self::date2timestamp($dtstamp['value']) - self::_getTzOffset('UTC',$dtstamp['params']['TZID']) . '000'; 346 else 347 $vevent['dtstamp'] = self::date2timestamp($dtstamp['value']) . '000'; 348 } 349 350 /* Definindo TRANSP */ 351 if(($tranp = $component->getProperty( 'transp', false , true )) && strtoupper($tranp) == 'OPAQUE') 352 $vevent['transparent'] = 1; 353 354 /* Definindo last_update */ 355 if($lastUpdate = $component->getProperty( 'LAST-MODIFIED', false , true )) 356 { 357 if(isset($lastUpdate['params']['TZID']) && !isset($lastUpdate['value']['tz'])) 358 $vevent['lasUpdate'] = self::date2timestamp($lastUpdate['value']) - self::_getTzOffset('UTC',$lastUpdate['params']['TZID']) . '000'; 359 else 360 $vevent['lastUpdate'] = self::date2timestamp($lastUpdate['value']) . '000'; 361 } 362 363 $interation['schedulable://'.$veventID] = $vevent; 364 365 365 break; 366 366 367 } 367 368
Note: See TracChangeset
for help on using the changeset viewer.