示例#1
0
 private function prepareFilter($filter)
 {
     $decodedFilter = is_array($_filter) || strlen($_filter) == 40 ? $_filter : Zend_Json::decode($_filter);
     if (is_array($decodedFilter)) {
         $filter = new Billing_Model_ReceiptFilter(array());
         $filter->setFromArrayInUsersTimezone($decodedFilter);
     } else {
         if (!empty($decodedFilter) && strlen($decodedFilter) == 40) {
             $filter = Tinebase_PersistentFilter::getFilterById($decodedFilter);
         } else {
             if (!$filter instanceof Tinebase_Model_Filter_FilterGroup) {
                 // filter is empty
                 $filter = new Billing_Model_ReceiptFilter(array());
             }
         }
     }
     return $filter;
 }
 /**
  * decodes the filter string
  *
  * @param string|array $_filter
  * @param string $_filterModel the class name of the filter model to use
  * @param boolean $_throwExceptionIfEmpty
  * @return Tinebase_Model_Filter_FilterGroup
  */
 protected function _decodeFilter($_filter, $_filterModel, $_throwExceptionIfEmpty = FALSE)
 {
     $filterModel = $this->_getPluginForFilterModel($_filterModel);
     $decodedFilter = is_array($_filter) || strlen($_filter) == 40 ? $_filter : Zend_Json::decode($_filter);
     if (is_array($decodedFilter)) {
         $filter = new $filterModel(array());
         $filter->setFromArrayInUsersTimezone($decodedFilter);
     } else {
         if (!empty($decodedFilter) && strlen($decodedFilter) == 40) {
             $filter = Tinebase_PersistentFilter::getFilterById($decodedFilter);
         } else {
             if ($_throwExceptionIfEmpty) {
                 throw new Tinebase_Exception_InvalidArgument('Filter must not be empty!');
             } else {
                 $filter = new $filterModel(array());
             }
         }
     }
     return $filter;
 }
 /**
     
     /**
 * return (outer) contentfilter array
 * 
 * @param  int $_filterType
 * @return Tinebase_Model_Filter_FilterGroup
 */
 protected function _getContentFilter($_filterType)
 {
     $filter = new $this->_contentFilterClass();
     try {
         $persistentFilterId = $this->_device->{$this->_filterProperty};
         if ($persistentFilterId) {
             $filter = Tinebase_PersistentFilter::getFilterById($persistentFilterId);
         }
     } catch (Tinebase_Exception_NotFound $tenf) {
         // filter got deleted already
     }
     return $filter;
 }
 /**
  * testCheckSameFilterNameInDifferentApplications
  */
 public function testCheckSameFilterNameInDifferentApplications()
 {
     $savedFilter1 = $this->testSaveFilter();
     $filterData2 = self::getPersistentFilterData();
     $filterData2['application_id'] = Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId();
     $filterData2['model'] = 'Addressbook_Model_ContactFilter';
     $filterData2['filters'] = array(array('field' => 'query', 'operator' => 'contains', 'value' => 'test'));
     $savedFilter2 = $this->_uit->savePersistentFilter($filterData2);
     foreach (array('model', 'filters', 'application_id') as $fieldToTest) {
         $this->assertNotEquals($savedFilter1[$fieldToTest], $savedFilter2[$fieldToTest]);
     }
     $this->assertEquals($savedFilter1['name'], $savedFilter2['name']);
     $filter1 = Tinebase_PersistentFilter::getFilterById($savedFilter1['id']);
     $filter2 = Tinebase_PersistentFilter::getFilterById($savedFilter2['id']);
     $this->assertEquals($savedFilter1['model'], get_class($filter1));
     $this->assertEquals($savedFilter2['model'], get_class($filter2));
 }