You are here

function privatemsg_roles_sql_autocomplete_roles in Privatemsg 6.2

Same name and namespace in other branches
  1. 7.2 privatemsg_roles/privatemsg_roles.module \privatemsg_roles_sql_autocomplete_roles()
  2. 7 privatemsg_roles/privatemsg_roles.module \privatemsg_roles_sql_autocomplete_roles()

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.

File

privatemsg_roles/privatemsg_roles.module, line 174
Allows to send messages to all members of a role.

Code

function privatemsg_roles_sql_autocomplete_roles(&$fragments, $search, $names) {
  $fragments['primary_table'] = '{role} role';
  $fragments['select'][] = 'role.*';

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

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