2008-08-06 05:28:25 +02:00
|
|
|
<?php
|
2008-08-09 08:40:50 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-09 08:40:50 +02:00
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
|
2008-08-06 05:28:25 +02:00
|
|
|
/**
|
|
|
|
* Matches textual content with a LIKE '%keyword%' construct.
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-06 05:28:25 +02:00
|
|
|
* @subpackage search
|
|
|
|
*/
|
2008-08-09 05:54:55 +02:00
|
|
|
class PartialMatchFilter extends SearchFilter {
|
2008-08-06 05:28:25 +02:00
|
|
|
|
2011-03-21 09:37:55 +01:00
|
|
|
public function apply(DataQuery $query) {
|
|
|
|
$this->model = $query->applyRelation($this->relation);
|
2012-02-15 11:42:29 +01:00
|
|
|
$where = array();
|
2012-03-14 16:05:28 +01:00
|
|
|
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
2012-02-15 11:42:29 +01:00
|
|
|
if(is_array($this->getValue())) {
|
|
|
|
foreach($this->getValue() as $value) {
|
2012-03-14 16:05:28 +01:00
|
|
|
$where[]= sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($value));
|
2012-02-15 11:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2012-03-14 16:05:28 +01:00
|
|
|
$where[] = sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($this->getValue()));
|
2012-02-15 11:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $query->where(implode(' OR ', $where));
|
2008-08-09 06:06:52 +02:00
|
|
|
}
|
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
public function isEmpty() {
|
|
|
|
return $this->getValue() == null || $this->getValue() == '';
|
|
|
|
}
|
2008-08-06 05:28:25 +02:00
|
|
|
}
|