Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
drupal.org
realname
Commits
38cd4cf8
Commit
38cd4cf8
authored
Feb 11, 2011
by
Dave Reid
Browse files
by Dave Reid: Added a basic realname auto-completion callback.
parent
f9258da5
Changes
1
Hide whitespace changes
Inline
Side-by-side
realname.module
View file @
38cd4cf8
...
...
@@ -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
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment