summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-06-27 13:21:23 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-06-27 13:21:23 (GMT)
commita0a64ebabd382c0de03ccb00a0a2b52eb369248d (patch)
tree458109a7fa5c243ee470b127abef4f5bb10de4ee
parent9652212d7f584a4da1e15010c3cfdf639c17e89d (diff)
downloadkolab-wap-a0a64ebabd382c0de03ccb00a0a2b52eb369248d.tar.gz
Support 'id' in list results
-rw-r--r--lib/api/kolab_api_service_domains.php1
-rw-r--r--lib/api/kolab_api_service_groups.php2
-rw-r--r--lib/api/kolab_api_service_resources.php1
-rw-r--r--lib/api/kolab_api_service_roles.php1
-rw-r--r--lib/api/kolab_api_service_sharedfolders.php1
-rw-r--r--lib/api/kolab_api_service_users.php1
-rw-r--r--lib/kolab_api_service.php24
7 files changed, 30 insertions, 1 deletions
diff --git a/lib/api/kolab_api_service_domains.php b/lib/api/kolab_api_service_domains.php
index fe9804e..ca9ea01 100644
--- a/lib/api/kolab_api_service_domains.php
+++ b/lib/api/kolab_api_service_domains.php
@@ -95,6 +95,7 @@ class kolab_api_service_domains extends kolab_api_service
$search = $this->parse_list_search($post);
$domains = $auth->list_domains($attributes, $search, $params);
+ $domains = $this->parse_list_result($domains);
return $domains;
}
diff --git a/lib/api/kolab_api_service_groups.php b/lib/api/kolab_api_service_groups.php
index c613408..1c90a81 100644
--- a/lib/api/kolab_api_service_groups.php
+++ b/lib/api/kolab_api_service_groups.php
@@ -67,8 +67,8 @@ class kolab_api_service_groups extends kolab_api_service
$search = $this->parse_list_search($post);
$groups = $auth->list_groups(null, $attributes, $search, $params);
+ $groups = $this->parse_list_result($groups);
return $groups;
-
}
}
diff --git a/lib/api/kolab_api_service_resources.php b/lib/api/kolab_api_service_resources.php
index f7b00dc..2527ed6 100644
--- a/lib/api/kolab_api_service_resources.php
+++ b/lib/api/kolab_api_service_resources.php
@@ -68,6 +68,7 @@ class kolab_api_service_resources extends kolab_api_service
$search = $this->parse_list_search($post);
$resources = $auth->list_resources(null, $attributes, $search, $params);
+ $resources = $this->parse_list_result($resources);
return $resources;
}
diff --git a/lib/api/kolab_api_service_roles.php b/lib/api/kolab_api_service_roles.php
index 41938d1..dee7859 100644
--- a/lib/api/kolab_api_service_roles.php
+++ b/lib/api/kolab_api_service_roles.php
@@ -66,6 +66,7 @@ class kolab_api_service_roles extends kolab_api_service
$search = $this->parse_list_search($post);
$roles = $auth->list_roles(null, $attributes, $search, $params);
+ $roles = $this->parse_list_result($roles);
return $roles;
}
diff --git a/lib/api/kolab_api_service_sharedfolders.php b/lib/api/kolab_api_service_sharedfolders.php
index 03c7a6c..8951250 100644
--- a/lib/api/kolab_api_service_sharedfolders.php
+++ b/lib/api/kolab_api_service_sharedfolders.php
@@ -70,6 +70,7 @@ class kolab_api_service_sharedfolders extends kolab_api_service
$search = $this->parse_list_search($post);
$resources = $auth->list_sharedfolders(null, $attributes, $search, $params);
+ $resources = $this->parse_list_result($resources);
return $resources;
}
diff --git a/lib/api/kolab_api_service_users.php b/lib/api/kolab_api_service_users.php
index 16ea440..38f6b59 100644
--- a/lib/api/kolab_api_service_users.php
+++ b/lib/api/kolab_api_service_users.php
@@ -73,6 +73,7 @@ class kolab_api_service_users extends kolab_api_service
$search = $this->parse_list_search($post);
$users = $auth->list_users(null, $attributes, $search, $params);
+ $users = $this->parse_list_result($users);
Log::trace("users.list result: " . var_export($users, TRUE));
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 4cc526a..9cdc582 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -379,6 +379,11 @@ abstract class kolab_api_service
$attributes = array_intersect($this->list_attribs, $post['attributes']);
// need to fix array keys
$attributes = array_values($attributes);
+
+ // unique attribute is always allowed
+ if (($key = array_search('id', $post['attributes'])) !== false) {
+ $attributes[] = $this->unique_attribute();
+ }
}
if (empty($attributes)) {
@@ -388,6 +393,25 @@ abstract class kolab_api_service
return $attributes;
}
+ protected function parse_list_result($result)
+ {
+ if (!empty($result) && !empty($result['count'])) {
+ $unique_attr = $this->unique_attribute();
+
+ // replace back unique attribute name with 'id'
+ foreach ($result['list'] as $idx => $record) {
+ // if not set, we assume unique attribute wasn't requested
+ if (!isset($record[$unique_attr])) {
+ break;
+ }
+ $result['list'][$idx]['id'] = $record[$unique_attr];
+ unset($result['list'][$idx][$unique_attr]);
+ }
+ }
+
+ return $list;
+ }
+
protected function parse_list_params($post)
{
$params = Array();