/**
  * fetches all events and sorts exceptions into exdate prop for given filter
  * 
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string                            $action
  */
 protected function _getEvents($_filter, $_action)
 {
     if (!$_filter instanceof Calendar_Model_EventFilter) {
         $_filter = new Calendar_Model_EventFilter();
     }
     $events = $this->_eventController->search($_filter, NULL, FALSE, FALSE, $_action);
     // if an id filter is set, we need to fetch exceptions in a second query
     if ($_filter->getFilter('id', true, true)) {
         $events->merge($this->_eventController->search(new Calendar_Model_EventFilter(array(array('field' => 'base_event_id', 'operator' => 'in', 'value' => $events->id), array('field' => 'id', 'operator' => 'notin', 'value' => $events->id), array('field' => 'recurid', 'operator' => 'notnull', 'value' => null))), NULL, FALSE, FALSE, $_action));
     }
     $this->_eventController->getAlarms($events);
     Tinebase_FileSystem_RecordAttachments::getInstance()->getMultipleAttachmentsOfRecords($events);
     $baseEventMap = array();
     // id => baseEvent
     $exceptionSets = array();
     // id => exceptions
     $exceptionMap = array();
     // idx => event
     foreach ($events as $event) {
         if ($event->rrule) {
             $eventId = $event->id;
             $baseEventMap[$eventId] = $event;
             $exceptionSets[$eventId] = new Tinebase_Record_RecordSet('Calendar_Model_Event');
         } else {
             if ($event->recurid) {
                 $exceptionMap[] = $event;
             }
         }
     }
     foreach ($exceptionMap as $exception) {
         $baseEventId = $exception->base_event_id;
         $baseEvent = array_key_exists($baseEventId, $baseEventMap) ? $baseEventMap[$baseEventId] : false;
         if ($baseEvent) {
             $exceptionSet = $exceptionSets[$baseEventId];
             $exceptionSet->addRecord($exception);
             $events->removeRecord($exception);
         }
     }
     foreach ($baseEventMap as $id => $baseEvent) {
         $exceptionSet = $exceptionSets[$id];
         $this->_eventController->fakeDeletedExceptions($baseEvent, $exceptionSet);
         $baseEvent->exdate = $exceptionSet;
     }
     return $events;
 }
Ejemplo n.º 2
0
 /**
  * fetches all eventids for given filter
  * 
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string                            $action
  */
 protected function _getEventIds($_filter, $_action)
 {
     if (!$_filter instanceof Calendar_Model_EventFilter) {
         $_filter = new Calendar_Model_EventFilter();
     }
     $recurIdFilter = new Tinebase_Model_Filter_Text('recurid', 'isnull', null);
     $_filter->addFilter($recurIdFilter);
     $baseEventIds = $this->_eventController->search($_filter, NULL, FALSE, TRUE, $_action);
     $_filter->removeFilter($recurIdFilter);
     $baseEventUIDs = $this->_eventController->search(new Calendar_Model_EventFilter(array(array('field' => 'id', 'operator' => 'in', 'value' => $baseEventIds))), NULL, FALSE, 'uid', $_action);
     // add exceptions where the user has no access to the base event as baseEvents
     $uidFilter = new Tinebase_Model_Filter_Text('uid', 'notin', $baseEventUIDs);
     $recurIdFilter = new Tinebase_Model_Filter_Text('recurid', 'notnull', null);
     $_filter->addFilter($uidFilter);
     $_filter->addFilter($recurIdFilter);
     $baselessExceptionIds = $this->_eventController->search($_filter, NULL, FALSE, TRUE, $_action);
     $_filter->removeFilter($uidFilter);
     $_filter->removeFilter($recurIdFilter);
     return array_unique(array_merge($baseEventIds, $baselessExceptionIds));
 }