function privatemsg_sql_autocomplete

1 privatemsg.module privatemsg_sql_autocomplete(&$fragments, $search, $names)
7-1 privatemsg.module privatemsg_sql_autocomplete($search, $names)
7-2 privatemsg.module privatemsg_sql_autocomplete($search, $names)
6-2 privatemsg.module privatemsg_sql_autocomplete(&$fragments, $search, $names)

Looks up autocomplete suggestions for users.

Parameters

$search: The string that is being searched for.

$names: Array of names which are already selected and should be excluded.

See also

hook_query_privatemsg_autocomplete_alter()

Related topics

File

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

Code

function privatemsg_sql_autocomplete($search, $names) {
  $query = db_select('users', 'u')->fields('u', array('uid'))->condition('u.name', $search . '%', 'LIKE')->condition('u.status', 0, '<>')->where("NOT EXISTS (SELECT 1 FROM {pm_setting} pms WHERE pms.id = u.uid AND pms.type = 'user' AND pms.setting = 'disabled')")->orderBy('u.name', 'ASC')->range(0, 10);

  if (!empty($names)) {
    $query->condition('u.name', $names, 'NOT IN');
  }
  return $query;
}