FOF30\Model\DataModel\Filter\Date::between PHP Метод

between() публичный Метод

Perform a between limits match. When $include is true the condition tested is: $from <= VALUE <= $to When $include is false the condition tested is: $from < VALUE < $to
public between ( mixed $from, mixed $to, boolean $include = true ) : string
$from mixed The lowest value to compare to
$to mixed The higherst value to compare to
$include boolean Should we include the boundaries in the search?
Результат string The SQL where clause for this search
    public function between($from, $to, $include = true)
    {
        if ($this->isEmpty($from) || $this->isEmpty($to)) {
            return '';
        }
        $extra = '';
        if ($include) {
            $extra = '=';
        }
        $sql = '((' . $this->getFieldName() . ' >' . $extra . ' ' . $this->db->q($from) . ') AND ';
        $sql .= '(' . $this->getFieldName() . ' <' . $extra . ' ' . $this->db->q($to) . '))';
        return $sql;
    }

Usage Example

Пример #1
0
 /**
  * @group           DateFilter
  * @group           DateFilterBetween
  * @covers          FOF30\Model\DataModel\Filter\Date::between
  * @dataProvider    DateDataprovider::getTestBetween
  */
 public function testBetween($test, $check)
 {
     $msg = 'Date::between %s - Case: ' . $check['case'];
     $filter = new Date(\JFactory::getDbo(), (object) array('name' => 'test', 'type' => 'datetime'));
     $result = $filter->between($test['from'], $test['to'], $test['include']);
     $this->assertEquals($check['result'], $result, sprintf($msg, 'Failed to build the correct SQL query'));
 }