user_search_execute

Versions
7
user_search_execute($keys = NULL)

Implements hook_search_execute().

Code

modules/user/user.module, line 846

<?php
function user_search_execute($keys = NULL) {
  $find = array();
  // Replace wildcards with MySQL/PostgreSQL wildcards.
  $keys = preg_replace('!\*+!', '%', $keys);
  $query = db_select('users')->extend('PagerDefault');
  $query->fields('users', array('name', 'uid', 'mail'));
  if (user_access('administer users')) {
    // Administrators can also search in the otherwise private email field.
    $query->condition(db_or()->
      where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"))->
      where('LOWER(mail) LIKE LOWER(:mail)', array(':mail' => "%$keys%")));
  }
  else {
    $query->where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"));
  }
  $result = $query
    ->limit(15)
    ->execute();
  foreach ($result as $account) {
    $find[] = array('title' => $account->name . ' (' . $account->mail . ')', 'link' => url('user/' . $account->uid, array('absolute' => TRUE)));
  }
  return $find;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.