summaryrefslogtreecommitdiffstats
path: root/lib/api/kolab_api_service_type.php
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-08-26 05:09:40 -0400
committerAleksander Machniak <machniak@kolabsys.com>2014-08-26 05:09:40 -0400
commita21a3ede4bfc20c2b1d14d5aa6656df1c3fd46aa (patch)
treeea8bfab5c6da0de02df88e0775a6a2faad453f4d /lib/api/kolab_api_service_type.php
parent7fd434797e24e256bfec7645048767ef9c4d3afe (diff)
downloadwebadmin-a21a3ede4bfc20c2b1d14d5aa6656df1c3fd46aa.tar.gz
Make possible to define default object type (#2587)
Diffstat (limited to 'lib/api/kolab_api_service_type.php')
-rw-r--r--lib/api/kolab_api_service_type.php12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/api/kolab_api_service_type.php b/lib/api/kolab_api_service_type.php
index 162b29d..868018b 100644
--- a/lib/api/kolab_api_service_type.php
+++ b/lib/api/kolab_api_service_type.php
@@ -94,6 +94,7 @@ class kolab_api_service_type extends kolab_api_service
'name' => $postdata['name'],
'description' => $postdata['description'] ? $postdata['description'] : '',
'attributes' => json_encode($postdata['attributes']),
+ 'is_default' => $postdata['is_default'] ? 1 : 0,
);
if ($postdata['type'] == 'user') {
@@ -110,6 +111,11 @@ class kolab_api_service_type extends kolab_api_service
return false;
}
+ // there can be only one default
+ if ($postdata['is_default']) {
+ $this->db->query("UPDATE {$type}_types SET is_default = 0 WHERE id <> " . intval($id));
+ }
+
// update cache
$this->cache['object_types'][$type][$id] = $postdata;
@@ -182,6 +188,7 @@ class kolab_api_service_type extends kolab_api_service
'name' => $postdata['name'],
'description' => $postdata['description'] ? $postdata['description'] : '',
'attributes' => json_encode($postdata['attributes']),
+ 'is_default' => $postdata['is_default'] ? 1 : 0,
);
if ($postdata['type'] == 'user') {
@@ -199,6 +206,11 @@ class kolab_api_service_type extends kolab_api_service
return false;
}
+ // there can be only one default
+ if ($postdata['is_default']) {
+ $this->db->query("UPDATE {$type}_types SET is_default = 0 WHERE id <> " . intval($postdata['id']));
+ }
+
// update cache
$this->cache['object_types'][$type][$id] = $postdata;