FOF30\Model\DataModel\Filter\Number::between PHP Méthode

between() public méthode

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?
Résultat string The SQL where clause for this search
    public function between($from, $to, $include = true)
    {
        $from = (double) $from;
        $to = (double) $to;
        if ($this->isEmpty($from) || $this->isEmpty($to)) {
            return '';
        }
        $extra = '';
        if ($include) {
            $extra = '=';
        }
        $from = $this->sanitiseValue($from);
        $to = $this->sanitiseValue($to);
        $sql = '((' . $this->getFieldName() . ' >' . $extra . ' ' . $from . ') AND ';
        $sql .= '(' . $this->getFieldName() . ' <' . $extra . ' ' . $to . '))';
        return $sql;
    }

Usage Example

Exemple #1
0
 /**
  * @group           NumberFilter
  * @group           NumberFilterBetween
  * @covers          FOF30\Model\DataModel\Filter\Number::between
  * @dataProvider    NumberDataprovider::getTestBetween
  */
 public function testBetween($test, $check)
 {
     $msg = 'Number::between %s - Case: ' . $check['case'];
     $filter = new Number(\JFactory::getDbo(), (object) array('name' => 'test', 'type' => 'int (10)'));
     $result = $filter->between($test['from'], $test['to'], $test['inclusive']);
     $this->assertEquals($check['result'], $result, sprintf($msg, 'Failed to return the correct SQL'));
 }