mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-26 23:36:03 +03:00
Handle custom blank autofilter rule in show/hide
This commit is contained in:
parent
2f4620c3f9
commit
5ed20761c6
@ -352,14 +352,18 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
*/
|
*/
|
||||||
private static function _filterTestInCustomDataSet($cellValue,$ruleSet)
|
private static function _filterTestInCustomDataSet($cellValue,$ruleSet)
|
||||||
{
|
{
|
||||||
// Blank cells are always ignored, so return a FALSE
|
var_dump($ruleSet);
|
||||||
// TODO a rule of notEqual ' ' overrides this, unsure how to handle it at this point
|
|
||||||
if (($cellValue == '') || ($cellValue === NULL)) {
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
$dataSet = $ruleSet['filterRules'];
|
$dataSet = $ruleSet['filterRules'];
|
||||||
$join = $ruleSet['join'];
|
$join = $ruleSet['join'];
|
||||||
|
$customRuleForBlanks = isset($ruleSet['customRuleForBlanks']) ? $ruleSet['customRuleForBlanks'] : FALSE;
|
||||||
|
|
||||||
|
if (!$customRuleForBlanks) {
|
||||||
|
// Blank cells are always ignored, so return a FALSE
|
||||||
|
if (($cellValue == '') || ($cellValue === NULL)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
$returnVal = ($join == PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND);
|
$returnVal = ($join == PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND);
|
||||||
foreach($dataSet as $rule) {
|
foreach($dataSet as $rule) {
|
||||||
if (is_numeric($rule['value'])) {
|
if (is_numeric($rule['value'])) {
|
||||||
@ -384,6 +388,18 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
$retVal = ($cellValue <= $rule['value']);
|
$retVal = ($cellValue <= $rule['value']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} elseif($rule['value'] == '') {
|
||||||
|
switch ($rule['operator']) {
|
||||||
|
case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL :
|
||||||
|
$retVal = (($cellValue == '') || ($cellValue === NULL));
|
||||||
|
break;
|
||||||
|
case PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_NOTEQUAL :
|
||||||
|
$retVal = (($cellValue != '') && ($cellValue !== NULL));
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
$retVal = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// String values are always tested for equality, factoring in for wildcards (hence a regexp test)
|
// String values are always tested for equality, factoring in for wildcards (hence a regexp test)
|
||||||
$retVal = preg_match('/^'.$rule['value'].'$/i',$cellValue);
|
$retVal = preg_match('/^'.$rule['value'].'$/i',$cellValue);
|
||||||
@ -655,6 +671,7 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER :
|
case PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER :
|
||||||
|
$customRuleForBlanks = FALSE;
|
||||||
$ruleValues = array();
|
$ruleValues = array();
|
||||||
// Build a list of the filter value selections
|
// Build a list of the filter value selections
|
||||||
foreach($rules as $rule) {
|
foreach($rules as $rule) {
|
||||||
@ -664,6 +681,10 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
// Convert to a regexp allowing for regexp reserved characters, wildcards and escaped wildcards
|
// Convert to a regexp allowing for regexp reserved characters, wildcards and escaped wildcards
|
||||||
$ruleValue = preg_quote($ruleValue);
|
$ruleValue = preg_quote($ruleValue);
|
||||||
$ruleValue = str_replace(self::$_fromReplace,self::$_toReplace,$ruleValue);
|
$ruleValue = str_replace(self::$_fromReplace,self::$_toReplace,$ruleValue);
|
||||||
|
if (trim($ruleValue) == '') {
|
||||||
|
$customRuleForBlanks = TRUE;
|
||||||
|
$ruleValue = trim($ruleValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$ruleValues[] = array( 'operator' => $rule->getOperator(),
|
$ruleValues[] = array( 'operator' => $rule->getOperator(),
|
||||||
'value' => $ruleValue
|
'value' => $ruleValue
|
||||||
@ -673,7 +694,8 @@ class PHPExcel_Worksheet_AutoFilter
|
|||||||
$columnFilterTests[$columnID] = array(
|
$columnFilterTests[$columnID] = array(
|
||||||
'method' => '_filterTestInCustomDataSet',
|
'method' => '_filterTestInCustomDataSet',
|
||||||
'arguments' => array( 'filterRules' => $ruleValues,
|
'arguments' => array( 'filterRules' => $ruleValues,
|
||||||
'join' => $join
|
'join' => $join,
|
||||||
|
'customRuleForBlanks' => $customRuleForBlanks
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user