/**
  * event handler for group updates
  * 
  * @param Tinebase_Model_Group $_group
  * @return void
  */
 public function onUpdateGroup($_groupId)
 {
     $doContainerACLChecks = $this->doContainerACLChecks(FALSE);
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'attender', 'operator' => 'equals', 'value' => array('user_type' => Calendar_Model_Attender::USERTYPE_GROUP, 'user_id' => $_groupId)), array('field' => 'period', 'operator' => 'within', 'value' => array('from' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'until' => Tinebase_DateTime::now()->addYear(100)->get(Tinebase_Record_Abstract::ISO8601LONG)))));
     $events = $this->search($filter, new Tinebase_Model_Pagination(), FALSE, FALSE);
     foreach ($events as $event) {
         try {
             if (!$event->rrule) {
                 // update non recurring futrue events
                 Calendar_Model_Attender::resolveGroupMembers($event->attendee);
                 $this->update($event);
             } else {
                 // update thisandfuture for recurring events
                 $nextOccurrence = Calendar_Model_Rrule::computeNextOccurrence($event, $this->getRecurExceptions($event), Tinebase_DateTime::now());
                 Calendar_Model_Attender::resolveGroupMembers($nextOccurrence->attendee);
                 if ($nextOccurrence->dtstart != $event->dtstart) {
                     $this->createRecurException($nextOccurrence, FALSE, TRUE);
                 } else {
                     $this->update($nextOccurrence);
                 }
             }
         } catch (Exception $e) {
             Tinebase_Core::getLogger()->NOTICE(__METHOD__ . '::' . __LINE__ . " could not update attendee");
         }
     }
     $this->doContainerACLChecks($doContainerACLChecks);
 }
 protected function _getEventAttendee($_egwEventData)
 {
     $tineAttendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender');
     foreach ($_egwEventData['attendee'] as $idx => $egwAttender) {
         try {
             $tineAttenderArray = array('quantity' => $egwAttender['cal_quantity'], 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'status' => isset($this->_attenderStatusMap[$egwAttender['cal_status']]) || array_key_exists($egwAttender['cal_status'], $this->_attenderStatusMap) ? $this->_attenderStatusMap[$egwAttender['cal_status']] : Calendar_Model_Attender::STATUS_NEEDSACTION, 'status_authkey' => Calendar_Model_Attender::generateUID());
             switch ($egwAttender['cal_user_type']) {
                 case 'u':
                     // user and group
                     if ($egwAttender['cal_user_id'] > 0) {
                         $tineAttenderArray['user_type'] = Calendar_Model_Attender::USERTYPE_USER;
                         $tineAttenderArray['user_id'] = Tinebase_User::getInstance()->getUserById($this->mapAccountIdEgw2Tine($egwAttender['cal_user_id']))->contact_id;
                         $tineAttenderArray['displaycontainer_id'] = $this->getPersonalContainer($this->mapAccountIdEgw2Tine($egwAttender['cal_user_id']))->getId();
                     } else {
                         $tineAttenderArray['user_type'] = Calendar_Model_Attender::USERTYPE_GROUP;
                         $tineAttenderArray['user_id'] = $this->mapAccountIdEgw2Tine($egwAttender['cal_user_id']);
                     }
                     break;
                 case 'c':
                     // try to find contact in tine (NOTE: id is useless, as contacts get new ids during migration)
                     $contact_id = $this->_getContactIdByEmail($egwAttender['email'], $this->mapAccountIdEgw2Tine($_egwEventData['cal_owner']));
                     if (!$contact_id) {
                         continue 2;
                     }
                     $tineAttenderArray['user_type'] = Calendar_Model_Attender::USERTYPE_USER;
                     $tineAttenderArray['user_id'] = $contact_id;
                     break;
                 case 'r':
                     $resource_id = $this->_getResourceId($egwAttender['cal_user_id']);
                     if (!$resource_id) {
                         continue 2;
                     }
                     $tineAttenderArray['user_type'] = Calendar_Model_Attender::USERTYPE_RESOURCE;
                     $tineAttenderArray['user_id'] = $resource_id;
                     break;
                 default:
                     throw new Exception("unsupported attender type: {$egwAttender['cal_user_type']}");
                     break;
             }
             $tineAttendee->addRecord(new Calendar_Model_Attender($tineAttenderArray));
         } catch (Exception $e) {
             $this->_log->warn(__METHOD__ . '::' . __LINE__ . ' skipping attender for event "' . $_egwEventData['cal_id'] . '"cause: ' . $e->getMessage());
             // skip attender
         }
     }
     // resolve groupmembers
     Calendar_Model_Attender::resolveGroupMembers($tineAttendee);
     $groupMembers = $tineAttendee->filter('user_type', Calendar_Model_Attender::USERTYPE_GROUPMEMBER);
     foreach ($groupMembers as $groupMember) {
         $groupMember->status_authkey = Calendar_Model_Attender::generateUID();
         $contact = Addressbook_Controller_Contact::getInstance()->get($groupMember->user_id);
         $groupMember->displaycontainer_id = $this->getPersonalContainer($contact->account_id)->getId();
     }
     return $tineAttendee;
 }
Esempio n. 3
0
 /**
  * event handler for group updates
  * 
  * @param Tinebase_Model_Group $_group
  * @return void
  */
 public function onUpdateGroup($_groupId)
 {
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'attender', 'operator' => 'equals', 'value' => array('user_type' => Calendar_Model_Attender::USERTYPE_GROUP, 'user_id' => $_groupId)), array('field' => 'dtstart', 'operator' => 'after', 'value' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG))));
     $doContainerACLChecks = $this->doContainerACLChecks(FALSE);
     $events = $this->search($filter, new Tinebase_Model_Pagination(), FALSE, FALSE);
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . ' (' . __LINE__ . ') updated group ' . $events);
     foreach ($events as $event) {
         Calendar_Model_Attender::resolveGroupMembers($event->attendee);
         $this->update($event);
     }
     $this->doContainerACLChecks($doContainerACLChecks);
 }