function nat_handler_argument_term_node_tid_depth::query in Node Auto Term [NAT] 7
Same name and namespace in other branches
- 6.2 includes/nat_handler_argument_term_node_tid_depth.inc \nat_handler_argument_term_node_tid_depth::query()
- 6 includes/nat_handler_argument_term_node_tid_depth.inc \nat_handler_argument_term_node_tid_depth::query()
- 7.2 includes/nat_handler_argument_term_node_tid_depth.inc \nat_handler_argument_term_node_tid_depth::query()
Set up the query for this argument.
The argument sent may be found at $this->argument.
Parameters
bool $group_by: Whether the query uses a group-by.
Overrides views_handler_argument::query
File
- includes/
nat_handler_argument_term_node_tid_depth.inc, line 74 - NAT (Node Auto Term) nid views argument with depth handler.
Class
- nat_handler_argument_term_node_tid_depth
- Argument handler for NAT terms over NAT nid with depth.
Code
function query() {
$this
->ensure_my_table();
if (!empty($this->options['break_phrase'])) {
$tids = new stdClass();
$tids->value = $this->argument;
$tids = views_break_phrase($this->argument, $tids);
if ($tids->value == -1) {
return FALSE;
}
if (count($tids->value) > 1) {
$placeholder = " IN (" . implode(', ', array_fill(0, sizeof($tids->value), '%d')) . ")";
}
else {
$placeholder = " = %d";
}
foreach ($tids->value as $tid) {
$nat_tid = nat_get_term($tid);
$nat_tids[] = $nat_tid->tid;
}
$tids = $nat_tids;
}
else {
$placeholder = "= %d";
$tids = array(
$this->argument,
);
$nat_tid = nat_get_term($this->argument);
$tids = array(
$nat_tid->tid,
);
}
$subquery = "\n SELECT tn.vid FROM {taxonomy_term_data} tn\n";
$where = " WHERE tn.tid {$placeholder}\n";
$args = $tids;
$last = "tn";
if ($this->options['depth'] > 0) {
$subquery .= " LEFT JOIN {taxonomy_term_hierarchy} th ON th.tid = tn.tid\n";
$last = "th";
foreach (range(1, abs($this->options['depth'])) as $count) {
$subquery .= " LEFT JOIN {taxonomy_term_hierarchy} th{$count} ON {$last}.parent = th{$count}.tid\n";
$where .= " OR th{$count}.tid {$placeholder}\n";
$args = array_merge($args, $tids);
$last = "th{$count}";
}
}
elseif ($this->options['depth'] < 0) {
foreach (range(1, abs($this->options['depth'])) as $count) {
$subquery .= " LEFT JOIN {taxonomy_term_hierarchy} th{$count} ON {$last}.tid = th{$count}.parent\n";
$where .= " OR th{$count}.tid {$placeholder}\n";
$args = array_merge($args, $tids);
$last = "th{$count}";
}
}
$this->query
->add_where(0, "{$this->table_alias}.{$this->real_field} IN ({$subquery}{$where} )", $args);
}