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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Incomplete.
|
|
|
|
*
|
|
|
|
* @todo add to tests
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-09 08:40:50 +02:00
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
class WithinRangeFilter extends SearchFilter {
|
|
|
|
|
|
|
|
private $min;
|
|
|
|
private $max;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setMin($min) {
|
2008-08-09 08:40:50 +02:00
|
|
|
$this->min = $min;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setMax($max) {
|
2008-08-09 08:40:50 +02:00
|
|
|
$this->max = $max;
|
|
|
|
}
|
|
|
|
|
2012-09-06 09:54:44 +02:00
|
|
|
protected function applyOne(DataQuery $query) {
|
2012-05-18 03:19:20 +02:00
|
|
|
$this->model = $query->applyRelation($this->relation);
|
2012-06-15 05:48:47 +02:00
|
|
|
return $query->where(sprintf(
|
2012-05-18 03:19:20 +02:00
|
|
|
"%s >= '%s' AND %s <= '%s'",
|
2008-10-05 21:20:35 +02:00
|
|
|
$this->getDbName(),
|
|
|
|
Convert::raw2sql($this->min),
|
|
|
|
$this->getDbName(),
|
|
|
|
Convert::raw2sql($this->max)
|
|
|
|
));
|
2008-08-09 08:40:50 +02:00
|
|
|
}
|
|
|
|
|
2012-09-06 09:54:44 +02:00
|
|
|
protected function excludeOne(DataQuery $query) {
|
|
|
|
$this->model = $query->applyRelation($this->relation);
|
|
|
|
return $query->where(sprintf(
|
|
|
|
"%s < '%s' OR %s > '%s'",
|
|
|
|
$this->getDbName(),
|
|
|
|
Convert::raw2sql($this->min),
|
|
|
|
$this->getDbName(),
|
|
|
|
Convert::raw2sql($this->max)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|