lib/api lib/kolab_api_service.php

Aleksander Machniak machniak at kolabsys.com
Mon Nov 18 14:57:43 CET 2013


 lib/api/kolab_api_service_form_value.php |    6 +--
 lib/kolab_api_service.php                |   47 +++++++++++++++----------------
 2 files changed, 27 insertions(+), 26 deletions(-)

New commits:
commit 4aaa9b2a828af9d8a2a5aa31b38677208b6d0261
Author: Aleksander Machniak <alec at alec.pl>
Date:   Mon Nov 18 14:56:27 2013 +0100

    Make so object type ID is not required when only one type is defined (Bug #2519)

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index df1d29e..f4015c4 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -64,7 +64,7 @@ class kolab_api_service_form_value extends kolab_api_service
      */
     public function generate($getdata, $postdata)
     {
-        $attribs    = $this->object_type_attributes($postdata['object_type'], $postdata['type_id'], true, $type_key);
+        $attribs    = $this->object_type_attributes($postdata['object_type'], $postdata['type_id'], $type_key);
         $attributes = (array) $postdata['attributes'];
         $result     = array();
 
@@ -112,7 +112,7 @@ class kolab_api_service_form_value extends kolab_api_service
     {
         //console($postdata);
 
-        $attribs   = $this->object_type_attributes($postdata['object_type'], $postdata['type_id'], true, $key_name);
+        $attribs   = $this->object_type_attributes($postdata['object_type'], $postdata['type_id'], $key_name);
         $attr_name = $postdata['attribute'];
         $result    = array(
             // return search value, so client can match response to request
@@ -161,7 +161,7 @@ class kolab_api_service_form_value extends kolab_api_service
     public function select_options($getdata, $postdata)
     {
         //console("form_value.select_options postdata", $postdata);
-        $attribs    = $this->object_type_attributes($postdata['object_type'], $postdata['type_id'], true, $key_name);
+        $attribs    = $this->object_type_attributes($postdata['object_type'], $postdata['type_id'], $key_name);
         $attributes = (array) $postdata['attributes'];
         $result     = array();
 
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 83fdd5b..ab2400f 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -57,40 +57,41 @@ abstract class kolab_api_service
      *
      * @param string $object_name  Name of the object (user, group, etc.)
      * @param int    $type_id      User type identifier
-     * @param bool   $required     Throws exception on empty ID
      * @param string $key_name     Reference to a variable which will be set to type key
      *
      * @return array User type attributes
      */
-    protected function object_type_attributes($object_name, $type_id, $required = true, &$key_name = null)
+    protected function object_type_attributes($object_name, $type_id, &$key_name = null)
     {
         if (!$object_name || !in_array($object_name, $this->supported_types)) {
             return array();
         }
 
-        if (empty($type_id)) {
-            if ($required) {
-                throw new Exception($this->controller->translate('api.notypeid'), 34);
-            }
-
-            return array();
+        // get list of object types
+        if ($object_name == 'domain') {
+            $object_types = array(
+                '1' => array(
+                    'key'        => 'default',
+                    'attributes' => kolab_api_service_domain_types::$DEFAULT_TYPE_ATTRS,
+                ),
+            );
+            $object_types['1']['attributes']['form_fields']['aci'] = array(
+                'type'     => 'list',
+                'optional' => true,
+            );
+        }
+        else {
+            $object_types = $this->object_types($object_name);
         }
 
-        $object_types = $this->object_types($object_name);
-
-        if (empty($object_types[$type_id])) {
-            if ($object_name == 'domain') {
-                $result = kolab_api_service_domain_types::$DEFAULT_TYPE_ATTRS;
-                $result['form_fields']['aci'] = array(
-                    'type' => 'list',
-                    'optional' => true,
-                );
-
-                return $result;
-            }
-            else {
-                throw new Exception($this->controller->translate('api.invalidtypeid'), 35);
-            }
+        if ($type_id && empty($object_types[$type_id])) {
+            throw new Exception($this->controller->translate('api.invalidtypeid'), 35);
+        }
+        else if (count($object_types) == 1) {
+            $type_id = key($object_types);
+        }
+        else {
+            throw new Exception($this->controller->translate('api.notypeid'), 34);
         }
 
         $key_name = $object_types[$type_id]['key'];




More information about the commits mailing list