summaryrefslogtreecommitdiff
path: root/lib/kolab_api_service.php
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-22 08:16:00 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-22 08:21:39 (GMT)
commitd36051ee4515bba6904f2950822df828c124dce2 (patch)
tree704b8d6081d05a06c4a39b8894cdec0d1075efeb /lib/kolab_api_service.php
parent13ea713d0e97ae9a8cdacd0126b0e48d0974eecd (diff)
downloadkolab-wap-d36051ee4515bba6904f2950822df828c124dce2.tar.gz
Move the attributes, search and param parse functions to common ground (code-deduplication)
Diffstat (limited to 'lib/kolab_api_service.php')
-rw-r--r--lib/kolab_api_service.php64
1 files changed, 63 insertions, 1 deletions
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index cbe27ba..823996a 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -294,6 +294,68 @@ abstract class kolab_api_service
return $result;
}
+ protected function parse_list_attributes($post) {
+ $attributes = Array();
+ // Attributes to return
+ if (!empty($post['attributes']) && is_array($post['attributes'])) {
+ // get only supported attributes
+ $attributes = array_intersect($this->list_attribs, $post['attributes']);
+ // need to fix array keys
+ $attributes = array_values($attributes);
+ }
+
+ if (empty($attributes)) {
+ $attributes = (array)$this->list_attribs[0];
+ }
+
+ return $attributes;
+ }
+
+ protected function parse_list_params($post) {
+ $params = Array();
+ if (!empty($post['sort_by'])) {
+ if (is_array($post['sort_by'])) {
+ $params['sort_by'] = Array();
+ foreach ($post['sort_by'] as $attrib) {
+ if (in_array($attrib, $this->list_attribs)) {
+ $params['sort_by'][] = $attrib;
+ }
+ }
+ } else {
+ // check if sort attribute is supported
+ if (in_array($post['sort_by'], $this->list_attribs)) {
+ $params['sort_by'] = $post['sort_by'];
+ }
+ }
+ }
+
+ if (!empty($post['sort_order'])) {
+ $params['sort_order'] = $post['sort_order'] == 'DESC' ? 'DESC' : 'ASC';
+ }
+
+ if (!empty($post['page'])) {
+ $params['page'] = $post['page'];
+ }
+
+ if (!empty($post['page_size'])) {
+ $params['page_size'] = $post['page_size'];
+ }
+
+ return $params;
+ }
+
+ protected function parse_list_search($post) {
+ $search = Array();
+ // Search parameters
+ if (!empty($post['search']) && is_array($post['search'])) {
+ $search = $post['search'];
+ if (!empty($post['search_operator'])) {
+ $search['operator'] = $post['search_operator'];
+ }
+ }
+ return $search;
+ }
+
/**
* Parses result attributes
*
@@ -352,7 +414,7 @@ abstract class kolab_api_service
// Get extra attributes
if (!empty($extra_attrs)) {
- $extra_attrs = $auth->get_attributes($dn, $extra_attrs);
+ $extra_attrs = $auth->get_entry_attributes($dn, $extra_attrs);
if (!empty($extra_attrs)) {
$attrs = array_merge($attrs, $extra_attrs);
}