Skip to content
Snippets Groups Projects
Commit 1da5e2eb authored by Peter Rotich's avatar Peter Rotich Committed by Jared Hancock
Browse files

forms: Add flags field to form field.

This is necessary so we can consolidate various settings and permissions
into one bit mask field.
parent 1561ce20
Branches
Tags
No related merge requests found
...@@ -689,10 +689,12 @@ class DynamicFormEntry extends VerySimpleModel { ...@@ -689,10 +689,12 @@ class DynamicFormEntry extends VerySimpleModel {
return $ans; return $ans;
return null; return null;
} }
function setAnswer($name, $value, $id=false) { function setAnswer($name, $value, $id=false) {
foreach ($this->getAnswers() as $ans) { foreach ($this->getAnswers() as $ans) {
if ($ans->getField()->get('name') == $name) { $f = $ans->getField();
$ans->getField()->reset(); if ($f->isStorable() && $f->get('name') == $name) {
$f->reset();
$ans->set('value', $value); $ans->set('value', $value);
if ($id !== false) if ($id !== false)
$ans->set('value_id', $id); $ans->set('value_id', $id);
...@@ -907,18 +909,8 @@ class DynamicFormEntry extends VerySimpleModel { ...@@ -907,18 +909,8 @@ class DynamicFormEntry extends VerySimpleModel {
$this->_fields[] = $fImpl; $this->_fields[] = $fImpl;
$this->_form = null; $this->_form = null;
// Omit fields without data // Omit fields without data and non-storable fields.
// For user entries, the name and email fields should not be if (!$field->hasData() || !$field->isStorable())
// 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())
continue; continue;
$a->save(); $a->save();
...@@ -937,15 +929,10 @@ class DynamicFormEntry extends VerySimpleModel { ...@@ -937,15 +929,10 @@ class DynamicFormEntry extends VerySimpleModel {
$this->set('updated', new SqlFunction('NOW')); $this->set('updated', new SqlFunction('NOW'));
parent::save(); parent::save();
foreach ($this->getFields() as $field) { foreach ($this->getFields() as $field) {
$a = $field->getAnswer(); if (!$field->isStorable())
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; continue;
$a = $field->getAnswer();
// Set the entry ID here so that $field->getClean() can use the // Set the entry ID here so that $field->getClean() can use the
// entry-id if necessary // entry-id if necessary
$a->set('entry_id', $this->get('id')); $a->set('entry_id', $this->get('id'));
......
...@@ -397,6 +397,18 @@ class FormField { ...@@ -397,6 +397,18 @@ class FormField {
return (($this->get('edit_mask') & 32) == 0); 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 * parse
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# useful for page and email templates, where %{ ticket.<name> } # useful for page and email templates, where %{ ticket.<name> }
# will be used to retrieve the data from the field. # will be used to retrieve the data from the field.
# hint: Help text shown with 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, # edit_mask: Mask out edits to the field (1=>delete, 2=>change name,
# 4=>privacy setting, 8=>requirement setting) # 4=>privacy setting, 8=>requirement setting)
# private: True if the field should be hidden from the client # private: True if the field should be hidden from the client
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
label: Email Address label: Email Address
required: true required: true
sort: 1 sort: 1
flags: 3
edit_mask: 15 edit_mask: 15
configuration: configuration:
size: 40 size: 40
...@@ -46,6 +48,7 @@ ...@@ -46,6 +48,7 @@
label: Full Name label: Full Name
required: true required: true
sort: 2 sort: 2
flags: 3
edit_mask: 15 edit_mask: 15
configuration: configuration:
size: 40 size: 40
...@@ -55,6 +58,7 @@ ...@@ -55,6 +58,7 @@
label: Phone Number label: Phone Number
required: false required: false
sort: 3 sort: 3
flags: 1
- type: memo # notrans - type: memo # notrans
name: notes name: notes
label: Internal Notes label: Internal Notes
...@@ -81,6 +85,7 @@ ...@@ -81,6 +85,7 @@
required: true required: true
edit_mask: 15 edit_mask: 15
sort: 1 sort: 1
flags: 1
configuration: configuration:
size: 40 size: 40
length: 50 length: 50
...@@ -92,6 +97,7 @@ ...@@ -92,6 +97,7 @@
required: true required: true
edit_mask: 15 edit_mask: 15
sort: 2 sort: 2
flags: 3
- id: 22 - id: 22
type: priority # notrans type: priority # notrans
name: priority # notrans name: priority # notrans
...@@ -100,6 +106,7 @@ ...@@ -100,6 +106,7 @@
private: true private: true
edit_mask: 3 edit_mask: 3
sort: 3 sort: 3
flags: 1
- type: C # notrans - type: C # notrans
title: Company Information title: Company Information
instructions: Details available in email templates instructions: Details available in email templates
...@@ -110,6 +117,7 @@ ...@@ -110,6 +117,7 @@
label: Company Name label: Company Name
required: true required: true
sort: 1 sort: 1
flags: 1
edit_mask: 3 edit_mask: 3
configuration: configuration:
size: 40 size: 40
...@@ -118,6 +126,7 @@ ...@@ -118,6 +126,7 @@
name: website # notrans name: website # notrans
label: Website label: Website
sort: 2 sort: 2
flags: 1
configuration: configuration:
size: 40 size: 40
length: 64 length: 64
...@@ -126,6 +135,7 @@ ...@@ -126,6 +135,7 @@
label: Phone Number label: Phone Number
required: false required: false
sort: 3 sort: 3
flags: 1
configuration: configuration:
ext: false ext: false
- type: memo # notrans - type: memo # notrans
...@@ -133,6 +143,7 @@ ...@@ -133,6 +143,7 @@
label: Address label: Address
required: false required: false
sort: 4 sort: 4
flags: 1
configuration: configuration:
rows: 2 rows: 2
cols: 40 cols: 40
...@@ -148,6 +159,7 @@ ...@@ -148,6 +159,7 @@
label: Name label: Name
required: true required: true
sort: 1 sort: 1
flags: 3
edit_mask: 15 edit_mask: 15
configuration: configuration:
size: 40 size: 40
...@@ -157,6 +169,7 @@ ...@@ -157,6 +169,7 @@
label: Address label: Address
required: false required: false
sort: 2 sort: 2
flags: 1
configuration: configuration:
rows: 2 rows: 2
cols: 40 cols: 40
...@@ -167,11 +180,13 @@ ...@@ -167,11 +180,13 @@
label: Phone label: Phone
required: false required: false
sort: 3 sort: 3
flags: 1
- type: text - type: text
name: website name: website
label: Website label: Website
required: false required: false
sort: 4 sort: 4
flags: 1
configuration: configuration:
size: 40 size: 40
length: 0 length: 0
...@@ -180,6 +195,7 @@ ...@@ -180,6 +195,7 @@
label: Internal Notes label: Internal Notes
required: false required: false
sort: 5 sort: 5
flags: 1
configuration: configuration:
rows: 4 rows: 4
cols: 40 cols: 40
...@@ -127,6 +127,7 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%form_field`; ...@@ -127,6 +127,7 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%form_field`;
CREATE TABLE `%TABLE_PREFIX%form_field` ( CREATE TABLE `%TABLE_PREFIX%form_field` (
`id` int(11) unsigned NOT NULL auto_increment, `id` int(11) unsigned NOT NULL auto_increment,
`form_id` int(11) unsigned NOT NULL, `form_id` int(11) unsigned NOT NULL,
`flags` int(10) unsigned DEFAULT 1,
`type` varchar(255) NOT NULL DEFAULT 'text', `type` varchar(255) NOT NULL DEFAULT 'text',
`label` varchar(255) NOT NULL, `label` varchar(255) NOT NULL,
`required` tinyint(1) NOT NULL DEFAULT 0, `required` tinyint(1) NOT NULL DEFAULT 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment