summaryrefslogtreecommitdiff
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:56:27 (GMT)
commit19e0281fab8f0198f05bf216d2ee754905faeff8 (patch)
tree7dfbcd44a6283af3a1d1a3e11773bcde501cab4d
parent9221299075acdfbfaebf33bb398c57e93755f796 (diff)
downloadkolab-wap-19e0281fab8f0198f05bf216d2ee754905faeff8.tar.gz
Make so object type ID is not required when only one type is defined (Bug #2519)
-rw-r--r--lib/api/kolab_api_service_form_value.php6
-rw-r--r--lib/kolab_api_service.php47
2 files changed, 27 insertions, 26 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 1bed5f0..3ea1670 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 276e679..ef0e8bf 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'];