Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(TB CustomFieldFilter) apply foreignId filter changes for cf filte…
Browse files Browse the repository at this point in the history
…rs too

Change-Id: Ia26930a1158e9f348d6195af5cdd223fb2b5e41d
Reviewed-on: http://gerrit.tine20.com/customers/19065
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
  • Loading branch information
paulmhh committed Feb 9, 2021
1 parent 87603cb commit 0232ff2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
36 changes: 32 additions & 4 deletions tine20/Tinebase/Model/Filter/CustomField.php
Expand Up @@ -93,6 +93,7 @@ class Tinebase_Model_Filter_CustomField extends Tinebase_Model_Filter_Abstract
*/
protected $_subFilterController = null;

protected $_passThroughFilter = null;

/**
* get a new single filter action
Expand Down Expand Up @@ -155,10 +156,19 @@ public function __construct($_fieldOrData, $_operator = NULL, $_value = NULL, ar
case 'record':
if (is_array($_fieldOrData['value']['value'])) {
$modelName = Tinebase_CustomField::getModelNameFromDefinition($this->_cfRecord->definition);
$this->_subFilterController = Tinebase_Core::getApplicationInstance($modelName);
$this->_subFilter = Tinebase_Model_Filter_FilterGroup::getFilterForModel($modelName);
$filterClass = null;
$this->_operators = ['AND', 'OR', 'notDefinedBy:AND', 'notDefinedBy:OR'];
$passThroughData = $_fieldOrData;
$passThroughData['field'] = 'value';
$passThroughData['value'] = $passThroughData['value']['value'];
$filterGroup = get_class(Tinebase_Model_Filter_FilterGroup::getFilterForModel($modelName));
if ($filterGroup === Tinebase_Model_Filter_FilterGroup::class) {
$filterGroup = $modelName;
}
$passThroughData['options'] = [
'tablename' => $this->_correlationName,
'controller' => get_class(Tinebase_Core::getApplicationInstance($modelName)),
'filtergroup' => $filterGroup,
];
$this->_passThroughFilter = new Tinebase_Model_Filter_ForeignId($passThroughData);
} else {
$filterClass = Tinebase_Model_Filter_Id::class;
}
Expand All @@ -185,6 +195,21 @@ public function __construct($_fieldOrData, $_operator = NULL, $_value = NULL, ar

parent::__construct($_fieldOrData, $_operator, $_value, $_options);
}

/**
* sets operator
*
* @param string $_operator
* @throws Tinebase_Exception_UnexpectedValue
*/
public function setOperator($_operator)
{
if (null !== $this->_passThroughFilter) {
$this->_operator = $_operator;
} else {
parent::setOperator($_operator);
}
}

/**
* set options
Expand Down Expand Up @@ -276,6 +301,9 @@ public function appendFilterSql($_select, $_backend)
}
}
}
if (null !== $this->_passThroughFilter) {
$this->_passThroughFilter->appendFilterSql($_select, $_backend);
}
}

/**
Expand Down
13 changes: 10 additions & 3 deletions tine20/Tinebase/Model/Filter/ForeignId.php
Expand Up @@ -68,14 +68,21 @@ public function appendFilterSql($_select, $_backend)
if ($this->_valueIsNull) {
$_select->where($this->_getQuotedFieldName($_backend) . ' IS NOT NULL');
} elseif (!empty($this->_foreignIds)) {
$_select->where($this->_getQuotedFieldName($_backend) . ' NOT IN (?)', $this->_foreignIds);
$groupSelect = new Tinebase_Backend_Sql_Filter_GroupSelect($_select);
$valueIdentifier = $this->_getQuotedFieldName($_backend);
$groupSelect->orWhere($valueIdentifier . ' IS NULL');
$groupSelect->orWhere($valueIdentifier . ' NOT IN (?)', $this->_foreignIds);
$groupSelect->appendWhere(Zend_Db_Select::SQL_OR);
}
} else {
if (!$this->_valueIsNull && empty($this->_foreignIds)) {
$_select->where('1 = 0');
} else {
$_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)',
empty($this->_foreignIds) ? new Zend_Db_Expr('NULL') : $this->_foreignIds);
if (empty($this->_foreignIds)) {
$_select->where($this->_getQuotedFieldName($_backend) . ' IS NULL');
} else {
$_select->where($this->_getQuotedFieldName($_backend) . ' IN (?)', $this->_foreignIds);
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion tine20/Tinebase/Model/Filter/ForeignRecord.php
Expand Up @@ -169,11 +169,15 @@ protected function _removePrefixesFromFilterValue(&$value)
*/
protected function _setFilterGroup()
{
$options = $this->_options;
if (isset($options['tablename'])) {
unset($options['tablename']);
}
$this->_filterGroup = Tinebase_Model_Filter_FilterGroup::getFilterForModel(
$this->_options['filtergroup'],
$this->_value,
$this->_conditionSubFilter,
$this->_options
$options
);
}

Expand Down

0 comments on commit 0232ff2

Please sign in to comment.