You are here

function privatemsg_sql_autocomplete in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg.module \privatemsg_sql_autocomplete()
  2. 7.2 privatemsg.module \privatemsg_sql_autocomplete()
  3. 7 privatemsg.module \privatemsg_sql_autocomplete()

Query definition to search for username autocomplete suggestions.

Parameters

$fragments: Query fragments array.

$search: Which search string is currently searched for.

$names: Array of names not to be used as suggestions.

Related topics

File

./privatemsg.module, line 1327
Allows users to send private messages to other users.

Code

function privatemsg_sql_autocomplete(&$fragments, $search, $names) {
  $fragments['primary_table'] = '{users} u';
  $fragments['select'][] = 'u.name';

  // Escape the % to get it through the placeholder replacement.
  $fragments['where'][] = "u.name LIKE '%s'";
  $fragments['query_args']['where'][] = $search . '%%';
  if (!empty($names)) {

    // If there are already names selected, exclude them from the suggestions.
    $fragments['where'][] = "u.name NOT IN (" . db_placeholders($names, 'text') . ")";
    $fragments['query_args']['where'] += $names;
  }

  // Only load active users and sort them by name.
  $fragments['where'][] = 'u.status <> 0';
  $fragments['order_by'][] = 'u.name ASC';
}