public function revisioning_handler_filter_revision_latest::query in Revisioning 7
Same name and namespace in other branches
- 8 views/revisioning_handler_filter_revision_latest.inc \revisioning_handler_filter_revision_latest::query()
- 6.3 views/revisioning_handler_filter_revision_latest.inc \revisioning_handler_filter_revision_latest::query()
Override the query, in particular the WHERE clause.
Overrides views_handler_filter_boolean_operator::query
File
- views/
revisioning_handler_filter_revision_latest.inc, line 52 - Views filter to display in a 'Content revisions' view only published revisions. Does not work in a standard 'Content' view.
Class
- revisioning_handler_filter_revision_latest
- @file Views filter to display in a 'Content revisions' view only published revisions. Does not work in a standard 'Content' view.
Code
public function query() {
$revisions_table = $this
->ensure_my_table();
$node_table = $this->query
->ensure_table('node');
// If we are using a relationship we need to try again because the alias
// is not going to be node!
if (!$node_table) {
$node_table = $this->query
->ensure_table('node_' . $revisions_table);
}
if (!$node_table) {
// Final desperate guess ...
$node_table = 'node';
}
// The subquery selects the maximum revision ID (vid) for a given node ID
// (nid). This is guaranteed to be the latest revision, because vids are
// assigned chronologically.
$max_vid_subquery = "SELECT MAX(vid) FROM {$revisions_table} WHERE {$revisions_table}.nid = {$node_table}.nid";
$where_clause = "{$revisions_table}.vid = ({$max_vid_subquery})";
$this->query
->add_where_expression($this->options['group'], $where_clause);
}