/** * Does the value get filtered? * * @param array $row * @throws \Exception * @return boolean */ public function applyFilter(array $row) { $wasTrueOneTime = false; $isApply = false; foreach ($this->getFilter()->getValues() as $filterValue) { $filter = $this->getFilter(); $col = $filter->getColumn(); $value = $row[$col->getUniqueId()]; $value = $col->getType()->getFilterValue($value); if ($filter->getOperator() == DatagridFilter::BETWEEN) { //BETWEEN have to be tested in one call $isApply = DatagridFilter::isApply($value, $this->getFilter()->getValues(), $filter->getOperator()); return $isApply; } else { $isApply = DatagridFilter::isApply($value, $filterValue, $filter->getOperator()); } if (true === $isApply) { $wasTrueOneTime = true; } switch ($filter->getOperator()) { case DatagridFilter::NOT_LIKE: case DatagridFilter::NOT_LIKE_LEFT: case DatagridFilter::NOT_LIKE_RIGHT: case DatagridFilter::NOT_EQUAL: case DatagridFilter::NOT_IN: if (false === $isApply) { // normally one "match" is okay -> so it's applied // but e.g. NOT_LIKE is not allowed to match so even if the othere rules are true // it has to fail! return false; } break; } } if (false === $isApply && true === $wasTrueOneTime) { return true; } return $isApply; }
public function testIsApplyInvalidArgumentException() { $filter = new Filter(); $this->setExpectedException('\\InvalidArgumentException'); $filter->isApply(123, 100, 'UndefinedFilter'); }
/** * Display this action on this row? * * @param array $row * @return boolean */ public function isDisplayed(array $row) { if ($this->hasShowOnValues() === false) { return true; } $isDisplayed = false; foreach ($this->getShowOnValues() as $rule) { $value = ''; if (isset($row[$rule['column']->getUniqueId()])) { $value = $row[$rule['column']->getUniqueId()]; } if ($rule['value'] instanceof AbstractColumn) { if (isset($row[$rule['value']->getUniqueId()])) { $ruleValue = $row[$rule['value']->getUniqueId()]; } else { $ruleValue = ''; } } else { $ruleValue = $rule['value']; } $isDisplayedMatch = Filter::isApply($value, $ruleValue, $rule['comparison']); if ($this->getShowOnValueOperator() == 'OR' && true === $isDisplayedMatch) { // For OR one match is enough return true; } elseif ($this->getShowOnValueOperator() == 'AND' && false === $isDisplayedMatch) { return false; } else { $isDisplayed = $isDisplayedMatch; } } return $isDisplayed; }