function commerce_backoffice_handler_filter_term_node_tid::query in Commerce Backoffice 7
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 views_handler_filter::query
File
- includes/
views/ handlers/ commerce_backoffice_handler_filter_term_node_tid.inc, line 190 - Definition of commerce_backoffice_handler_filter_term_node_tid.
Class
- commerce_backoffice_handler_filter_term_node_tid
- Filter by term id.
Code
function query() {
// If no filter values are present, then do nothing.
if (count($this->value) == 0) {
return;
}
elseif (count($this->value) == 1) {
// Somethis $this->value is an array with a single element so convert it.
if (is_array($this->value)) {
$this->value = current($this->value);
}
$operator = '=';
}
else {
$operator = 'IN';
}
// The normal use of ensure_my_table() here breaks Views.
// So instead we trick the filter into using the alias of the base table.
// See http://drupal.org/node/271833
// If a relationship is set, we must use the alias it provides.
if (!empty($this->relationship)) {
$this->table_alias = $this->relationship;
}
elseif (isset($this->query->table_queue[$this->query->base_table]['alias'])) {
$this->table_alias = $this->query->table_queue[$this->query->base_table]['alias'];
}
else {
return;
}
if (empty($this->options['per_vocabulary']) || $operator == '=') {
if (!is_array($this->value) && ($value_parts = explode('-', $this->value))) {
$tid = $value_parts[1];
}
else {
$tid = $this->value;
}
$subquery = db_select('taxonomy_index', 'tn');
$subquery
->addField('tn', 'nid');
$last = 'tn';
$subquery
->condition('tn.tid', $tid, $operator);
$this->query
->add_where($this->options['group'], "{$this->table_alias}.nid", $subquery, 'IN');
}
else {
$values = array();
foreach ($this->value as $value) {
$value_parts = explode('-', $value);
$values[$value_parts[0]][] = $value_parts[1];
}
foreach ($values as $vid => $tids) {
// Now build the subqueries.
$subquery = db_select('taxonomy_index', 'tn');
$subquery
->addField('tn', 'nid');
$last = 'tn';
$subquery
->innerJoin('taxonomy_term_data', 'td', 'td.tid = tn.tid');
$last = 'td';
$subquery
->condition('tn.tid', array_values($tids), $operator);
$subquery
->condition('td.vid', $vid);
$this->query
->add_where($this->options['group'], "{$this->table_alias}.nid", $subquery, 'IN');
}
}
}