diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 1ff552bd0d80edd5d56242312e1cc8ff4dab00e2..4bed6b6fdb00f4273dd06264ccdaf20bd9be1b54 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -689,10 +689,12 @@ class DynamicFormEntry extends VerySimpleModel { return $ans; return null; } + function setAnswer($name, $value, $id=false) { foreach ($this->getAnswers() as $ans) { - if ($ans->getField()->get('name') == $name) { - $ans->getField()->reset(); + $f = $ans->getField(); + if ($f->isStorable() && $f->get('name') == $name) { + $f->reset(); $ans->set('value', $value); if ($id !== false) $ans->set('value_id', $id); @@ -907,18 +909,8 @@ class DynamicFormEntry extends VerySimpleModel { $this->_fields[] = $fImpl; $this->_form = null; - // Omit fields without data - // For user entries, the name and email fields should not be - // saved with the rest of the data - if ($this->object_type == 'U' - && in_array($field->get('name'), array('name','email'))) - continue; - - if ($this->object_type == 'O' - && in_array($field->get('name'), array('name'))) - continue; - - if (!$field->hasData()) + // Omit fields without data and non-storable fields. + if (!$field->hasData() || !$field->isStorable()) continue; $a->save(); @@ -937,15 +929,10 @@ class DynamicFormEntry extends VerySimpleModel { $this->set('updated', new SqlFunction('NOW')); parent::save(); foreach ($this->getFields() as $field) { - $a = $field->getAnswer(); - if ($this->object_type == 'U' - && in_array($field->get('name'), array('name','email'))) - continue; - - if ($this->object_type == 'O' - && in_array($field->get('name'), array('name'))) + if (!$field->isStorable()) continue; + $a = $field->getAnswer(); // Set the entry ID here so that $field->getClean() can use the // entry-id if necessary $a->set('entry_id', $this->get('id')); diff --git a/include/class.forms.php b/include/class.forms.php index e744f172cc41cd4b3cd073f659da8b2c1b888540..7cebfb42fabed8cb04bd9b7f6b8376d1e6c4ef49 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -397,6 +397,18 @@ class FormField { return (($this->get('edit_mask') & 32) == 0); } + /** + * isStorable + * + * Indicate if this field data is storable locally (default).Some field's data + * might beed to be stored elsewhere for optimization reasons at the + * application level. + * + */ + + function isStorable() { + return (($this->get('flags') & 2) == 0); + } /** * parse diff --git a/include/i18n/en_US/form.yaml b/include/i18n/en_US/form.yaml index b5bde9db9af53ae3189a77080db5085e649184cf..d8759c8fc57500485f266f28221a88f194ce2e33 100644 --- a/include/i18n/en_US/form.yaml +++ b/include/i18n/en_US/form.yaml @@ -15,6 +15,7 @@ # useful for page and email templates, where %{ ticket.<name> } # will be used to retrieve the data from the field. # hint: Help text shown with the field +# flags: Bit mask for settings & options # edit_mask: Mask out edits to the field (1=>delete, 2=>change name, # 4=>privacy setting, 8=>requirement setting) # private: True if the field should be hidden from the client @@ -36,6 +37,7 @@ label: Email Address required: true sort: 1 + flags: 3 edit_mask: 15 configuration: size: 40 @@ -46,6 +48,7 @@ label: Full Name required: true sort: 2 + flags: 3 edit_mask: 15 configuration: size: 40 @@ -55,6 +58,7 @@ label: Phone Number required: false sort: 3 + flags: 1 - type: memo # notrans name: notes label: Internal Notes @@ -81,6 +85,7 @@ required: true edit_mask: 15 sort: 1 + flags: 1 configuration: size: 40 length: 50 @@ -92,6 +97,7 @@ required: true edit_mask: 15 sort: 2 + flags: 3 - id: 22 type: priority # notrans name: priority # notrans @@ -100,6 +106,7 @@ private: true edit_mask: 3 sort: 3 + flags: 1 - type: C # notrans title: Company Information instructions: Details available in email templates @@ -110,6 +117,7 @@ label: Company Name required: true sort: 1 + flags: 1 edit_mask: 3 configuration: size: 40 @@ -118,6 +126,7 @@ name: website # notrans label: Website sort: 2 + flags: 1 configuration: size: 40 length: 64 @@ -126,6 +135,7 @@ label: Phone Number required: false sort: 3 + flags: 1 configuration: ext: false - type: memo # notrans @@ -133,6 +143,7 @@ label: Address required: false sort: 4 + flags: 1 configuration: rows: 2 cols: 40 @@ -148,6 +159,7 @@ label: Name required: true sort: 1 + flags: 3 edit_mask: 15 configuration: size: 40 @@ -157,6 +169,7 @@ label: Address required: false sort: 2 + flags: 1 configuration: rows: 2 cols: 40 @@ -167,11 +180,13 @@ label: Phone required: false sort: 3 + flags: 1 - type: text name: website label: Website required: false sort: 4 + flags: 1 configuration: size: 40 length: 0 @@ -180,6 +195,7 @@ label: Internal Notes required: false sort: 5 + flags: 1 configuration: rows: 4 cols: 40 diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql index b10118f2fb5dc49d4f42b74df3e0e5b01b147bc4..f32ff6d74962ad72ed72886ef9fcefb145d1e039 100644 --- a/setup/inc/streams/core/install-mysql.sql +++ b/setup/inc/streams/core/install-mysql.sql @@ -127,6 +127,7 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%form_field`; CREATE TABLE `%TABLE_PREFIX%form_field` ( `id` int(11) unsigned NOT NULL auto_increment, `form_id` int(11) unsigned NOT NULL, + `flags` int(10) unsigned DEFAULT 1, `type` varchar(255) NOT NULL DEFAULT 'text', `label` varchar(255) NOT NULL, `required` tinyint(1) NOT NULL DEFAULT 0,