Skip to content
Snippets Groups Projects
Commit c00b66fe authored by Björn Schießle's avatar Björn Schießle
Browse files

implement DisplayNamesInGroup for database back-end

parent e6cc0cd0
Branches
No related tags found
No related merge requests found
......@@ -289,7 +289,7 @@ class OC_Group {
/**
* @brief get a list of all display names in a group
* @returns array with display names (key) and user ids(value)
* @returns array with display names (value) and user ids(key)
*/
public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$displayNames=array();
......
......@@ -140,7 +140,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
* @param string $search
* @param int $limit
* @param int $offset
* @return array with display names (key) and user ids (value)
* @return array with display names (value) and user ids (key)
*/
public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$displayNames = '';
......
......@@ -208,4 +208,32 @@ class OC_Group_Database extends OC_Group_Backend {
}
return $users;
}
/**
* @brief get a list of all display names in a group
* @param string $gid
* @param string $search
* @param int $limit
* @param int $offset
* @return array with display names (value) and user ids (key)
*/
public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$displayNames = '';
/*
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName
*/
$stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname` FROM `*PREFIX*users` INNER JOIN `*PREFIX*group_user` ON `*PREFIX*group_user`.`uid` = `*PREFIX*users`.`uid` WHERE `gid` = ? AND `*PREFIX*group_user.uid` LIKE ?', $limit, $offset);
$result = $stmt->execute(array($gid, $search.'%'));
$users = array();
while ($row = $result->fetchRow()) {
$displayName = trim($row['displayname'], ' ');
$displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
}
return $displayNames;
}
}
......@@ -477,7 +477,7 @@ class OC_User {
/**
* @brief Get a list of all users display name
* @returns associative array with all display names (key) and corresponding uids (value)
* @returns associative array with all display names (value) and corresponding uids (key)
*
* Get a list of all display names and user ids.
*/
......
......@@ -138,8 +138,9 @@ class OC_User_Database extends OC_User_Backend {
if( $this->userExists($uid) ) {
$query = OC_DB::prepare( 'SELECT displayname FROM `*PREFIX*users` WHERE `uid` = ?' );
$result = $query->execute( array( $uid ))->fetchAll();
if (!empty($result[0]['displayname'])) {
return $result[0]['displayname'];
$displayName = trim($result[0]['displayname'], ' ');
if ( !empty($displayName) ) {
return $displayName;
} else {
return $uid;
}
......@@ -157,8 +158,9 @@ class OC_User_Database extends OC_User_Backend {
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
$result = $query->execute(array($search.'%'));
$users = array();
while ($row = $result->fetchRow()) {
$displayNames[$row['uid']] = $row['displayname'];
while ($row = $result->fetchRow()) {
$displayName = trim($row['displayname'], ' ');
$displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
}
return $displayNames;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment