You are here

function revisioning_handler_filter_revision_latest::query in Revisioning 6.3

Same name and namespace in other branches
  1. 8 views/revisioning_handler_filter_revision_latest.inc \revisioning_handler_filter_revision_latest::query()
  2. 7 views/revisioning_handler_filter_revision_latest.inc \revisioning_handler_filter_revision_latest::query()

Override the query, in particular the WHERE clause.

File

views/revisioning_handler_filter_revision_latest.inc, line 12
Views filter override to filter on revision recency, i.e. whether this is the latest revision of a node or not.

Class

revisioning_handler_filter_revision_latest
@file Views filter override to filter on revision recency, i.e. whether this is the latest revision of a node or not.

Code

function query() {
  $revisions_table = $this
    ->ensure_my_table();
  $node_table = $this->query
    ->ensure_table('node');
  $max_vid_subquery = "SELECT MAX(vid) FROM {" . $revisions_table . "} WHERE {$revisions_table}.nid={$node_table}.nid";

  // The subquery selects the maximum vid for a given nid
  // This is guaranteed to be the latest revision, because vids are assigned
  // chronologically.
  $where_clause = $this->value == 1 ? "{$revisions_table}.vid =({$max_vid_subquery})" : "{$revisions_table}.vid!=({$max_vid_subquery})";
  $this->query
    ->add_where($this->options['group'], $where_clause);
}