You are here

public function HistoryUserTimestamp::query in Views (for Drupal 7) 8.3

Same name in this branch
  1. 8.3 lib/Views/node/Plugin/views/filter/HistoryUserTimestamp.php \Views\node\Plugin\views\filter\HistoryUserTimestamp::query()
  2. 8.3 lib/Views/node/Plugin/views/field/HistoryUserTimestamp.php \Views\node\Plugin\views\field\HistoryUserTimestamp::query()

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides FilterPluginBase::query

File

lib/Views/node/Plugin/views/filter/HistoryUserTimestamp.php, line 58
Definition of Views\node\Plugin\views\filter\HistoryUserTimestamp.

Class

HistoryUserTimestamp
Filter for new content.

Namespace

Views\node\Plugin\views\filter

Code

public function query() {
  global $user;

  // This can only work if we're logged in.
  if (!$user || !$user->uid) {
    return;
  }

  // Don't filter if we're exposed and the checkbox isn't selected.
  if (!empty($this->options['exposed']) && empty($this->value)) {
    return;
  }

  // Hey, Drupal kills old history, so nodes that haven't been updated
  // since NODE_NEW_LIMIT are bzzzzzzzt outta here!
  $limit = REQUEST_TIME - NODE_NEW_LIMIT;
  $this
    ->ensureMyTable();
  $field = "{$this->tableAlias}.{$this->realField}";
  $node = $this->query
    ->ensure_table('node', $this->relationship);
  $clause = '';
  $clause2 = '';
  if (module_exists('comment')) {
    $ncs = $this->query
      ->ensure_table('node_comment_statistics', $this->relationship);
    $clause = "OR {$ncs}.last_comment_timestamp > (***CURRENT_TIME*** - {$limit})";
    $clause2 = "OR {$field} < {$ncs}.last_comment_timestamp";
  }

  // NULL means a history record doesn't exist. That's clearly new content.
  // Unless it's very very old content. Everything in the query is already
  // type safe cause none of it is coming from outside here.
  $this->query
    ->add_where_expression($this->options['group'], "({$field} IS NULL AND ({$node}.changed > (***CURRENT_TIME*** - {$limit}) {$clause})) OR {$field} < {$node}.changed {$clause2}");
}