function views_plugin_query_default::add_having
Same name in other branches
- 7.x-3.x plugins/views_plugin_query_default.inc \views_plugin_query_default::add_having()
Add a simple HAVING clause to the query. The caller is responsible for ensuring that all fields are fully qualified (TABLE.FIELD) and that the table and an appropriate GROUP BY already exist in the query.
Parameters
$group: The HAVING 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 having 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 805
Class
- views_plugin_query_default
- Object used to create a SELECT query.
Code
function add_having($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->having[$group])) {
$this->set_where_group('AND', $group, 'having');
}
// Add the clause and the args.
if (is_array($args)) {
$this->having[$group]['clauses'][] = $clause;
$this->having[$group]['args'] = array_merge($this->having[$group]['args'], array_values($args));
}
}