Fixed autocomplete returning bogus results

This commit is contained in:
Craig Andrews 2009-11-05 23:51:30 -05:00
parent d6ddb84132
commit 9c80f141e2
1 changed files with 10 additions and 9 deletions

View File

@ -98,11 +98,10 @@ class AutocompleteAction extends Action
$user = new User(); $user = new User();
$user->limit($limit); $user->limit($limit);
$user->whereAdd('nickname like \'' . trim($user->escape($q), '\'') . '%\''); $user->whereAdd('nickname like \'' . trim($user->escape($q), '\'') . '%\'');
$user->find(); if($user->find()){
while($user->fetch()) { while($user->fetch()) {
$profile = Profile::staticGet($user->id); $this->users[]=clone($user);
$user->profile=$profile; }
$this->users[]=$user;
} }
} }
if(substr($q,0,1)=='!'){ if(substr($q,0,1)=='!'){
@ -111,9 +110,10 @@ class AutocompleteAction extends Action
$group = new User_group(); $group = new User_group();
$group->limit($limit); $group->limit($limit);
$group->whereAdd('nickname like \'' . trim($group->escape($q), '\'') . '%\''); $group->whereAdd('nickname like \'' . trim($group->escape($q), '\'') . '%\'');
$group->find(); if($group->find()){
while($group->fetch()) { while($group->fetch()) {
$this->groups[]=$group; $this->groups[]=clone($group);
}
} }
} }
return true; return true;
@ -124,7 +124,8 @@ class AutocompleteAction extends Action
parent::handle($args); parent::handle($args);
$results = array(); $results = array();
foreach($this->users as $user){ foreach($this->users as $user){
$results[]=array('nickname' => $user->nickname, 'fullname'=> $user->profile->fullname, 'type'=>'user'); $profile = $user->getProfile();
$results[]=array('nickname' => $user->nickname, 'fullname'=> $profile->fullname, 'type'=>'user');
} }
foreach($this->groups as $group){ foreach($this->groups as $group){
$results[]=array('nickname' => $group->nickname, 'fullname'=> $group->fullname, 'type'=>'group'); $results[]=array('nickname' => $group->nickname, 'fullname'=> $group->fullname, 'type'=>'group');