You are here

function quotes_block_where_sql in Quotes 5

Same name and namespace in other branches
  1. 6 quotes.module \quotes_block_where_sql()
  2. 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 1351

Code

function quotes_block_where_sql($filters = array(), $aliases = array(
  'node' => 'n',
  'users_roles' => 'qur',
  'users' => 'qu',
  'term_node' => 'qtn',
)) {
  $where = array();
  if ($filters['nid_filter']) {
    $where[] = " {$aliases['node']}.nid IN ({$filters['nid_filter']}) ";
  }
  if ($filters['aid_filter']) {
    $where[] = " (q.aid IN ({$filters['aid_filter']})) ";
  }
  if ($filters['rid_filter']) {
    $where[] = sprintf(" ({$aliases['users_roles']}.rid IN ({$filters['rid_filter']}) OR (%d IN ({$filters['rid_filter']}) AND {$aliases['node']}.uid = 0)) ", DRUPAL_ANONYMOUS_RID);
  }
  if ($filters['uid_filter'] != '') {
    $where[] = " {$aliases['node']}.uid IN ({$filters['uid_filter']}) ";
  }
  if ($filters['tid_filter']) {
    $where[] = " {$aliases['term_node']}.tid IN ({$filters['tid_filter']}) ";
  }
  return $where ? implode(' AND ', $where) : '1=1';
}