function _user_reference_get_user_names in References 7.2
Helper function for widgets and formatters.
Store user names collected in the curent request.
1 call to _user_reference_get_user_names()
- user_reference_autocomplete_validate in user_reference/
user_reference.module - Validation callback for a user_reference autocomplete element.
File
- user_reference/
user_reference.module, line 555 - Defines a field type for referencing a user from a node.
Code
function _user_reference_get_user_names($uids, $known_titles = array()) {
$titles =& drupal_static(__FUNCTION__, array());
// Save titles we receive.
$titles += $known_titles;
// Collect nids to retrieve from database.
$uids_query = array();
foreach ($uids as $uid) {
if (!isset($titles[$uid])) {
$uids_query[] = $uid;
}
}
if ($uids_query) {
$query = db_select('users', 'u')
->fields('u', array(
'uid',
'name',
))
->condition('u.uid', $uids);
$titles += $query
->execute()
->fetchAllKeyed();
}
// Build the results array.
$return = array();
foreach ($uids as $uid) {
$return[$uid] = isset($titles[$uid]) ? $titles[$uid] : '';
}
return $return;
}