FOF30\Model\DataModel\Filter\Number::outside PHP Метод

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

Perform an outside limits match. When $include is true the condition tested is: (VALUE <= $from) || (VALUE >= $to) When $include is false the condition tested is: (VALUE < $from) || (VALUE > $to)
public outside ( mixed $from, mixed $to, boolean $include = false ) : string
$from mixed The lowest value of the excluded range
$to mixed The higherst value of the excluded range
$include boolean Should we include the boundaries in the search?
Результат string The SQL where clause for this search
    public function outside($from, $to, $include = false)
    {
        $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 . ') OR ';
        $sql .= '(' . $this->getFieldName() . ' >' . $extra . ' ' . $to . '))';
        return $sql;
    }

Usage Example

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