summaryrefslogtreecommitdiff
path: root/lib/kolab_api_service.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-11-18 13:56:27 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-11-18 13:57:36 (GMT)
commit4aaa9b2a828af9d8a2a5aa31b38677208b6d0261 (patch)
treec49a6a84a4b4231a0c57136b61ec7391f1f7e231 /lib/kolab_api_service.php
parent9cfd311602aa7ae92ba16c71c2f9949154de377e (diff)
downloadkolab-wap-4aaa9b2a828af9d8a2a5aa31b38677208b6d0261.tar.gz
Make so object type ID is not required when only one type is defined (Bug #2519)
Diffstat (limited to 'lib/kolab_api_service.php')
-rw-r--r--lib/kolab_api_service.php47
1 files changed, 24 insertions, 23 deletions
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'];