function views_plugin_query_default::add_where

Same name in other branches
  1. 7.x-3.x plugins/views_plugin_query_default.inc \views_plugin_query_default::add_where()

Add a simple WHERE clause to the query. The caller is responsible for ensuring that all fields are fully qualified (TABLE.FIELD) and that the table already exists in the query.

Parameters

$group: The WHERE group to add these to; groups are used to create AND/OR sections. Groups cannot be nested. Use 0 as the default group. If the group does not yet exist it will be created as an AND group.

$clause: The actual clause to add. When adding a where clause it is important that all tables are addressed by the alias provided by add_table or ensure_table and that all fields are addressed by their alias wehn possible. Please use %d and %s for arguments.

...: A number of arguments as used in db_query(). May be many args or one array full of args.

File

plugins/views_plugin_query_default.inc, line 757

Class

views_plugin_query_default
Object used to create a SELECT query.

Code

function add_where($group, $clause) {
    $args = func_get_args();
    array_shift($args);
    // ditch $group
    array_shift($args);
    // ditch $clause
    // Expand an array of args if it came in.
    if (count($args) == 1 && is_array(reset($args))) {
        $args = current($args);
    }
    // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all
    // the default group.
    if (empty($group)) {
        $group = 0;
    }
    // Check for a group.
    if (!isset($this->where[$group])) {
        $this->set_where_group('AND', $group);
    }
    // Add the clause and the args.
    if (is_array($args)) {
        $this->where[$group]['clauses'][] = $clause;
        // we use array_values() here to prevent array_merge errors as keys from multiple
        // sources occasionally collide.
        $this->where[$group]['args'] = array_merge($this->where[$group]['args'], array_values($args));
    }
}