public function farm_log_handler_relationship_asset::query in farmOS 7
Called to implement a relationship in a query.
Overrides views_handler_relationship::query
File
- modules/
farm/ farm_log/ views/ handlers/ farm_log_handler_relationship_asset.inc, line 67 - Farm log location relationship handler.
Class
- farm_log_handler_relationship_asset
- Farm log asset relationship handler.
Code
public function query() {
// Figure out what base table this relationship brings to the party.
$table_data = views_fetch_data($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
$this
->ensure_my_table();
// Build a sub-query that will be used in the join to load the latest
// movement log of a given asset.
$asset_id_field = $this->table_alias . '.id';
$done = !empty($this->options['done']) ? TRUE : FALSE;
$future = !empty($this->options['future']) ? TRUE : FALSE;
if ($future) {
$time = 0;
}
else {
$time = REQUEST_TIME;
}
$query = $this
->build_query($asset_id_field, $time, $done);
// Build the join definition.
$def = $this->definition;
$def['table'] = $this->definition['base'];
$def['field'] = $base_field;
$def['left_table'] = $this->table_alias;
$def['left_field'] = $this->real_field;
$def['left_query'] = $query;
if (!empty($this->options['required'])) {
$def['type'] = 'INNER';
}
if (!empty($this->definition['extra'])) {
$def['extra'] = $this->definition['extra'];
}
// Create the join as an instance of the views_join_subquery class.
$join = new views_join_subquery();
$join->definition = $def;
$join->options = $this->options;
$join
->construct();
$join->adjusted = TRUE;
// Use a short alias for this.
$alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query
->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
// Add access tags if the base table provide it.
if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
$access_tag = $table_data['table']['base']['access query tag'];
$this->query
->add_tag($access_tag);
}
}