/**
  * get records and resolve fields
  *
  * @return Tinebase_Record_RecordSet
  */
 protected function _getRecords()
 {
     $pagination = !empty($this->_options['sortInfo']) ? new Tinebase_Model_Pagination($this->_options['sortInfo']) : new Tinebase_Model_Pagination();
     if ($this->_recordIds === NULL) {
         // need to fetch record ids first because filtered fields can change during iteration step
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Getting record ids using filter: ' . print_r($this->_filter->toArray(), TRUE) . ' and pagination: ' . print_r($pagination->toArray(), true));
         }
         $this->_recordIds = $this->_controller->search($this->_filter, $pagination, FALSE, TRUE, $this->_options['searchAction']);
         $this->_totalCount = count($this->_recordIds);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . $this->_totalCount . ' total records to process.');
         }
         if (empty($this->_recordIds)) {
             return new Tinebase_Record_RecordSet($this->_filter->getModelName());
         }
     }
     // get records by filter (ensure acl)
     $filterClassname = get_class($this->_filter);
     $recordIdsForIteration = array_splice($this->_recordIds, 0, $this->_options['limit']);
     $idFilter = new $filterClassname(array(array('field' => isset($this->_options['idProperty']) || array_key_exists('idProperty', $this->_options) ? $this->_options['idProperty'] : 'id', 'operator' => 'in', 'value' => $recordIdsForIteration)));
     $records = $this->_controller->search($idFilter, $pagination, $this->_options['getRelations']);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got ' . count($records) . ' for next iteration.');
     }
     return $records;
 }
 /**
  * export records
  */
 protected function _exportRecords()
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Starting export of ' . $this->_modelName . ' with filter: ' . print_r($this->_filter->toArray(), true) . ' and sort info: ' . print_r($this->_sortInfo, true));
     }
     $iterator = new Tinebase_Record_Iterator(array('iteratable' => $this, 'controller' => $this->_controller, 'filter' => $this->_filter, 'options' => array('searchAction' => 'export', 'sortInfo' => $this->_sortInfo, 'getRelations' => $this->_getRelations)));
     $result = $iterator->iterate();
     $this->_onAfterExportRecords($result);
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Exported ' . $result['totalcount'] . ' records.');
     }
 }
Example #3
0
 public function toArray($_valueToJson = false)
 {
     $result = parent::toArray($_valueToJson);
     /* foreach ($result as &$filterData) {
            if ($filterData['field'] == 'id' && $_valueToJson == true && ! empty($filterData['value'])) {
                //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' value:' . print_r($filterData['value'], true));
                try {
                    $filterData['value'] = Donator_Controller_Project::getInstance()->get($filterData['value'])->toArray();
                } catch (Tinebase_Exception_NotFound $nfe) {
                    if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " could not find and resolve timeaccount {$filterData['value']}");
                }
            }
        }*/
     return $result;
 }
Example #4
0
 /**
  * search for preferences
  * 
  * @param  Tinebase_Model_Filter_FilterGroup    $_filter
  * @param  Tinebase_Model_Pagination            $_pagination
  * @param  boolean                              $_onlyIds
  * @return Tinebase_Record_RecordSet|array of preferences / pref ids
  */
 public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Model_Pagination $_pagination = NULL, $_onlyIds = FALSE)
 {
     // make sure account is set in filter
     $userId = Tinebase_Core::getUser()->getId();
     if (!$_filter->isFilterSet('account')) {
         $accountFilter = $_filter->createFilter('account', 'equals', array('accountId' => $userId, 'accountType' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER));
         $_filter->addFilter($accountFilter);
     } else {
         // only admins can search for other users prefs
         $accountFilter = $_filter->getAccountFilter();
         $accountFilterValue = $accountFilter->getValue();
         if ($accountFilterValue['accountId'] != $userId && $accountFilterValue['accountType'] == Tinebase_Acl_Rights::ACCOUNT_TYPE_USER) {
             if (!Tinebase_Acl_Roles::getInstance()->hasRight($this->_application, Tinebase_Core::getUser()->getId(), Tinebase_Acl_Rights_Abstract::ADMIN)) {
                 return new Tinebase_Record_RecordSet('Tinebase_Model_Preference');
             }
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_filter->toArray(), TRUE));
     }
     $paging = new Tinebase_Model_Pagination(array('dir' => 'ASC', 'sort' => array('name')));
     $allPrefs = parent::search($_filter, $_pagination, $_onlyIds);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r(is_array($allPrefs) ? $allPrefs : $allPrefs->toArray(), TRUE));
     }
     if (!$_onlyIds) {
         $this->_addDefaultAndRemoveUndefinedPrefs($allPrefs, $_filter);
         // get single matching preferences for each different pref
         $result = $this->getMatchingPreferences($allPrefs);
     } else {
         $result = $allPrefs;
     }
     return $result;
 }
 /**
  * returns array with the filter settings of this filter group 
  *
  * @param  bool $_valueToJson resolve value for json api?
  * @return array
  */
 public function toArray($_valueToJson = false)
 {
     $result = parent::toArray($_valueToJson);
     foreach ($result as &$filterData) {
         if (isset($filterData['field']) && $filterData['field'] == 'id' && $_valueToJson == true && !empty($filterData['value']) && !is_array($filterData['value'])) {
             try {
                 $filterData['value'] = Timetracker_Controller_Timeaccount::getInstance()->get($filterData['value'])->toArray();
             } catch (Tinebase_Exception_NotFound $nfe) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                     Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . " could not find and resolve timeaccount {$filterData['value']}");
                 }
             }
         }
     }
     return $result;
 }