summaryrefslogtreecommitdiff
path: root/lib/kolab_api_service.php
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-25 10:56:51 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-25 10:56:51 (GMT)
commit2dee9bb43d2082344b1eb49dae35851406e7f472 (patch)
treecf1038e8d0af5c02a0bd7ffb31b10b5f0c1e041f /lib/kolab_api_service.php
parentf4e26dcfe7abc422deca8232f6fa5fff0d147390 (diff)
downloadkolab-wap-2dee9bb43d2082344b1eb49dae35851406e7f472.tar.gz
Implement $form_service->validate() (#680)
Diffstat (limited to 'lib/kolab_api_service.php')
-rw-r--r--lib/kolab_api_service.php130
1 files changed, 67 insertions, 63 deletions
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 18e6e82..7fca044 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -208,6 +208,73 @@ abstract class kolab_api_service
}
/**
+ * Parses input (for add/edit) attributes
+ *
+ * @param string $object_name Name of the object (user, group, etc.)
+ * @param array $attrs Entry attributes
+ *
+ * @return array Entry attributes
+ */
+ protected function parse_input_attributes($object_name, $attribs)
+ {
+ $type_attrs = $this->object_type_attributes($object_name, $attribs['type_id']);
+
+ //console("parse_input_attributes", $type_attrs);
+ //console("called with \$attribs", $attribs);
+
+ $form_service = $this->controller->get_service('form_value');
+
+ // With the result, start validating the input
+ $form_service->validate(null, $attribs);
+
+ $result = array();
+
+ if (isset($type_attrs['form_fields'])) {
+ foreach ($type_attrs['form_fields'] as $key => $value) {
+ //console("Running parse input attributes for key $key");
+
+ if (empty($attribs[$key]) && empty($value['optional'])) {
+ //console("\$attribs['" . $key . "'] is empty, and the field is not optional");
+ throw new Exception("Missing input value for $key", 345);
+ }
+ else {
+ //console("Either \$attribs['" . $key . "'] is empty or the field is optional");
+ $result[$key] = $attribs[$key];
+ }
+ }
+ }
+
+ if (isset($type_attrs['auto_form_fields'])) {
+ foreach ($type_attrs['auto_form_fields'] as $key => $value) {
+ if (empty($attribs[$key])) {
+ if (empty($value['optional'])) {
+ $attribs['attributes'] = array($key);
+ $res = $form_service->generate(null, $attribs);
+ $attribs[$key] = $res[$key];
+ $result[$key] = $attribs[$key];
+ }
+ } else {
+ $result[$key] = $attribs[$key];
+ }
+ }
+ }
+
+ if (isset($type_attrs['fields'])) {
+ foreach ($type_attrs['fields'] as $key => $value) {
+ if (empty($attribs[$key])) {
+ $result[$key] = $type_attrs['fields'][$key];
+ } else {
+ $result[$key] = $attribs[$key];
+ }
+ }
+ }
+
+ //console("parse_input_attributes result", $result);
+
+ return $result;
+ }
+
+ /**
* Parses result attributes
*
* @param string $object_name Name of the object (user, group, etc.)
@@ -278,67 +345,4 @@ abstract class kolab_api_service
return $attrs;
}
- /**
- * Parses input (for add/edit) attributes
- *
- * @param string $object_name Name of the object (user, group, etc.)
- * @param array $attrs Entry attributes
- *
- * @return array Entry attributes
- */
- protected function parse_input_attributes($object_name, $attribs)
- {
- $type_attrs = $this->object_type_attributes($object_name, $attribs['type_id']);
-
- //console("parse_input_attributes", $type_attrs);
- //console("called with \$attribs", $attribs);
-
- $form_service = $this->controller->get_service('form_value');
- $result = array();
-
- if (isset($type_attrs['form_fields'])) {
- foreach ($type_attrs['form_fields'] as $key => $value) {
- //console("Running parse input attributes for key $key");
-
- if (empty($attribs[$key]) && empty($value['optional'])) {
- //console("\$attribs['" . $key . "'] is empty, and the field is not optional");
- throw new Exception("Missing input value for $key", 345);
- }
- else {
- //console("Either \$attribs['" . $key . "'] is empty or the field is optional");
- $result[$key] = $attribs[$key];
- }
- }
- }
-
- if (isset($type_attrs['auto_form_fields'])) {
- foreach ($type_attrs['auto_form_fields'] as $key => $value) {
- if (empty($attribs[$key])) {
- if (empty($value['optional'])) {
- $attribs['attributes'] = array($key);
- $res = $form_service->generate(null, $attribs);
- $attribs[$key] = $res[$key];
- $result[$key] = $attribs[$key];
- }
- } else {
- $result[$key] = $attribs[$key];
- }
- }
- }
-
- if (isset($type_attrs['fields'])) {
- foreach ($type_attrs['fields'] as $key => $value) {
- if (empty($attribs[$key])) {
- $result[$key] = $type_attrs['fields'][$key];
- } else {
- $result[$key] = $attribs[$key];
- }
- }
- }
-
- //console("parse_input_attributes result", $result);
-
- return $result;
- }
-
}