mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-05 17:21:16 +02:00
Namespace all templates Move difflib and BBCodeParser2 to thirdparty Remove deprecated API marked for removal in 4.0
101 lines
2.5 KiB
PHP
101 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\ORM\Filters;
|
|
|
|
use SilverStripe\ORM\DataQuery;
|
|
use SilverStripe\ORM\DB;
|
|
use InvalidArgumentException;
|
|
|
|
/**
|
|
* Matches textual content with a LIKE '%keyword%' construct.
|
|
*/
|
|
class PartialMatchFilter extends SearchFilter {
|
|
|
|
public function getSupportedModifiers()
|
|
{
|
|
return ['not', 'nocase', 'case'];
|
|
}
|
|
|
|
/**
|
|
* Apply the match filter to the given variable value
|
|
*
|
|
* @param string $value The raw value
|
|
* @return string
|
|
*/
|
|
protected function getMatchPattern($value) {
|
|
return "%$value%";
|
|
}
|
|
|
|
protected function applyOne(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$comparisonClause = DB::get_conn()->comparisonClause(
|
|
$this->getDbName(),
|
|
null,
|
|
false, // exact?
|
|
false, // negate?
|
|
$this->getCaseSensitive(),
|
|
true
|
|
);
|
|
return $query->where(array(
|
|
$comparisonClause => $this->getMatchPattern($this->getValue())
|
|
));
|
|
}
|
|
|
|
protected function applyMany(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$whereClause = array();
|
|
$comparisonClause = DB::get_conn()->comparisonClause(
|
|
$this->getDbName(),
|
|
null,
|
|
false, // exact?
|
|
false, // negate?
|
|
$this->getCaseSensitive(),
|
|
true
|
|
);
|
|
foreach($this->getValue() as $value) {
|
|
$whereClause[] = array($comparisonClause => $this->getMatchPattern($value));
|
|
}
|
|
return $query->whereAny($whereClause);
|
|
}
|
|
|
|
protected function excludeOne(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$comparisonClause = DB::get_conn()->comparisonClause(
|
|
$this->getDbName(),
|
|
null,
|
|
false, // exact?
|
|
true, // negate?
|
|
$this->getCaseSensitive(),
|
|
true
|
|
);
|
|
return $query->where(array(
|
|
$comparisonClause => $this->getMatchPattern($this->getValue())
|
|
));
|
|
}
|
|
|
|
protected function excludeMany(DataQuery $query) {
|
|
$this->model = $query->applyRelation($this->relation);
|
|
$values = $this->getValue();
|
|
$comparisonClause = DB::get_conn()->comparisonClause(
|
|
$this->getDbName(),
|
|
null,
|
|
false, // exact?
|
|
true, // negate?
|
|
$this->getCaseSensitive(),
|
|
true
|
|
);
|
|
$parameters = array();
|
|
foreach($values as $value) {
|
|
$parameters[] = $this->getMatchPattern($value);
|
|
}
|
|
// Since query connective is ambiguous, use AND explicitly here
|
|
$count = count($values);
|
|
$predicate = implode(' AND ', array_fill(0, $count, $comparisonClause));
|
|
return $query->where(array($predicate => $parameters));
|
|
}
|
|
|
|
public function isEmpty() {
|
|
return $this->getValue() === array() || $this->getValue() === null || $this->getValue() === '';
|
|
}
|
|
}
|