2008-08-11 01:29:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a value starts with one of the items of in a given set.
|
|
|
|
* SQL syntax used: Column IN ('val1','val2')
|
|
|
|
*
|
|
|
|
* @todo Add negation (NOT IN)6
|
2010-10-13 05:53:12 +02:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage search
|
2008-08-11 01:29:30 +02:00
|
|
|
*/
|
|
|
|
class StartsWithMultiFilter extends SearchFilter {
|
|
|
|
|
2011-03-21 09:37:55 +01:00
|
|
|
public function apply(DataQuery $query) {
|
|
|
|
$this->model = $query->applyRelation($this->relation);
|
2008-08-11 02:03:57 +02:00
|
|
|
$values = explode(',', $this->getValue());
|
2008-08-11 01:29:30 +02:00
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
foreach($values as $value) {
|
2008-10-05 21:20:35 +02:00
|
|
|
$matches[] = sprintf("%s LIKE '%s%%'",
|
|
|
|
$this->getDbName(),
|
|
|
|
Convert::raw2sql(str_replace("'", '', $value))
|
|
|
|
);
|
2008-08-11 01:29:30 +02:00
|
|
|
}
|
2008-08-11 02:03:57 +02:00
|
|
|
|
2011-04-05 13:01:57 +02:00
|
|
|
return $query->where(implode(" OR ", $matches));
|
2008-08-11 01:29:30 +02:00
|
|
|
}
|
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
public function isEmpty() {
|
|
|
|
return $this->getValue() == null || $this->getValue() == '';
|
|
|
|
}
|
2008-08-11 01:29:30 +02:00
|
|
|
}
|
|
|
|
?>
|