autocomplete for multiple usernames?

pwolanin - September 6, 2006 - 17:13

In the core code, the user.module's autocomplete callback will only try to complete a single username. However, it seems as though this should be able to work for multiple names, like the free tagging in taxonomy module. Culling code form user and taxonomy modules, I think the code below could provide this functionality (I haven't tried it yet, however). Has anyone else wanted the same thing and gotten it working?

<?php
function multiuser_autocomplete($string = '') {
 
// The user enters a comma-separated list of usernames. We only autocomplete the last one.
 
$array = explode(',',$string);
 
// Fetch last tag
 
$last_string = trim(array_pop($array));
  if (
$last_string != '') {
   
user_autocomplete($last_string)
  }
}

function
mymodule_menu($may_cache) {
 
  if (
$may_cache) {
   
$items[] = array(
     
'path' => 'user/multi-autocomplete',
     
'title' => t('user autocomplete'),
     
'callback' => 'multiuser_autocomplete',
     
'access' => user_access('access user profiles'),
     
'type' => MENU_CALLBACK,
    );
  }
 
  return
$items;
}
?>

Great

Boris Mann - September 6, 2006 - 20:48

Yes, this would be super useful. It should actually be a core function, I think. For now, we're going to try and get this working with the organic groups add subscribers field. And by we, I mean point Moshe at this and see if he wants to give it a try :P

needs more from taxonomy module

pwolanin - September 7, 2006 - 03:10

the above doesn't work (only matches one name at the beginning of the line). The following is starting to work, after further study of the taxnomy module

<?php
function multiuser_autocomplete($string) {
 
// The user enters a comma-separated list of usernames. We only autocomplete the last one.
 
$array = explode(',',$string);
 
// Fetch last username
 
$last = trim(array_pop($array));
  if (
$last != '') {
   
$prefix = count($array) ? implode(',', $array) .', ' : '';
   
$matches = array();
   
$result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $last, 0, 10);

    while (
$user = db_fetch_object($result)) {
     
$matches[$prefix. $user->name] = check_plain($user->name);
    }
    print
drupal_to_js($matches);
    exit();
  }
}
?>

current / Drupal 5 status

Benjamin Melançon - February 14, 2007 - 22:39

an inquiry from a very interested party...

~ben

People Who Give a Damn :: http://pwgd.org/ :: Building the infrastructure of a network for everyone
Agaric Design Collective :: http://AgaricDesign.com/ :: Open Source Web Development

Just saw your post about the

pwolanin - February 15, 2007 - 01:10

Just saw your post about the multi-user autocomplete

It seems to be working in my volunteer_timeslots module: http://drupal.org/node/106536

Anyhow, I saw the link to your site, and I'm curious about this graphic:

http://agaricdesign.com/grade-in

As best as I can tell, it's not from the Univ. of Michigan GEO (where I was on the bargaining team and a department steward), but the graphic (and event) looks very much derived from the UofM GEO logo drawn by one of members at the time: http://www.umgeo.org/

 
 

Drupal is a registered trademark of Dries Buytaert.