Commit 38cd4cf8 authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Added a basic realname auto-completion callback.

parent f9258da5
......@@ -38,6 +38,12 @@ function realname_menu() {
'file' => 'realname.admin.inc',
);
$items['realname/autocomplete'] = array(
'page callback' => 'realname_autocomplete',
'access arguments' => array('access user profiles'),
'type' => MENU_CALLBACK,
);
return $items;
}
......@@ -243,3 +249,27 @@ function realname_delete_all() {
/**
* @} End of "addtogroup realname".
*/
/**
* Menu callback; Retrieve a JSON object containing autocomplete suggestions
* for existing users based on their generated real names.
*/
function realname_autocomplete($string = '') {
$matches = array();
if ($string) {
$query = db_select('users', 'u');
$query->leftJoin('realname', 'rn', 'u.uid = rn.uid');
$query->fields('u', array('uid'));
$query->condition('rn.realname', db_like($string) . '%', 'LIKE');
$query->range(0, 10);
$uids = $query->execute()->fetchCol();
$accounts = user_load_multiple($uids);
foreach ($accounts as $account) {
$matches[$account->name] = format_username($account);
}
}
drupal_json_output($matches);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment