示例#1
0
 public function analize($data, $params = false)
 {
     $vcalendar = new icalCreatorVcalendar();
     $vcalendar->parse(trim($data));
     $vcalendar->sort();
     $return = array();
     $method = $vcalendar->getProperty('method', FALSE, FALSE);
     while ($component = $vcalendar->getComponent()) {
         $interation = array();
         $uid = $component->getProperty('uid', false, false);
         //Resgata o uid do componente
         switch (strtoupper($component->objName)) {
             case 'VEVENT':
                 switch ($method) {
                     case 'PUBLISH':
                         $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');
                         break;
                     case 'REQUEST':
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable) {
                             //Caso o evento exista
                             $isOrganizer = false;
                             $isParticipant = false;
                             foreach ($schedulable['participants'] as $value) {
                                 if ($value['user']['id'] == $params['owner']) {
                                     $isParticipant = true;
                                     if ($value['isOrganizer']) {
                                         $isOrganizer = true;
                                     }
                                     if (!self::_existInMyCalendars($schedulable['id'], $params['owner']) || $value['status'] == STATUS_UNANSWERED || $value['status'] == STATUS_DECLINED) {
                                         $interation = ICAL_ACTION_UPDATE;
                                         $interation = strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ? ICAL_ACTION_IMPORT_REQUIRED : array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');
                                         break;
                                     } else {
                                         if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) {
                                             //Organizador esta requisitando que você atualize o evento
                                             $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE;
                                         } else {
                                             $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE;
                                         }
                                     }
                                 }
                             }
                             if (!$isParticipant) {
                                 if (self::_existInMyCalendars($schedulable['id'], $params['owner'])) {
                                     $interation = self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] ? ICAL_ACTION_UPDATE : ICAL_ACTION_NONE;
                                 } else {
                                     $interation = self::_checkParticipantByPermissions($schedulable);
                                 }
                             }
                         } else {
                             $interation = array('action' => ICAL_ACTION_IMPORT_REQUIRED, 'type' => 'calendarIds');
                         }
                         if ($interation != ICAL_ACTION_NONE && $interation != ICAL_ACTION_ORGANIZER_NONE && $interation != ICAL_ACTION_ORGANIZER_UPDATE && $interation != ICAL_ACTION_NONE && $interation != ICAL_ACTION_UPDATE && !is_array($interation)) {
                             if ($params['owner'] != Config::me("uidNumber")) {
                                 $sig = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=', 'user', $params['owner']), array('=', 'isOwner', '1'))));
                                 $calendars = array();
                                 foreach ($sig as $val) {
                                     $calendars[] = $val['calendar'];
                                 }
                                 $calendarsPermission = Controller::find(array('concept' => 'calendarToPermission'), array('calendar'), array('filter' => array('AND', array('=', 'user', Config::me("uidNumber")), array('IN', 'calendar', $calendars))));
                                 foreach ($calendarsPermission as $val) {
                                     $ids[] = $val['calendar'];
                                 }
                                 $interation = array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION, 'calendar' => $ids);
                             }
                         }
                         break;
                     case 'REFRESH':
                         break;
                     case 'CANCEL':
                         $interation = ICAL_ACTION_DELETE;
                         break;
                     case 'ADD':
                         break;
                     case 'REPLY':
                         if ($schedulable = self::_getSchedulable($uid)) {
                             while ($property = $component->getProperty('attendee', FALSE, TRUE)) {
                                 if ($attendee = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'], true)) {
                                     $interation = constant('STATUS_' . strtoupper($property['params']['PARTSTAT'])) == $attendee['status'] ? ICAL_ACTION_NONE : ICAL_ACTION_REPLY;
                                 }
                             }
                         } else {
                             $interation = ICAL_NOT_FOUND;
                         }
                         break;
                     case 'COUNTER':
                         $interation = ICAL_ACTION_SUGGESTION;
                         break;
                     case 'DECLINECOUNTER':
                         $interation = ICAL_ACTION_NONE;
                         break;
                     default:
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable && (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) {
                             //Caso o evento exista
                             $interation = ICAL_ACTION_UPDATE;
                         } else {
                             if ($schedulable) {
                                 $interation = ICAL_ACTION_NONE;
                             } else {
                                 // Importar evento
                                 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');
                             }
                         }
                         break;
                 }
                 $return[$uid] = $interation;
                 break;
             case 'VTODO':
                 switch ($method) {
                     case 'PUBLISH':
                         $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                         break;
                     case 'REQUEST':
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable) {
                             //Caso o evento exista
                             $isOrganizer = false;
                             $isParticipant = false;
                             foreach ($schedulable['participants'] as $value) {
                                 if ($value['user']['id'] == $params['owner']) {
                                     $isParticipant = true;
                                     if ($value['isOrganizer']) {
                                         $isOrganizer = true;
                                     }
                                     if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) {
                                         $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                                         break;
                                     }
                                 } else {
                                     ///Atualiza o Caldadav mesmo que o expresso não prescisse de atualização, pois os calendarios do caldav são independentes um de cada usuario diferente do expresso que so tem 1 evento e é compartilhado entre os usuarios
                                     if (Config::module('useCaldav', 'expressoCalendar')) {
                                         //Ignorar Put dos eventos ja vindos do caldav
                                         require_once ROOTPATH . '/modules/calendar/interceptors/DAViCalAdapter.php';
                                         $calendars = self::schedulable2calendarToObject($schedulable['id'], isset($params['owner']) ? $params['owner'] : false);
                                         //Busca os calendarios do usuario logado que contenham o evento
                                         if (is_array($calendars)) {
                                             foreach ($calendars as $calendar) {
                                                 DAViCalAdapter::putIcal($data, array('uid' => $schedulable['uid'], 'location' => $calendar['calendar_location']));
                                             }
                                         }
                                     }
                                     if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) {
                                         //Organizador esta requisitando que você atualize o evento
                                         $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE;
                                     } else {
                                         $interation = $isOrganizer ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE;
                                     }
                                 }
                             }
                             if (!$isParticipant) {
                                 $interation = self::_checkParticipantByPermissions($schedulable);
                             }
                         } else {
                             $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                         }
                         break;
                     case 'REFRESH':
                         break;
                     case 'CANCEL':
                         $interation = ICAL_ACTION_DELETE;
                         break;
                     case 'ADD':
                         break;
                     case 'REPLY':
                         $interation = ICAL_ACTION_REPLY;
                         break;
                     case 'COUNTER':
                         $interation = ICAL_ACTION_SUGGESTION;
                         break;
                     case 'DECLINECOUNTER':
                         $interation = ICAL_ACTION_NONE;
                         break;
                     default:
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable && (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) {
                             //Caso o evento exista
                             $interation = ICAL_ACTION_UPDATE;
                         } else {
                             if ($schedulable) {
                                 $interation = ICAL_ACTION_NONE;
                             } else {
                                 // Importar evento
                                 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'groupIds');
                             }
                         }
                         break;
                 }
                 $return[$uid] = $interation;
                 break;
             case 'VTIMEZONE':
                 break;
         }
     }
     return $return;
 }
示例#2
0
 static function delete($data, $params = false)
 {
     $user = Controller::find(array('concept' => 'user', 'service' => 'OpenLDAP'), false, array('filter' => array('=', 'uid', $params['owner']), 'notExternal' => true));
     $params['owner'] = $user[0]['id'];
     self::initSessionVars(array('user' => array('uidNumber' => $params['owner'])));
     //Busca as Agendas do usuario
     $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar'), array('filter' => array('=', 'user', $params['owner'])));
     //TODO: RESGATAR AGENDA
     foreach ($sig as $i => $v) {
         $cal = Controller::read(array('concept' => 'calendar', 'id' => $v['calendar']), array('location'));
         if ($cal['location'] === $params['calendarName']) {
             $params['calendar'] = $v['calendar'];
         }
     }
     if (isset($params['calendar'])) {
         require_once ROOTPATH . '/plugins/icalcreator/iCalcreator.class.php';
         $vcalendar = new icalCreatorVcalendar();
         $vcalendar->parse($data);
         $vcalendar->sort();
         $toDelete = array();
         while ($component = $vcalendar->getComponent()) {
             switch (strtoupper($component->objName)) {
                 case 'VEVENT':
                     $toDelete[] = $component->getProperty('uid', false, false);
                     break;
                 case 'VTIMEZONE':
                     break;
             }
         }
         self::$deleted = $toDelete;
         foreach ($toDelete as $v) {
             $even = Controller::find(array('concept' => 'schedulable'), false, array('filter' => array('AND', array('=', 'calendar', $params['calendar']), array('=', 'uid', $v))));
             if (is_array($even) && count($even) > 0) {
                 Controller::delete(array('concept' => 'schedulable', 'id' => $even[0]['id']));
             }
         }
     }
 }