aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-01-28 15:47:57 +0100
committerBjörn Schießle <schiessle@owncloud.com>2013-01-28 15:47:57 +0100
commitc00b66fe5bb37403e4dec1ede9d509947b795df0 (patch)
tree5862b29d772e719116c4fb665231a1fd4e3127d5 /lib
parente6cc0cd08a502fc426c868bd1981c80eb39a9062 (diff)
downloadnextcloud-server-c00b66fe5bb37403e4dec1ede9d509947b795df0.tar.gz
nextcloud-server-c00b66fe5bb37403e4dec1ede9d509947b795df0.zip
implement DisplayNamesInGroup for database back-end
Diffstat (limited to 'lib')
-rw-r--r--lib/group.php2
-rw-r--r--lib/group/backend.php2
-rw-r--r--lib/group/database.php28
-rw-r--r--lib/user.php2
-rw-r--r--lib/user/database.php10
5 files changed, 37 insertions, 7 deletions
diff --git a/lib/group.php b/lib/group.php
index 8ebb698692b..5afef769361 100644
--- a/lib/group.php
+++ b/lib/group.php
@@ -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();
diff --git a/lib/group/backend.php b/lib/group/backend.php
index ceb2d9242dd..4f6570c3be3 100644
--- a/lib/group/backend.php
+++ b/lib/group/backend.php
@@ -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 = '';
diff --git a/lib/group/database.php b/lib/group/database.php
index 6eca98ba019..c5dd402b212 100644
--- a/lib/group/database.php
+++ b/lib/group/database.php
@@ -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;
+ }
}
diff --git a/lib/user.php b/lib/user.php
index b91abd71fe6..399a3240c8c 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -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.
*/
diff --git a/lib/user/database.php b/lib/user/database.php
index 52f11a5e29d..bed97f25fdb 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -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;
}