Changeset 5415 for trunk/prototype/services
- Timestamp:
- 01/24/12 17:22:37 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/services/iCal.php
r5399 r5415 105 105 $vcalendar = new icalCreator( ); 106 106 $vcalendar->parse(trim($data)); 107 $vcalendar->sort(); 108 107 $vcalendar->sort(); 108 109 109 $return = array(); 110 111 110 $method = $vcalendar->getProperty('method',FALSE , FALSE); 112 111 $params['prodid'] = $vcalendar->getProperty( 'prodid' , false , false ); 112 113 113 while ($component = $vcalendar->getComponent()) 114 { 115 114 { 116 115 $interation = array(); 116 $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente 117 117 118 118 switch (strtoupper($component->objName)) { 119 119 case 'VEVENT': 120 $vevent = array();121 $vevent['uid'] = $component->getProperty( 'uid' , false , false );122 $vevent['type'] = EVENT_ID;123 120 124 $exists = Controller::find(array('concept' => 'schedulable') , null , array ( 'deepness' => '*' , 'filter' => array('=' , 'uid' , $vevent['uid'] )));125 $exists = ( is_array($exists) && count($exists) > 0 ) ? $exists[0] : false;126 127 121 switch ($method) 128 122 { 129 case 'REPLY': 130 131 if($exists !== false) 132 { 133 while($property = $component->getProperty('attendee',FALSE , TRUE)) 134 if( $pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $exists['participants'])) 135 $interation['participant://'.$pID] = array( 'id' => $pID , 'status' => constant('STATUS_'.strtoupper($property['params']['PARTSTAT'])) ); 136 } 123 case 'PUBLISH': 124 if( !$schedulable = self::_getSchedulable($uid)) 125 $interation['schedulable://'.mt_rand().'(Formatter)'] = self::_makeCreateVEVENT($component); 137 126 break; 138 127 139 case 'CANCEL': 140 if($exists !== false) 141 $interation['schedulable://'.$exists['id']] = false; 142 break; 143 144 default: 145 $veventID = mt_rand().'1(Formatter)'; 146 147 if($exists !== false) 148 { 149 Config::regSet('noAlarm', False); //Reativa o envio de notificação 150 $existsCalendarToSchedulable = Controller::find( array( 'concept' => 'calendarToSchedulable' ) , array('id') ,array( 'filter' => array('AND' , array('=' , 'calendar' , $params['calendar'] ), array('=' , 'schedulable' , $exists['id'] ) )) ); 151 152 153 if( !is_array($existsCalendarToSchedulable) || count($existsCalendarToSchedulable) < 1 ) 154 { 128 case 'REQUEST': 129 $schedulable = self::_getSchedulable($uid); 130 131 if($schedulable) //Caso o evento exista 132 { 133 if(!self::_existInMyCalendars($schedulable['id'])) 134 { 155 135 $calendarToSchedulable = array(); 156 136 $calendarToSchedulable['calendar'] = $params['calendar']; 157 $calendarToSchedulable['schedulable'] = $ exists['id'];137 $calendarToSchedulable['schedulable'] = $schedulable['id']; 158 138 $interation['calendarToSchedulable://'.mt_rand().'(Formatter)'] = $calendarToSchedulable; 159 continue; 160 } 161 // Codigo para atualizar status do importador. não nescessario pois sera enviado um email de configmação para o organizador. 162 // foreach ($exists['participants'] as $participant) 163 // if($participant['user']['id'] == Config::me('uidNumber')) 164 // $interation['participant://'.$participant['id']] = array( 'id' => $participant['id'], 'status' => STATUS_CONFIRMED); 165 166 $veventID = $exists['id']; 167 $vevent = $exists; 168 } 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']) ) 139 140 if(isset($params['status'])) 141 { 142 $pID = self::_getParticipantByMail( Config::me('mail') , $schedulable['participants'] ); 143 $interation['participant://'.$pID]['status'] = $params['status']; 144 } 145 } 146 else 147 { 148 if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 149 $interation = self::_makeVEVENT($schedulable , $component , $params); 150 else if ( $component->getProperty( 'sequence' , false , false ) === $schedulable['sequence']) 180 151 { 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 152 //Ler melhor rfc sobre isto 3.2.2.2 153 //Aparentemente é para retornar um ical com o evento atualizado para o attende 154 } 322 155 } 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 { 329 $participantID = mt_rand().'2(Formatter)'; 330 331 $participant['schedulable'] = $veventID; 332 $participant['status'] = STATUS_CONFIRMED; 333 $participant['isOrganizer'] = '1'; 334 $participant['isExternal'] = 0; 335 $participant['user'] = $params['owner']; 336 $interation['participant://'.$participantID] = $participant; 337 $vevent['participants'][] = $participantID; 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 156 157 }else // Importar evento 158 $interation = self::_makeVEVENT( array() , $component , $params); 159 160 break; 161 162 case 'REFRESH': 163 break; 164 165 case 'CANCEL': 166 if($schedulable = self::_getSchedulable($uid)) 167 $interation['schedulable://'.$schedulable['id']] = false; 365 168 break; 169 170 case 'ADD': 171 break; 172 173 case 'REPLY': 174 if( $schedulable = self::_getSchedulable($uid) ) 175 { 176 while($property = $component->getProperty('attendee',FALSE , TRUE)) 177 if( $pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) 178 $interation['participant://'.$pID] = array( 'id' => $pID , 'status' => constant('STATUS_'.strtoupper($property['params']['PARTSTAT'])) ); 179 } 180 break; 181 182 case 'COUNTER': 183 break; 184 185 case 'DECLINE-COUNTER': 186 break; 187 188 default: 189 $schedulable = self::_getSchedulable($uid); 366 190 191 if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista 192 $interation = self::_makeVEVENT($schedulable , $component , $params); 193 else // Importar evento 194 $interation = self::_makeVEVENT( array() , $component , $params); 195 196 break; 367 197 } 368 198 … … 376 206 377 207 } 378 208 379 209 return $return; 380 210 } 211 212 public function analize ( $data , $params = false) 213 { 214 $vcalendar = new icalCreator( ); 215 $vcalendar->parse(trim($data)); 216 $vcalendar->sort(); 217 218 $return = array(); 219 $method = $vcalendar->getProperty('method',FALSE , FALSE); 220 221 while ($component = $vcalendar->getComponent()) 222 { 223 $interation = array(); 224 $uid = $component->getProperty( 'uid' , false , false ); //Resgata o uid do componente 225 226 switch (strtoupper($component->objName)) { 227 case 'VEVENT': 228 229 switch ($method) 230 { 231 case 'PUBLISH': 232 $interation = ICAL_ACTION_IMPORT; 233 break; 234 235 case 'REQUEST': 236 $schedulable = self::_getSchedulable($uid); 237 238 if($schedulable ) //Caso o evento exista 239 { 240 if(!self::_existInMyCalendars($schedulable['id'])) 241 $interation = ICAL_ACTION_IMPORT; 242 else 243 { 244 if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 245 $interation = ICAL_ACTION_UPDATE; 246 else 247 $interation = ICAL_ACTION_NONE; 248 } 249 }else 250 $interation = ICAL_ACTION_IMPORT; 251 252 break; 253 254 case 'REFRESH': 255 break; 256 257 case 'CANCEL': 258 $interation = ICAL_ACTION_DELETE; 259 break; 260 261 case 'ADD': 262 break; 263 264 case 'REPLY': 265 $interation = ICAL_ACTION_REPLY; 266 break; 267 268 case 'COUNTER': 269 break; 270 271 case 'DECLINE-COUNTER': 272 break; 273 274 default: 275 $schedulable = self::_getSchedulable($uid); 276 277 if($schedulable && ( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence'])) //Caso o evento exista 278 $interation = ICAL_ACTION_UPDATE; 279 else if($schedulable) 280 $interation = ICAL_ACTION_NONE; 281 else // Importar evento 282 $interation = ICAL_ACTION_IMPORT; 283 284 break; 285 } 286 287 $return[$uid] = $interation; 288 break; 289 case 'VTIMEZONE': 290 291 292 break; 293 } 294 295 } 296 297 return $return; 298 } 299 381 300 382 301 /* Helpers */ … … 410 329 411 330 private static function _getParticipantByMail( $mail , &$participants ) 412 { 413 331 { 414 332 foreach ($participants as $i => $v) 415 333 if($v['user']['mail'] == $mail || (isset($v['user']['mailAlternateAddress']) && in_array($mail, $v['user']['mailAlternateAddress']))) … … 447 365 } 448 366 367 static private function _makeVEVENT( $schedulable , $component ,$params) 368 { 369 $interation = array(); 370 $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand().'(Formatter)'; 371 372 /* Data de Inicio*/ 373 $startTime = $component->getProperty( 'dtstart', false , true ); 374 375 376 /* Tiem zone do evento*/ 377 if(isset($startTime['params']['TZID'])) 378 $schedulable['timezone'] = self::nomalizeTZID ($startTime['params']['TZID']); 379 else 380 $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 381 382 $objTimezone = new DateTimeZone($schedulable['timezone']); 383 384 if($startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone']) ) 385 { 386 $schedulable['allDay'] = 1; 387 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone']) . '000'; 388 } 389 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 */ 390 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC',$startTime['params']['TZID']) . '000'; 391 else 392 { 393 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 394 if( strpos($params['prodid'], 'Outlook') !== false ) 395 { 396 //Se o ics veio em utc não aplicar horario de verão 397 $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , new DateTimeZone('UTC') ); 398 $sTime->setTimezone($objTimezone); 399 if($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 400 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 401 } 402 } 403 404 405 /* Data de Termino*/ 406 $endTime = $component->getProperty( 'dtend', false , true ); 407 408 if($endTime['params']['VALUE'] === 'DATE') 409 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$schedulable['timezone']) . '000'; 410 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 */ 411 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC',$endTime['params']['TZID']) . '000'; 412 else 413 { 414 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 415 if( strpos($params['prodid'], 'Outlook') !== false ) 416 { 417 //Se o ics veio em utc não aplicar horario de verão 418 $eTime = new DateTime( '@'.(int)($schedulable['endTime'] / 1000) ,new DateTimeZone('UTC')); 419 $eTime->setTimezone($objTimezone); 420 if($eTime->format('I')) 421 $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 422 } 423 } 424 425 426 $schedulable['summary'] = mb_convert_encoding ( $component->getProperty( 'summary' , false , false ) , 'UTF-8' , 'UTF-8,ISO-8859-1'); 427 428 /* Definindo Description */ 429 if($desc = $component->getProperty( 'description' , false , false )) 430 $schedulable['description'] = mb_convert_encoding (str_ireplace ('\n', "\n", $desc) ,'UTF-8' , 'UTF-8,ISO-8859-1'); 431 432 /* Definindo location */ 433 if($location = $component->getProperty( 'location' , false , false )) 434 $schedulable['location'] = mb_convert_encoding ( $location , 'UTF-8' , 'UTF-8,ISO-8859-1') ; 435 436 437 /* Definindo Class */ 438 $class = $component->getProperty( 'class' , false , false ); 439 if( $class && defined(constant(strtoupper('CLASS_'.$class))) ) 440 $schedulable['class'] = constant(strtoupper('CLASS_'.$class)); 441 else if( !isset($exists['class']) ) 442 $schedulable['class'] = CLASS_PRIVATE ; // padrão classe private 443 444 /* Definindo RRULE */ 445 if( $rrule = $component->getProperty( 'rrule' , false , false )) 446 { 447 /* Gera um randon id para o contexto formater */ 448 $repeatID = mt_rand().'3(Formatter)'; 449 450 $repeat = array(); 451 $repeat['schedulable'] = $eventID; 452 foreach($rrule as $i => $v) 453 $repeat[strtolower($i)] = $v; 454 455 //$interation['repeat://'.$repeatID] = $repeat; 456 } 457 458 459 $schedulable['calendar'] = $params['calendar']; 460 461 $participantsInEvent = array(); 462 463 //TODO: Participants com delegated não estao sendo levados em conta 464 while($property = $component->getProperty('attendee',FALSE , TRUE)) 465 { 466 $participant = array(); 467 468 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 469 470 $participantID = mt_rand().'2(Formatter)'; 471 $participant['schedulable'] = $eventID; 472 473 if(isset($params['status']) && $mailUser == Config::me('mail')) 474 $participant['status'] = $params['status']; 475 else 476 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 477 478 479 $participant['isOrganizer'] = '0'; 480 481 /* Verifica se este usuario é um usuario interno do ldap */ 482 $intUser = Controller::find( array( 'concept' => 'user', 'service' => 'OpenLDAP' ) , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); 483 484 if( !is_array($intUser) || count($intUser) < 1 ) 485 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' , $mailUser )) ); 486 487 488 $user = null; 489 if( $intUser && count($intUser) > 0 ) 490 { 491 $participant['isExternal'] = 0; 492 $participant['user'] = $intUser[0]['id']; 493 } 494 else 495 { 496 $participant['isExternal'] = 1; 497 /* Gera um randon id para o contexto formater */ 498 $userID = mt_rand().'4(Formatter)'; 499 500 $user['mail'] = $mailUser; 501 $user['isExternal'] = '1'; 502 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 503 $user['participants'] = array($participantID); 504 $participant['user'] = $userID; 505 $interation['user://'.$userID] = $user; 506 } 507 508 $interation['participant://'.$participantID] = $participant; 509 $schedulable['participants'][] = $participantID; 510 511 }; 512 513 if($property = $component->getProperty('organizer',FALSE , TRUE)) 514 { 515 $participant = array(); 516 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 517 518 $participantID = mt_rand().'2(Formatter)'; 519 520 $participant['schedulable'] = $eventID; 521 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_'.$property['params']['PARTSTAT']) !== null ) ? constant('STATUS_'.$property['params']['PARTSTAT']) : STATUS_UNANSWERED; 522 $participant['isOrganizer'] = '1'; 523 524 /* Verifica se este usuario é um usuario interno do ldap */ 525 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'OpenLDAP') , array('uidNumber') ,array( 'filter' => array('OR' , array('=' , 'mail' , $mailUser ), array('=' , 'mailAlternateAddress' , $mailUser ) )) ); 526 527 if( !is_array($intUser) || count($intUser) < 1 ) 528 $intUser = Controller::find( array( 'concept' => 'user' ,'service' => 'PostgreSQL') , array('uidNumber') ,array( 'filter' => array('=' , 'mail' , $mailUser )) ); 529 530 $user = null; 531 if( $intUser && count($intUser) > 0 ) 532 { 533 $participant['isExternal'] = 0; 534 $participant['user'] = $intUser[0]['id']; 535 } 536 else 537 { 538 $participant['isExternal'] = 1; 539 /* Gera um randon id para o contexto formater */ 540 $userID = mt_rand().'4(Formatter)'; 541 542 $user['mail'] = $mailUser; 543 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 544 $user['participants'] = array($participantID); 545 $user['isExternal'] = '1'; 546 $participant['user'] = $userID; 547 $interation['user://'.$userID] = $user; 548 } 549 550 $interation['participant://'.$participantID] = $participant; 551 $schedulable['participants'][] = $participantID; 552 553 } 554 else if(!is_array($schedulable['participants']) || count($schedulable['participants']) < 1)//caso não tenha organizador o usuario se torna organizador 555 { 556 $user = Controller::read( array( 'concept' => 'user', 'id' => $params['owner'] ) , array('mail')); 557 558 if(!self::_getParticipantByMail($user['mail'] , $exists['participants'])) 559 { 560 $participantID = mt_rand().'2(Formatter)'; 561 562 $participant['schedulable'] = $eventID; 563 $participant['status'] = STATUS_CONFIRMED; 564 $participant['isOrganizer'] = '1'; 565 $participant['isExternal'] = 0; 566 $participant['user'] = $params['owner']; 567 $interation['participant://'.$participantID] = $participant; 568 $schedulable['participants'][] = $participantID; 569 } 570 } 571 572 /* Definindo DTSTAMP */ 573 if($dtstamp = self::_getTime($component , 'dtstamp') ) 574 $schedulable['dtstamp'] = $dtstamp; 575 576 /* Definindo TRANSP */ 577 if(($tranp = $component->getProperty( 'transp', false , true )) && strtoupper($tranp) == 'OPAQUE') 578 $schedulable['transparent'] = 1; 579 580 /* Definindo last_update */ 581 if($lastUpdate = self::_getTime($component , 'LAST-MODIFIED')) 582 $schedulable['lastUpdate'] = $lastUpdate; 583 584 585 if($sequence = $component->getProperty( 'SEQUENCE', false , false )) 586 $schedulable['sequence'] = $sequence; 587 588 if($uid = $component->getProperty( 'uid' , false , false )); 589 $schedulable['uid'] = $uid; 590 591 $interation['schedulable://'.$eventID] = $schedulable; 592 593 return $interation; 594 } 595 596 static private function _getSchedulable( $uid ) 597 { 598 $schedulable = Controller::find( array( 'concept' => 'schedulable' ) , null , array ( 'deepness' => '2' , 'filter' => array( '=' , 'uid' , $uid ))); 599 return (isset($schedulable[0])) ? $schedulable[0] : false; 600 } 601 602 static private function _existInMyCalendars( $id ) 603 { 604 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user','calendar'), array('filter' => array( '=' , 'user' , Config::me('uidNumber')))); 605 $calendars = array(); 606 foreach ($sig as $val) 607 $calendars[] = $val['calendar']; 608 609 $return = Controller::find( array( 'concept' => 'calendarToSchedulable' ) , null , array ( 'filter' => array('AND' , array( 'IN' , 'calendar' , $calendars ),array( '=' , 'schedulable' , $id )))); 610 611 return (isset($return[0])) ? true : false; 612 } 613 614 static private function _getTime(&$component , $property) 615 { 616 if($date = $component->getProperty($property , false , true )) 617 return (isset($date['params']['TZID']) && !isset($date['value']['tz'])) ? (self::date2timestamp($date['value']) - self::_getTzOffset('UTC',$date['params']['TZID'])) . '000' : self::date2timestamp($date['value']) . '000'; 618 619 return false; 620 } 449 621 } 450 622 ?>
Note: See TracChangeset
for help on using the changeset viewer.