- Timestamp:
- 12/26/12 15:02:28 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zpush/backend/expresso/providers/calendarProvider.php
r7671 r7687 4 4 require_once EXPRESSO_PATH . '/prototype/api/controller.php'; 5 5 require_once EXPRESSO_PATH . '/prototype/api/config.php'; 6 require_once EXPRESSO_PATH . '/prototype/modules/calendar/constants.php'; 6 7 7 8 use prototype\api\Config as Config; … … 162 163 $messages = array(); 163 164 164 $sql = 'SELECT calendar_object.last_update , calendar_object.cal_uid FROM calendar_signature , calendar , calendar_to_calendar_object, calendar_object WHERE calendar_signature.id = '.$idNumber.' AND calendar_signature.calendar_id = calendar.id AND calendar_to_calendar_object.calendar_id = calendar.id AND calendar_to_calendar_object.calendar_object_id = calendar_object.id AND calendar_object.last_update > '. $cutoffdate;165 $sql = 'SELECT calendar_object.last_update , calendar_object.cal_uid FROM calendar_signature , calendar , calendar_to_calendar_object, calendar_object WHERE calendar_signature.id = '.$idNumber.' AND calendar_signature.calendar_id = calendar.id AND calendar_to_calendar_object.calendar_id = calendar.id AND calendar_to_calendar_object.calendar_object_id = calendar_object.id AND calendar_object.last_update > '. $cutoffdate . '000'; 165 166 166 167 $rs = Controller::service('PostgreSQL')->execSql($sql); … … 222 223 } 223 224 224 $message->sensitivity = 0; // 0 - Normal 225 $message->sensitivity = 0; // 0 - Normal, 225 226 $message->alldayevent = (int)$schedulable['allDay']; // (0 - Não(default), 1- Sim) 226 $message->busystatus = 2; // 2 - Ocupado227 227 $message->timezone = base64_encode($this->_getSyncBlobFromTZ($this->_getGMTTZ())); 228 228 … … 241 241 $message->organizername = mb_convert_encoding($participant['user']['name'], 'UTF-8' , 'UTF-8,ISO-8859-1'); 242 242 $message->organizeremail = mb_convert_encoding($participant['user']['mail'], 'UTF-8' , 'UTF-8,ISO-8859-1'); 243 244 if(isset($participant['alarms'][0])) 243 } 244 else 245 { 246 $attendee = new SyncAttendee(); 247 $attendee->name = mb_convert_encoding($participant['user']['name'], 'UTF-8' , 'UTF-8,ISO-8859-1'); 248 $attendee->email = mb_convert_encoding($participant['user']['mail'], 'UTF-8' , 'UTF-8,ISO-8859-1'); 249 $message->attendees[] = $attendee; 250 } 251 252 if($participant['user']['id'] == $this->_uidnumber ) 253 { 254 if($participant['isOrganizer'] == 1 || strpos($participant['acl'] ,'w') !== false) // Caso ele seja organizador ou tenha permisão de editar o evento 255 { 256 $message->meetingstatus = 0; 257 } 258 else 259 { 260 $message->meetingstatus = 3; 261 } 262 263 if(isset($participant['alarms'][0]) ) 245 264 { 246 265 switch($participant['alarms'][0]['unit']) … … 260 279 } 261 280 281 switch($participant['status']) 282 { 283 case STATUS_ACCEPTED: 284 $message->busystatus = 2; 285 break; 286 case STATUS_TENTATIVE: 287 $message->busystatus = 1; 288 break; 289 case STATUS_DECLINED: 290 $message->busystatus = 3; 291 break; 292 case STATUS_UNANSWERED: 293 $message->busystatus = 0; 294 break; 295 } 296 262 297 } 263 else264 {265 $attendee = new SyncAttendee();266 $attendee->name = mb_convert_encoding($participant['user']['name'], 'UTF-8' , 'UTF-8,ISO-8859-1');267 $attendee->email = mb_convert_encoding($participant['user']['mail'], 'UTF-8' , 'UTF-8,ISO-8859-1');268 $message->attendees[] = $attendee;269 }270 //TODO: Verificar status dos convidados271 298 } 272 299 } … … 333 360 $message->recurrence = $recur; 334 361 } 362 363 335 364 return $message; 336 365 } … … 386 415 { 387 416 388 389 return $idMessage ? $this->updateEvent($folderid, $idMessage, $message) : $this->createEvent($folderid, $idMessage, $message);390 }391 392 private function updateEvent($folderid, $idMessage, $message)393 {394 417 $idNumber = (int)str_replace('calendar' , '' , $folderid); 395 418 $calendarSignature = Controller::read( array( 'concept' => 'calendarSignature' , 'id' => $idNumber )); 396 419 $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $calendarSignature['calendar'] )); 397 420 398 $schedulable = Controller::find(array('concept' => 'schedulable'), null , array('deepness'=> 2 , 'filter' => array( '=' , 'uid' , $idMessage))); 399 $schedulable = $schedulable[0]; 421 if($idMessage) 422 { 423 $schedulable = Controller::find(array('concept' => 'schedulable'), null , array('deepness'=> 2 , 'filter' => array( '=' , 'uid' , $idMessage))); 424 $schedulable = $schedulable[0]; 425 426 427 foreach($schedulable['participants'] as $i => $v) 428 { 429 if($v['user']['id'] == $this->_uidnumber ) 430 { 431 if(strpos($v['acl'] ,'w') !== false) //Caso o usuario tenha permissão de editar o evento 432 { 433 return $this->updateEvent($folderid, $idMessage, $message , $calendar ,$schedulable); 434 } 435 else 436 { 437 $interation = array(); 438 439 if(isset($message->reminder) && $message->reminder > 0) 440 { 441 $alarm = array(); 442 $alarmID = mt_rand() . '6(Formatter)'; 443 $alarm['type'] = 'alert'; 444 $alarm['time'] = $message->reminder; 445 $alarm['unit'] = 'm'; 446 $alarm['participant'] = $v['id']; 447 $alarm['schedulable'] = $schedulable['id']; 448 $interation['alarm://' . $alarmID ] = $alarm; 449 450 } 451 452 $status = $this->formatBusy($message->busystatus); 453 454 if($status == STATUS_DECLINED ) //Caso ele não seja dono do evento e recusou o convite deletar o evento da sua agenda. 455 { 456 Controller::deleteAll(array('concept' => 'calendarToSchedulable' ) , false , array('filter' => array('AND', array('=','calendar',$calendarSignature['calendar']), array('=','schedulable',$schedulable['id'])))); 457 } 458 459 $v['status'] = $status; 460 461 $interation['participant://' . $v['id'] ] = $v; 462 463 ob_start(); 464 $args = $interation; 465 include EXPRESSO_PATH.'/prototype/Sync.php'; 466 ob_end_clean(); 467 468 } 469 } 470 } 471 return $this->StatMessage($folderid, $message->uid); 472 } 473 else 474 { 475 if (!$schedulable = $this->_getSchedulable($message->uid)) 476 return $this->createEvent($folderid, $idMessage, $message ,$calendar); 477 else{ 478 $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 479 array('AND', 480 array('=', 'calendar', $calendar['id']), 481 array('=', 'schedulable', $schedulable['id']) 482 ))); 483 484 if(!$links && !isset($links[0])) 485 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $calendar['id'], 'schedulable' => $schedulable['id'])); 486 487 foreach($schedulable['participants'] as $i => $v) 488 { 489 if($v['user']['id'] == $this->_uidnumber) 490 { 491 Controller::update(array('concept' => 'participant','id' => $v['id']), array('status' => $this->formatBusy($message->busystatus ) )); 492 } 493 } 494 495 return $this->StatMessage($folderid, $message->uid); 496 } 497 } 498 499 } 500 501 private function _getSchedulable($uid) { 502 $schedulable = Controller::find(array('concept' => 'schedulable'), false, array('filter' => array('=', 'uid', $uid), 'deepness' => 2)); 503 return (isset($schedulable[0])) ? $schedulable[0] : false; 504 } 505 506 private function updateEvent($folderid, $idMessage, $message , $calendar ,$schedulable ) 507 { 508 400 509 401 510 $tz_CEL = $this->_getTZFromSyncBlob(base64_decode($message->timezone)); … … 584 693 } 585 694 695 foreach($schedulable['participants'] as $i => $v) 696 { 697 if($v['user']['id'] == $this->_uidnumber ) 698 { 699 $schedulable['participants'][$i]['status'] = $this->formatBusy($message->busystatus); 700 } 701 } 702 586 703 unset($schedulable['repeat']); 587 704 … … 596 713 } 597 714 598 private function createEvent($folderid, $idMessage, $message) 599 { 600 $idNumber = (int)str_replace('calendar' , '' , $folderid); 601 $calendarSignature = Controller::read( array( 'concept' => 'calendarSignature' , 'id' => $idNumber )); 602 $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $calendarSignature['calendar'] )); 603 604 715 private function createEvent($folderid, $idMessage, $message , $calendar) 716 { 605 717 $tz_CEL = $this->_getTZFromSyncBlob(base64_decode($message->timezone)); 606 718 $GMT_CEL = -(($tz_CEL["bias"] + $tz_CEL["dstbias"]) * 60); … … 611 723 $eventID = mt_rand() . '(Formatter)'; 612 724 613 $schedulable['calendar'] = $calendar Signature['calendar'];725 $schedulable['calendar'] = $calendar['id']; 614 726 $schedulable['uid'] = $message->uid; 615 727 $schedulable['summary'] = $message->subject; … … 664 776 $participant['isExternal'] = 0; 665 777 $participant['user'] = $this->_uidnumber; 778 $participant['status'] = $this->formatBusy($message->busystatus); 666 779 } 667 780 … … 754 867 $participant['user'] = $userID; 755 868 $interation['user://' . $userID] = $user; 869 870 if($userID == $this->_uidnumber) 871 { 872 $participant['status'] = $this->formatBusy($message->busystatus); 873 } 874 756 875 } 757 876 … … 834 953 public function DeleteMessage($folderid, $id) 835 954 { 836 $even = Controller::find(array('concept' => 'schedulable') , false , array ( 'filter' => array('=' , 'uid' , $id ) ) ); 837 838 if(is_array($even) && count($even) > 0 ) 839 Controller::delete(array('concept' => 'schedulable' , 'id' => $even[0]['id'])); 840 955 956 $idNumber = (int)str_replace('calendar' , '' , $folderid); 957 $calendarSignature = Controller::read( array( 'concept' => 'calendarSignature' , 'id' => $idNumber )); 958 $even = $this->_getSchedulable($id ); 959 $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $calendarSignature['calendar'] )); 960 961 $link = Controller::read(array('concept' => 'calendarToSchedulable'), false, array('filter' => array('AND', array('=','calendar',$calendarSignature['calendar']), array('=','schedulable',$even['id'])))); 962 963 $delete = false; 964 foreach($even['participants'] as $i => $v) 965 { 966 if($v['user']['id'] == $this->_uidnumber && $v['user']['isOrganizer'] == '1') 967 { 968 $delete = true; 969 } 970 } 971 972 if( $delete === true) 973 { 974 Controller::delete(array('concept' => 'schedulable' , 'id' => $even['id'])); 975 } 976 else 977 { 978 Controller::delete(array('concept' => 'calendarToSchedulable', 'id' => $link[0]['id'])); 979 980 foreach($even['participants'] as $i => $v) 981 { 982 if($v['user']['id'] == $this->_uidnumber) 983 { 984 Controller::update(array('concept' => 'participant','id' => $v['id']), array('status' => STATUS_CANCELLED )); 985 } 986 } 987 988 } 841 989 return true; 842 990 } … … 897 1045 $_SESSION['flags']['currentapp'] = 'expressoCalendar'; 898 1046 899 Config::regSet( 'noAlarm' , true ); //Evita envio de alertas pelo expresso isto é responsabilidade do cliente celular900 1047 //----------------------------------------------------------------------------------------// 901 1048 … … 1044 1191 return false; 1045 1192 } 1193 1194 1195 private function formatBusy($status) 1196 { 1197 switch($status) 1198 { 1199 case 2: 1200 return STATUS_ACCEPTED; 1201 break; 1202 case 1: 1203 return STATUS_TENTATIVE; 1204 break; 1205 case 3: 1206 return STATUS_DECLINED; 1207 break; 1208 case 0: 1209 return STATUS_UNANSWERED; 1210 break; 1211 } 1212 } 1213 1214 1215 1046 1216 }
Note: See TracChangeset
for help on using the changeset viewer.