You are here

protected function AuditLogDate::opSimple in Audit Log 8.2

Overrides Date::opSimple

File

src/Plugin/views/filter/AuditLogDate.php, line 19

Class

AuditLogDate
Filter to handle dates stored as a timestamp.

Namespace

Drupal\audit_log\Plugin\views\filter

Code

protected function opSimple($field) {
  if (!empty($this->value['type']) && $this->value['type'] == 'offset') {
    $value = intval(strtotime($this->value['value'], 0));
    $value = '***CURRENT_TIME***' . sprintf('%+d', $value);
  }
  else {
    $tz = 'UTC';
    $dt = new \DateTime($this->value['value'], new \DateTimeZone($tz));
    $value = $dt
      ->getTimestamp();
  }

  // This is safe because we are manually scrubbing the value.
  // It is necessary to do it this way because $value is a formula
  // when using an offset.
  $expression = "{$field} {$this->operator} {$value}";
  $this->query
    ->addWhereExpression($this->options['group'], $expression);
}