This many to one helper object is used on both arguments and filters. More...
Public Member Functions | |
views_many_to_one_helper (&$handler) | |
options_form (&$form, &$form_state) | |
get_field () | |
Sometimes the handler might want us to use some kind of formula, so give it that option. | |
add_table ($join=NULL, $alias=NULL) | |
Add a table to the query. | |
get_join () | |
summary_join () | |
Provide the proper join for summary queries. | |
ensure_my_table () | |
Override ensure_my_table so we can control how this joins in. | |
placeholder () | |
Provides a unique placeholders for handlers. | |
add_filter () | |
Static Public Member Functions | |
static | option_definition (&$options) |
This many to one helper object is used on both arguments and filters.
Any handler that uses this can have the following possibly additional definition terms:
Definition at line 733 of file handlers.inc.
views_many_to_one_helper::add_table | ( | $ | join = NULL , |
|
$ | alias = NULL | |||
) |
Add a table to the query.
This is an advanced concept; not only does it add a new instance of the table, but it follows the relationship path all the way down to the relationship link point and adds *that* as a new relationship and then adds the table to the relationship, if necessary.
Definition at line 774 of file handlers.inc.
References views_get_table_join().
Referenced by ensure_my_table(), and summary_join().
{ // This is used for lookups in the many_to_one table. $field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field; if (empty($join)) { $join = $this->get_join(); } // See if there's a chain between us and the base relationship. If so, we need // to create a new relationship to use. $relationship = $this->handler->relationship; // Determine the primary table to seek if (empty($this->handler->query->relationships[$relationship])) { $base_table = $this->handler->query->base_table; } else { $base_table = $this->handler->query->relationships[$relationship]['base']; } // Cycle through the joins. This isn't as error-safe as the normal // ensure_path logic. Perhaps it should be. $r_join = clone $join; while ($r_join->left_table != $base_table) { $r_join = views_get_table_join($r_join->left_table, $base_table); } // If we found that there are tables in between, add the relationship. if ($r_join->table != $join->table) { $relationship = $this->handler->query->add_relationship($this->handler->table . '_' . $r_join->table, $r_join, $r_join->table, $this->handler->relationship); } // And now add our table, using the new relationship if one was used. $alias = $this->handler->query->add_table($this->handler->table, $relationship, $join, $alias); // Store what values are used by this table chain so that other chains can // automatically discard those values. if (empty($this->handler->view->many_to_one_tables[$field])) { $this->handler->view->many_to_one_tables[$field] = $this->handler->value; } else { $this->handler->view->many_to_one_tables[$field] = array_merge($this->handler->view->many_to_one_tables[$field], $this->handler->value); } return $alias; }
views_many_to_one_helper::ensure_my_table | ( | ) |
Override ensure_my_table so we can control how this joins in.
The operator actually has influence over joining.
Definition at line 865 of file handlers.inc.
References add_table().
{ if (!isset($this->handler->table_alias)) { // Case 1: Operator is an 'or' and we're not reducing duplicates. // We hence get the absolute simplest: $field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field; if ($this->handler->operator == 'or' && empty($this->handler->options['reduce_duplicates'])) { if (empty($this->handler->options['add_table']) && empty($this->handler->view->many_to_one_tables[$field])) { // query optimization, INNER joins are slightly faster, so use them // when we know we can. $join = $this->get_join(); if (isset($join)) { $join->type = 'INNER'; } $this->handler->table_alias = $this->handler->query->ensure_table($this->handler->table, $this->handler->relationship, $join); $this->handler->view->many_to_one_tables[$field] = $this->handler->value; } else { $join = $this->get_join(); $join->type = 'LEFT'; if (!empty($this->handler->view->many_to_one_tables[$field])) { foreach ($this->handler->view->many_to_one_tables[$field] as $value) { $join->extra = array( array( 'field' => $this->handler->real_field, 'operator' => '!=', 'value' => $value, 'numeric' => !empty($this->handler->definition['numeric']), ), ); } } $this->handler->table_alias = $this->add_table($join); } return $this->handler->table_alias; } // Case 2: it's an 'and' or an 'or'. // We do one join per selected value. if ($this->handler->operator != 'not') { // Clone the join for each table: $this->handler->table_aliases = array(); foreach ($this->handler->value as $value) { $join = $this->get_join(); if ($this->handler->operator == 'and') { $join->type = 'INNER'; } $join->extra = array( array( 'field' => $this->handler->real_field, 'value' => $value, 'numeric' => !empty($this->handler->definition['numeric']), ), ); // The table alias needs to be unique to this value across the // multiple times the filter or argument is called by the view. if (!isset($this->handler->view->many_to_one_aliases[$field][$value])) { if (!isset($this->handler->view->many_to_one_count[$this->handler->table])) { $this->handler->view->many_to_one_count[$this->handler->table] = 0; } $this->handler->view->many_to_one_aliases[$field][$value] = $this->handler->table . '_value_' . ($this->handler->view->many_to_one_count[$this->handler->table]++); } $alias = $this->handler->table_aliases[$value] = $this->add_table($join, $this->handler->view->many_to_one_aliases[$field][$value]); // and set table_alias to the first of these. if (empty($this->handler->table_alias)) { $this->handler->table_alias = $alias; } } } // Case 3: it's a 'not'. // We just do one join. We'll add a where clause during // the query phase to ensure that $table.$field IS NULL. else { $join = $this->get_join(); $join->type = 'LEFT'; $join->extra = array(); $join->extra_type = 'OR'; foreach ($this->handler->value as $value) { $join->extra[] = array( 'field' => $this->handler->real_field, 'value' => $value, 'numeric' => !empty($this->handler->definition['numeric']), ); } $this->handler->table_alias = $this->add_table($join); } } return $this->handler->table_alias; }
views_many_to_one_helper::get_field | ( | ) |
Sometimes the handler might want us to use some kind of formula, so give it that option.
If it wants us to do this, it must set $helper->formula = TRUE and implement handler->get_formula();
Definition at line 757 of file handlers.inc.
{ if (!empty($this->formula)) { return $this->handler->get_formula(); } else { return $this->handler->table_alias . '.' . $this->handler->real_field; } }
views_many_to_one_helper::placeholder | ( | ) |
Provides a unique placeholders for handlers.
Definition at line 962 of file handlers.inc.
{ return $this->handler->query->placeholder($this->handler->options['table'] . '_' . $this->handler->options['field']); }
views_many_to_one_helper::summary_join | ( | ) |
Provide the proper join for summary queries.
This is important in part because it will cooperate with other arguments if possible.
Definition at line 828 of file handlers.inc.
References add_table().
{ $field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field; $join = $this->get_join(); // shortcuts $options = $this->handler->options; $view = &$this->handler->view; $query = &$this->handler->query; if (!empty($options['require_value'])) { $join->type = 'INNER'; } if (empty($options['add_table']) || empty($view->many_to_one_tables[$field])) { return $query->ensure_table($this->handler->table, $this->handler->relationship, $join); } else { if (!empty($view->many_to_one_tables[$field])) { foreach ($view->many_to_one_tables[$field] as $value) { $join->extra = array( array( 'field' => $this->handler->real_field, 'operator' => '!=', 'value' => $value, 'numeric' => !empty($this->definition['numeric']), ), ); } } return $this->add_table($join); } }