/**
  * 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;
 }