From 64551ee06f2d33979c525a36455337aaca646d16 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@owncloud.com>
Date: Tue, 26 Feb 2013 22:27:09 +0100
Subject: [PATCH] LDAP: sort users on server-side

---
 apps/user_ldap/lib/access.php | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php
index 901299e7c2..05249b8f16 100644
--- a/apps/user_ldap/lib/access.php
+++ b/apps/user_ldap/lib/access.php
@@ -624,7 +624,8 @@ abstract class Access {
 	 * @brief executes an LDAP search
 	 * @param $filter the LDAP filter for the search
 	 * @param $base an array containing the LDAP subtree(s) that shall be searched
-	 * @param $attr optional, when a certain attribute shall be filtered out
+	 * @param $attr optional, array, one or more attributes that shall be
+	 * retrieved. Results will according to the order in the array.
 	 * @returns array with the search result
 	 *
 	 * Executes an LDAP search
@@ -656,6 +657,14 @@ abstract class Access {
 			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), \OCP\Util::ERROR);
 			return array();
 		}
+
+		// Do the server-side sorting
+		foreach(array_reverse($attr) as $sortAttr){
+			foreach($sr as $searchResource) {
+				ldap_sort($link_resource, $searchResource, $sortAttr);
+			}
+		}
+
 		$findings = array();
 		foreach($sr as $key => $res) {
 		    $findings = array_merge($findings, ldap_get_entries($link_resource, $res ));
-- 
GitLab