FOF30\Model\DataModel\Filter\Date::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)
    {
        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           DateFilterOutside
  * @covers          FOF30\Model\DataModel\Filter\Date::outside
  * @dataProvider    DateDataprovider::getTestOutside
  */
 public function testOutside($test, $check)
 {
     $msg = 'Date::outside %s - Case: ' . $check['case'];
     $filter = new Date(\JFactory::getDbo(), (object) array('name' => 'test', 'type' => 'datetime'));
     $result = $filter->outside($test['from'], $test['to'], $test['include']);
     $this->assertEquals($check['result'], $result, sprintf($msg, 'Failed to build the correct SQL query'));
 }