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);
|
2013-06-21 00:32:08 +02:00
|
|
|
$predicate = sprintf('%1$s >= ? AND %1$s <= ?', $this->getDbName());
|
|
|
|
return $query->where(array(
|
|
|
|
$predicate => array(
|
|
|
|
$this->min,
|
|
|
|
$this->max
|
|
|
|
)
|
2008-10-05 21:20:35 +02:00
|
|
|
));
|
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);
|
2013-06-21 00:32:08 +02:00
|
|
|
$predicate = sprintf('%1$s < ? OR %1$s > ?', $this->getDbName());
|
|
|
|
return $query->where(array(
|
|
|
|
$predicate => array(
|
|
|
|
$this->min,
|
|
|
|
$this->max
|
|
|
|
)
|
2012-09-06 09:54:44 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|