mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-20 00:16:55 +02:00
6f0df9eb19
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@103388 467b73ca-7a2a-4603-9d3b-597d59a354a9
54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage search
|
|
*/
|
|
|
|
/**
|
|
* Checks if a value is in a given set.
|
|
* SQL syntax used: Column IN ('val1','val2')
|
|
*
|
|
* @todo Add negation (NOT IN)6
|
|
* @package sapphire
|
|
* @subpackage search
|
|
*/
|
|
class ExactMatchMultiFilter extends SearchFilter {
|
|
|
|
public function apply(SQLQuery $query) {
|
|
$query = $this->applyRelation($query);
|
|
|
|
// hack
|
|
// PREVIOUS $values = explode(',',$this->getValue());
|
|
$values = array();
|
|
if (is_string($this->getValue())) {
|
|
$values = explode(',',$this->getValue());
|
|
}
|
|
else {
|
|
foreach($this->getValue() as $v) {
|
|
$values[] = $v;
|
|
}
|
|
}
|
|
|
|
|
|
if(! $values) return false;
|
|
for($i = 0; $i < count($values); $i++) {
|
|
if(! is_numeric($values[$i])) {
|
|
// @todo Fix string replacement to only replace leading and tailing quotes
|
|
$values[$i] = str_replace("'", '', $values[$i]);
|
|
$values[$i] = Convert::raw2sql($values[$i]);
|
|
}
|
|
}
|
|
$SQL_valueStr = "'" . implode("','", $values) . "'";
|
|
|
|
return $query->where(sprintf(
|
|
"%s IN (%s)",
|
|
$this->getDbName(),
|
|
$SQL_valueStr
|
|
));
|
|
}
|
|
|
|
public function isEmpty() {
|
|
return $this->getValue() == null || $this->getValue() == '';
|
|
}
|
|
}
|
|
?>
|