/**
  * Search for events matching given arguments
  *
  * @param  array $_filter
  * @param  array $_paging
  * @return array
  */
 public function searchEvents($filter, $paging)
 {
     $controller = Calendar_Controller_Event::getInstance();
     $decodedPagination = is_array($paging) ? $paging : Zend_Json::decode($paging);
     $pagination = new Tinebase_Model_Pagination($decodedPagination);
     $clientFilter = $filter = $this->_decodeFilter($filter, 'Calendar_Model_EventFilter');
     // find out if fixed calendars should be used
     $fixedCalendars = Calendar_Config::getInstance()->get(Calendar_Config::FIXED_CALENDARS);
     $useFixedCalendars = is_array($fixedCalendars) && !empty($fixedCalendars);
     $periodFilter = $filter->getFilter('period');
     // add period filter per default to prevent endless search
     if (!$periodFilter) {
         $periodFilter = $this->_getDefaultPeriodFilter();
         // periodFilter will be added to fixed filter when using fixed calendars
         if (!$useFixedCalendars) {
             $filter->addFilter($periodFilter);
         }
     }
     // add fixed calendar on demand
     if ($useFixedCalendars) {
         $fixed = new Calendar_Model_EventFilter(array(), 'AND');
         $fixed->addFilter(new Tinebase_Model_Filter_Text('container_id', 'in', $fixedCalendars));
         $fixed->addFilter($periodFilter);
         $og = new Calendar_Model_EventFilter(array(), 'OR');
         $og->addFilterGroup($fixed);
         $og->addFilterGroup($clientFilter);
         $filter = new Calendar_Model_EventFilter(array(), 'AND');
         $filter->addFilterGroup($og);
     }
     $records = $controller->search($filter, $pagination, FALSE);
     $result = $this->_multipleRecordsToJson($records, $clientFilter, $pagination);
     return array('results' => $result, 'totalcount' => count($result), 'filter' => $clientFilter->toArray(TRUE));
 }
 /**
  * Gets one entry (by property)
  *
  * @param  mixed  $_value
  * @param  string $_property
  * @param  bool   $_getDeleted
  * @return Tinebase_Record_Interface
  * @throws Tinebase_Exception_NotFound
  */
 public function getByProperty($_value, $_property = 'name', $_getDeleted = FALSE)
 {
     //$pagination = new Tinebase_Model_Pagination(array('limit' => 1));
     $filters = new Calendar_Model_EventFilter();
     $filter = new Tinebase_Model_Filter_Text($_property, 'equals', $_value);
     $filters->addFilter($filter);
     if ($_getDeleted) {
         $deletedFilter = new Tinebase_Model_Filter_Bool('is_deleted', 'equals', Tinebase_Model_Filter_Bool::VALUE_NOTSET);
         $filters->addFilter($deletedFilter);
     }
     $resultSet = $this->search($filters, NULL, FALSE);
     switch (count($resultSet)) {
         case 0:
             throw new Tinebase_Exception_NotFound($this->_modelName . " record with {$_property} " . $_value . ' not found!');
             break;
         case 1:
             $result = $resultSet->getFirstRecord();
             break;
         default:
             throw new Tinebase_Exception_UnexpectedValue(' in total ' . count($resultSet) . ' where found. But only one should!');
     }
     return $result;
 }
예제 #3
0
 /**
  * Gets one entry (by property)
  *
  * @param  mixed  $_value
  * @param  string $_property
  * @param  bool   $_getDeleted
  * @return Tinebase_Record_Interface
  * @throws Tinebase_Exception_NotFound
  */
 public function getByProperty($_value, $_property = 'name', $_getDeleted = FALSE)
 {
     //$pagination = new Tinebase_Model_Pagination(array('limit' => 1));
     $filters = new Calendar_Model_EventFilter();
     $filter = new Tinebase_Model_Filter_Text($_property, 'equals', $_value);
     $filters->addFilter($filter);
     // for get operations we need to take all attendee into account
     $filters->addFilter($filters->createFilter('attender', 'specialNode', 'all'));
     $resultSet = $this->search($filters, NULL, FALSE, $_getDeleted);
     switch (count($resultSet)) {
         case 0:
             throw new Tinebase_Exception_NotFound($this->_modelName . " record with {$_property} " . $_value . ' not found!');
             break;
         case 1:
             $result = $resultSet->getFirstRecord();
             break;
         default:
             throw new Tinebase_Exception_UnexpectedValue(' in total ' . count($resultSet) . ' where found. But only one should!');
     }
     return $result;
 }
예제 #4
0
 /**
  * Search for events matching given arguments
  *
  * @param  array $_filter
  * @param  array $_paging
  * @return array
  */
 public function searchEvents($filter, $paging)
 {
     $controller = Calendar_Controller_Event::getInstance();
     $decodedPagination = is_array($paging) ? $paging : Zend_Json::decode($paging);
     $pagination = new Tinebase_Model_Pagination($decodedPagination);
     $clientFilter = $filter = $this->_decodeFilter($filter, 'Calendar_Model_EventFilter');
     // add fixed calendar on demand
     $fixedCalendars = Tinebase_Config::getInstance()->getConfigAsArray('fixedCalendars', 'Calendar');
     if (is_array($fixedCalendars) && !empty($fixedCalendars)) {
         $fixed = new Calendar_Model_EventFilter(array(), 'AND');
         $fixed->addFilter(new Tinebase_Model_Filter_Text('container_id', 'in', $fixedCalendars));
         $periodFilter = $filter->getFilter('period');
         if ($periodFilter) {
             $fixed->addFilter($periodFilter);
         }
         $og = new Calendar_Model_EventFilter(array(), 'OR');
         $og->addFilterGroup($fixed);
         $og->addFilterGroup($clientFilter);
         $filter = new Calendar_Model_EventFilter(array(), 'AND');
         $filter->addFilterGroup($og);
     }
     $records = $controller->search($filter, $pagination, FALSE);
     $result = $this->_multipleRecordsToJson($records, $clientFilter, $pagination);
     return array('results' => $result, 'totalcount' => count($result), 'filter' => $clientFilter->toArray(TRUE));
 }
 /**
  * find existing event by uid
  *
  * @param $_iMIP
  * @param bool $_refetch
  * @param bool $_getDeleted
  * @return NULL|Tinebase_Record_Abstract
  */
 public function getExistingEvent($_iMIP, $_refetch = FALSE, $_getDeleted = FALSE)
 {
     if ($_refetch || !$_iMIP->existing_event instanceof Calendar_Model_Event) {
         $iMIPEvent = $_iMIP->getEvent();
         $filters = new Calendar_Model_EventFilter(array(array('field' => 'uid', 'operator' => 'equals', 'value' => $iMIPEvent->uid)));
         if ($_getDeleted) {
             $deletedFilter = new Tinebase_Model_Filter_Bool('is_deleted', 'equals', Tinebase_Model_Filter_Bool::VALUE_NOTSET);
             $filters->addFilter($deletedFilter);
         }
         $events = Calendar_Controller_MSEventFacade::getInstance()->search($filters);
         // NOTE: cancelled attendees from ext. organizers don't have read grant
         // find a better way to check grants
         if (!$_getDeleted) {
             $events = $events->filter(Tinebase_Model_Grants::GRANT_READ, TRUE);
         }
         $event = $events->getFirstRecord();
         Calendar_Model_Attender::resolveAttendee($event['attendee']);
         $_iMIP->existing_event = $event;
     }
     return $_iMIP->existing_event;
 }
예제 #6
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));
 }