protected function DatexViewsDate::opBetween in Datex 8
Filters by operator between.
Parameters
object $field: The views field.
Overrides Date::opBetween
File
- src/
Plugin/ views/ filter/ DatexViewsDate.php, line 139
Class
- DatexViewsDate
- Filter to handle dates stored as a timestamp.
Namespace
Drupal\datex\Plugin\views\filterCode
protected function opBetween($field) {
$this->value['min'] = DatexArgHandlerTrait::translate($this->value['min']);
$this->value['max'] = DatexArgHandlerTrait::translate($this->value['max']);
$cal = datex_factory();
if (!$cal) {
parent::opBetween($field);
return;
}
// if type is offset translate value and delegate handling to parent class
if ($this->value['type'] == 'offset') {
parent::opBetween($field);
return;
}
if (!$cal
->parse($this->value['min'] . ' 00:00:00', 'Y-m-d H:i:s')) {
$this->query
->addWhereExpression($this->options['group'], '1 = 2');
return;
}
$a = $cal
->getTimestamp();
if (!$cal
->parse($this->value['max'] . ' 23:59:59', 'Y-m-d H:i:s')) {
$this->query
->addWhereExpression($this->options['group'], '1 = 2');
return;
}
$b = $cal
->getTimestamp();
$operator = strtoupper($this->operator);
$this->query
->addWhereExpression($this->options['group'], "{$field} {$operator} {$a} AND {$b}");
}