local user backend shall search for both username and displayname, fixes #5401

This commit is contained in:
Arthur Schiwon 2013-10-25 21:57:12 +02:00
parent e0f5fa9ea7
commit 466b6c1ee0

View file

@ -156,25 +156,14 @@ class OC_User_Database extends OC_User_Backend {
public function getDisplayNames($search = '', $limit = null, $offset = null) {
$displayNames = array();
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`'
.' WHERE LOWER(`displayname`) LIKE LOWER(?)', $limit, $offset);
$result = $query->execute(array($search.'%'));
.' WHERE LOWER(`displayname`) LIKE LOWER(?) OR '
.'LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
$result = $query->execute(array($search.'%', $search.'%'));
$users = array();
while ($row = $result->fetchRow()) {
$displayNames[$row['uid']] = $row['displayname'];
}
// let's see if we can also find some users who don't have a display name yet
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`'
.' WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
$result = $query->execute(array($search.'%'));
while ($row = $result->fetchRow()) {
$displayName = trim($row['displayname'], ' ');
if ( empty($displayName) ) {
$displayNames[$row['uid']] = $row['uid'];
}
}
return $displayNames;
}