function quotes_block_where_sql in Quotes 6
Same name and namespace in other branches
- 5 quotes.module \quotes_block_where_sql()
- 7 quotes.module \quotes_block_where_sql()
Returns the SQL where text necessary for the provided filter criteria.
Parameters
$filters: The array specifying filter criteria using the keys nid_filter, rid_filter, uid_filter, and tid_filter.
$aliases: The array specifying the aliases used for the tables that are being joined in the query. Keys are the table names node, users_roles, users, and term_node.
Return value
A string containing the SQL where text necessary for the provided criteria.
1 call to quotes_block_where_sql()
- quotes_get_quote in ./
quotes.module - Returns the node ID for either a random quote or the most recent quote based on the provided filter criteria.
File
- ./
quotes.module, line 1380 - The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.
Code
function quotes_block_where_sql($filters = array()) {
$aliases = array(
'node' => 'n',
'users_roles' => 'r',
'users' => 'u',
'term_node' => 'tn',
);
$where = array();
if ($filters['nid_filter']) {
$f = $filters['nid_filter'];
$a = $aliases['node'];
$where[] = " {$a}.nid IN ({$f}) ";
}
if ($filters['aid_filter'] && $filters['aid_filter'] != 'none') {
$f = $filters['aid_filter'];
$where[] = " (q.aid IN ({$f})) ";
}
if ($filters['rid_filter'] && $filters['rid_filter'] != 'none') {
$f = $filters['rid_filter'];
$ar = $aliases['users_roles'];
$an = $aliases['node'];
$where[] = sprintf(" ({$ar}.rid IN ({$f}) OR (%d IN ({$f}) AND {$an}.uid = 0)) ", DRUPAL_ANONYMOUS_RID);
}
if ($filters['uid_filter'] && $filters['uid_filter'] != 'none') {
$f = $filters['uid_filter'];
$a = $aliases['node'];
$where[] = " {$a}.uid IN ({$f}) ";
}
if ($filters['tid_filter'] && $filters['tid_filter'] != 'none') {
$f = $filters['tid_filter'];
$a = $aliases['term_node'];
$where[] = " {$a}.tid IN ({$f}) ";
}
return $where ? implode(' AND ', $where) : '1=1';
}