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
|
|
|
|
*/
|
|
|
|
class StartsWithMultiFilter extends SearchFilter {
|
|
|
|
|
|
|
|
public function apply(SQLQuery $query) {
|
2008-08-11 02:03:57 +02:00
|
|
|
$query = $this->applyRelation($query);
|
|
|
|
$values = explode(',', $this->getValue());
|
2008-08-11 01:29:30 +02:00
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
foreach($values as $value) {
|
|
|
|
$SQL_value = Convert::raw2sql(str_replace("'", '', $value));
|
|
|
|
$matches[] = "{$this->getDbName()} LIKE '$SQL_value%'";
|
2008-08-11 01:29:30 +02:00
|
|
|
}
|
2008-08-11 02:03: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
|
|
|
}
|
|
|
|
?>
|