From bb52739dce13d471ebaf4a8b906b4ef2d598a526 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 10 Oct 2013 09:38:22 +0200 Subject: Slice page from list result after sorting and ordering, small code improvements --- lib/Auth/LDAP.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php index 6d13a6c..bf02ba1 100644 --- a/lib/Auth/LDAP.php +++ b/lib/Auth/LDAP.php @@ -1304,21 +1304,18 @@ class LDAP extends Net_LDAP3 { } if (!empty($params) && is_array($params)) { - if (array_key_exists('sort_by', $params)) { + if (!empty($params['sort_by'])) { $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)) { - if ($result->count() > $params['page_size']) { - $entries = array_slice($entries, (($params['page'] - 1) * $params['page_size']), $params['page_size'], true); - } - + if (!empty($params['sort_order']) && $params['sort_order'] == "DESC") { + $entries = array_reverse($entries, true); } - if (array_key_exists('sort_order', $params) && !empty($params['sort_order'])) { - if ($params['sort_order'] == "DESC") { - $entries = array_reverse($entries, true); + if (!empty($params['page_size']) && !empty($params['page'])) { + if ($result->count() > $params['page_size']) { + $entries = array_slice($entries, (($params['page'] - 1) * $params['page_size']), $params['page_size'], true); } } } -- cgit v1.1