You are here

function privatemsg_filter_create_get_query in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_get_query()
  2. 6 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_get_query()
  3. 7 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_get_query()

Creates a GET query based on the selected filters.

1 call to privatemsg_filter_create_get_query()
privatemsg_filter_dropdown_submit in privatemsg_filter/privatemsg_filter.module

File

privatemsg_filter/privatemsg_filter.module, line 457
Allows users to tag private messages and to filter based upon those tags.

Code

function privatemsg_filter_create_get_query($filter) {
  $query = array();
  if (isset($filter['tags']) && !empty($filter['tags'])) {
    $ids = array();
    foreach ($filter['tags'] as $tag) {
      if ((int) $tag > 0) {
        $ids[] = $tag;
      }
      else {
        $query['tags'][] = $tag;
      }
    }
    $sql = 'SELECT pmt.tag FROM {pm_tags} pmt WHERE pmt.tag_id IN (:tags)';
    $query['tags'] = db_query($sql, array(
      ':tags' => $filter['tags'],
    ))
      ->fetchCol();
    if (isset($query['tags'])) {
      $query['tags'] = implode(',', $query['tags']);
    }
  }
  if (isset($filter['author']) && !empty($filter['author'])) {
    foreach ($filter['author'] as $author) {
      if (is_object($author) && isset($author->uid) && isset($author->name)) {
        $query['author'][] = privatemsg_recipient_format($author, array(
          'plain' => TRUE,
        ));
      }
      elseif (is_int($author) && ($author_obj = array_shift(privatemsg_user_load_multiple(array(
        $author,
      ))))) {
        $query['author'][] = privatemsg_recipient_format($author_obj, array(
          'plain' => TRUE,
        ));
      }
    }
    if (isset($query['author'])) {
      $query['author'] = implode(',', $query['author']);
    }
  }
  if (isset($filter['search']) && !empty($filter['search'])) {
    $query['search'] = $filter['search'];
  }
  return $query;
}