2008-08-09 08:40:50 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-09 08:40:50 +02:00
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Matches textual content with a substring match on a text fragment leading
|
|
|
|
* to the end of the string.
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* "abcdefg" => "defg" # true
|
|
|
|
* "abcdefg" => "abcd" # false
|
|
|
|
* </code>
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-09 08:40:50 +02:00
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
class EndsWithFilter extends SearchFilter {
|
2012-12-10 23:35:04 +01:00
|
|
|
|
|
|
|
public function setModifiers(array $modifiers) {
|
2012-09-20 09:26:05 +02:00
|
|
|
if(($extras = array_diff($modifiers, array('not', 'nocase', 'case'))) != array()) {
|
|
|
|
throw new InvalidArgumentException(
|
|
|
|
get_class($this) . ' does not accept ' . implode(', ', $extras) . ' as modifiers');
|
|
|
|
}
|
2012-12-10 23:35:04 +01:00
|
|
|
|
|
|
|
parent::setModifiers($modifiers);
|
2012-09-20 09:26:05 +02:00
|
|
|
}
|
2008-08-09 08:40:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies a match on the trailing characters of a field value.
|
|
|
|
*
|
2012-09-06 09:54:44 +02:00
|
|
|
* @return DataQuery
|
2008-08-09 08:40:50 +02:00
|
|
|
*/
|
2012-09-06 09:54:44 +02:00
|
|
|
protected function applyOne(DataQuery $query) {
|
2011-03-21 09:37:55 +01:00
|
|
|
$this->model = $query->applyRelation($this->relation);
|
2012-12-10 23:35:04 +01:00
|
|
|
$modifiers = $this->getModifiers();
|
|
|
|
$where = DB::getConn()->comparisonClause(
|
2012-03-14 16:05:28 +01:00
|
|
|
$this->getDbName(),
|
2012-12-10 23:35:04 +01:00
|
|
|
'%' . Convert::raw2sql($this->getValue()),
|
|
|
|
false, // exact?
|
|
|
|
false, // negate?
|
|
|
|
$this->getCaseSensitive()
|
|
|
|
);
|
|
|
|
return $query->where($where);
|
2008-08-09 08:40:50 +02:00
|
|
|
}
|
2012-09-06 09:54:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies a match on the trailing characters of a field value.
|
|
|
|
* Matches against one of the many values.
|
|
|
|
*
|
|
|
|
* @return DataQuery
|
|
|
|
*/
|
|
|
|
protected function applyMany(DataQuery $query) {
|
|
|
|
$this->model = $query->applyRelation($this->relation);
|
2012-12-10 23:35:04 +01:00
|
|
|
$modifiers = $this->getModifiers();
|
2012-09-06 09:54:44 +02:00
|
|
|
$connectives = array();
|
|
|
|
foreach($this->getValue() as $value) {
|
2012-12-10 23:35:04 +01:00
|
|
|
$connectives[] = DB::getConn()->comparisonClause(
|
2012-09-06 09:54:44 +02:00
|
|
|
$this->getDbName(),
|
2012-12-10 23:35:04 +01:00
|
|
|
'%' . Convert::raw2sql($value),
|
|
|
|
false, // exact?
|
|
|
|
false, // negate?
|
|
|
|
$this->getCaseSensitive()
|
2012-09-06 09:54:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$whereClause = implode(' OR ', $connectives);
|
|
|
|
return $query->where($whereClause);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Excludes a match on the trailing characters of a field value.
|
|
|
|
*
|
|
|
|
* @return DataQuery
|
|
|
|
*/
|
|
|
|
protected function excludeOne(DataQuery $query) {
|
|
|
|
$this->model = $query->applyRelation($this->relation);
|
2012-12-10 23:35:04 +01:00
|
|
|
$modifiers = $this->getModifiers();
|
|
|
|
$where = DB::getConn()->comparisonClause(
|
2012-09-06 09:54:44 +02:00
|
|
|
$this->getDbName(),
|
2012-12-10 23:35:04 +01:00
|
|
|
'%' . Convert::raw2sql($this->getValue()),
|
|
|
|
false, // exact?
|
|
|
|
true, // negate?
|
|
|
|
$this->getCaseSensitive()
|
|
|
|
);
|
|
|
|
return $query->where($where);
|
2012-09-06 09:54:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Excludes a match on the trailing characters of a field value.
|
|
|
|
* Excludes a field if it matches any of the values.
|
|
|
|
*
|
|
|
|
* @return DataQuery
|
|
|
|
*/
|
|
|
|
protected function excludeMany(DataQuery $query) {
|
|
|
|
$this->model = $query->applyRelation($this->relation);
|
2012-12-10 23:35:04 +01:00
|
|
|
$modifiers = $this->getModifiers();
|
2012-09-06 09:54:44 +02:00
|
|
|
$connectives = array();
|
|
|
|
foreach($this->getValue() as $value) {
|
2012-12-10 23:35:04 +01:00
|
|
|
$connectives[] = DB::getConn()->comparisonClause(
|
2012-09-06 09:54:44 +02:00
|
|
|
$this->getDbName(),
|
2012-12-10 23:35:04 +01:00
|
|
|
'%' . Convert::raw2sql($value),
|
|
|
|
false, // exact?
|
|
|
|
true, // negate?
|
|
|
|
$this->getCaseSensitive()
|
2012-09-06 09:54:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$whereClause = implode(' AND ', $connectives);
|
|
|
|
return $query->where($whereClause);
|
|
|
|
}
|
2008-08-09 08:40:50 +02:00
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
public function isEmpty() {
|
2012-09-06 09:54:44 +02:00
|
|
|
return $this->getValue() === array() || $this->getValue() === null || $this->getValue() === '';
|
2008-08-11 02:03:57 +02:00
|
|
|
}
|
2008-08-09 08:40:50 +02:00
|
|
|
}
|