mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-08 10:41:25 +02:00
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* @package framework
|
|
* @subpackage search
|
|
*/
|
|
|
|
/**
|
|
* Matches textual content with a LIKE '%keyword%' construct.
|
|
*
|
|
* @package framework
|
|
* @subpackage search
|
|
*/
|
|
class PartialMatchFilter extends SearchFilter {
|
|
|
|
protected function applyOne(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
|
$where = sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($this->getValue()));
|
|
|
|
return $query->where($where);
|
|
}
|
|
|
|
protected function applyMany(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$where = array();
|
|
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
|
foreach($this->getValue() as $value) {
|
|
$where[]= sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($value));
|
|
}
|
|
|
|
return $query->where(implode(' OR ', $where));
|
|
}
|
|
|
|
protected function excludeOne(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
|
$where = sprintf("%s NOT %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($this->getValue()));
|
|
|
|
return $query->where($where);
|
|
}
|
|
|
|
protected function excludeMany(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$where = array();
|
|
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
|
foreach($this->getValue() as $value) {
|
|
$where[]= sprintf("%s NOT %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($value));
|
|
}
|
|
|
|
return $query->where(implode(' AND ', $where));
|
|
}
|
|
|
|
public function isEmpty() {
|
|
return $this->getValue() === array() || $this->getValue() === null || $this->getValue() === '';
|
|
}
|
|
}
|