function user_search_execute
user_search_execute($keys = NULL, $conditions = NULL)
Implements hook_search_execute().
File
- modules/user/ user.module, line 959
- Enables the user registration and login system.
Code
function user_search_execute($keys = NULL, $conditions = NULL) { $find = array(); // Escape for LIKE matching. $keys = db_like($keys); // Replace wildcards with MySQL/PostgreSQL wildcards. $keys = preg_replace('!\*+!', '%', $keys); $query = db_select('users')->extend('PagerDefault'); $query->fields('users', array('uid')); if (user_access('administer users')) { // Administrators can also search in the otherwise private email field, // and they don't need to be restricted to only active users. $query->fields('users', array('mail')); $query->condition(db_or()-> condition('name', '%' . $keys . '%', 'LIKE')-> condition('mail', '%' . $keys . '%', 'LIKE')); } else { // Regular users can only search via usernames, and we do not show them // blocked accounts. $query->condition('name', '%' . $keys . '%', 'LIKE') ->condition('status', 1); } $uids = $query ->limit(15) ->execute() ->fetchCol(); $accounts = user_load_multiple($uids); $results = array(); foreach ($accounts as $account) { $result = array( 'title' => format_username($account), 'link' => url('user/' . $account->uid, array('absolute' => TRUE)), ); if (user_access('administer users')) { $result['title'] .= ' (' . $account->mail . ')'; } $results[] = $result; } return $results; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!user!user.module/function/user_search_execute/7.x