2 commits - lib/Auth
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Mon Sep 17 16:19:06 CEST 2012
lib/Auth/LDAP.php | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
New commits:
commit bce7575103474e68c875e644b9c4b38304905184
Merge: bb09dde 4a1056f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Mon Sep 17 16:18:57 2012 +0200
Merge branch 'master' of ssh://git.kolab.org/git/kolab-wap
commit bb09dded77f55e5e6f213e1f03a617e7a514c8b3
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Mon Sep 17 16:17:44 2012 +0200
Improve sort_and_slice by reintroducing sort_result as a callback for uasort
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 858c422..1c30c0c 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -967,26 +967,19 @@ class LDAP extends Net_LDAP3 {
}
private function sort_and_slice(&$result, &$params) {
+ $entries = $result->entries(TRUE);
+
if (!empty($params) && is_array($params)) {
if (array_key_exists('sort_by', $params)) {
- if (is_array($params['sort_by'])) {
- $sort = array_shift($params['sort_by']);
- } else {
- $sort = $params['sort_by'];
- }
-
- $result->sort($sort);
-
+ $this->sort_result_key = $params['sort_by'];
+ uasort($entries, array($this, 'sort_result'));
}
if (array_key_exists('page_size', $params) && array_key_exists('page', $params)) {
- $entries = $result->entries(TRUE);
if ($result->count() > $params['page_size']) {
$entries = array_slice($entries, (($params['page'] - 1) * $params['page_size']), $params['page_size'], TRUE);
}
- } else {
- $entries = $result->entries(TRUE);
}
if (array_key_exists('sort_order', $params) && !empty($params['sort_order'])) {
@@ -994,13 +987,33 @@ class LDAP extends Net_LDAP3 {
$entries = array_reverse($entries, TRUE);
}
}
- } else {
- $entries = $result->entries(TRUE);
}
return $entries;
}
+ /**
+ * Result sorting callback for uasort()
+ */
+ private function sort_result($a, $b)
+ {
+ if (is_array($this->sort_result_key)) {
+ foreach ($this->sort_result_key as $attrib) {
+ if (array_key_exists($attrib, $a) && !$str1) {
+ $str1 = $a[$attrib];
+ }
+ if (array_key_exists($attrib, $b) && !$str2) {
+ $str2 = $b[$attrib];
+ }
+ }
+ } else {
+ $str1 = $a[$this->sort_result_key];
+ $str2 = $b[$this->sort_result_key];
+ }
+
+ return strcmp(mb_strtoupper($str1), mb_strtoupper($str2));
+ }
+
private function unique_attribute() {
$unique_attr = $this->conf->get("unique_attribute");
return empty($unique_attr) ? 'nsuniqueid' : $unique_attr;
More information about the commits
mailing list