You are here

function quotes_block_where_sql in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \quotes_block_where_sql()
  2. 6 quotes.module \quotes_block_where_sql()

Modifies the SQL query as needed with conditions provided by filter criteria.

Parameters

array $filters: The array specifying filter criteria using the keys nid_filter, rid_filter, uid_filter, and tid_filter.

string $query: The sql query we are modifying.

Return value

string The modified query containing any conditions necessary for the provided criteria.

1 call to quotes_block_where_sql()
quotes_get_quote in ./quotes.module
Returns random quote or the most recent quote ID based on filter criteria.

File

./quotes.module, line 1886
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(), $query) {

  // Filter by specific node IDs.
  if ($filters['nid_filter']) {
    $nid_nums = explode(",", $filters['nid_filter']);
    $query
      ->condition('n.nid', $nid_nums, 'IN');
  }

  // Filter by specific author IDs.
  if ($filters['aid_filter'] && $filters['aid_filter'] != 'none') {
    $aid_nums = explode(",", $filters['aid_filter']);
    $query
      ->condition('q.aid', $aid_nums, 'IN');
  }
  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);
    $ur_nums = explode(",", $filters['rid_filter']);
    $query
      ->condition(db_or()
      ->condition('ur.rid', $ur_nums, 'IN')
      ->condition(db_and()
      ->condition('n.uid', 0)
      ->condition('qb.rid_filter', DRUPAL_ANONYMOUS_RID, 'IN')));
  }
  if ($filters['uid_filter'] && $filters['uid_filter'] != 'none') {
    $id_nums = explode(",", $filters['uid_filter']);
    $query
      ->condition('n.uid', $id_nums, 'IN');
  }
  if ($filters['tid_filter'] && $filters['tid_filter'] != 'none') {
    $tid_nums = explode(",", $filters['tid_filter']);
    $query
      ->condition('ti.tid', $tid_nums, 'IN');
  }
}