From e6cc0cd08a502fc426c868bd1981c80eb39a9062 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= <schiessle@owncloud.com>
Date: Mon, 28 Jan 2013 15:07:31 +0100
Subject: [PATCH] implement display names for the database back-end

---
 lib/user/database.php | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/lib/user/database.php b/lib/user/database.php
index 49c7654532..52f11a5e29 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -129,6 +129,40 @@ class OC_User_Database extends OC_User_Backend {
 		}
 	}
 
+	/**
+	 * @brief get display name of the user
+	 * @param $uid user ID of the user
+	 * @return display name
+	 */
+	public function getDisplayName($uid) {
+		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'];
+			} else {
+				return $uid;
+			}
+		}
+	}
+	
+	/**
+	 * @brief Get a list of all display names
+	 * @returns array with  all displayNames (value) and the correspondig uids (key)
+	 *
+	 * Get a list of all display names and user ids.
+	 */
+	public function getDisplayNames($search = '', $limit = null, $offset = null) {
+		$displayNames = array();
+		$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'];
+		}
+		return $displayNames;
+	}
+	
 	/**
 	 * @brief Check if the password is correct
 	 * @param $uid The username
-- 
GitLab