@@ -46,72 +46,72 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @param Func_App $App |
| 48 | 48 | */ |
| 49 | - public function __construct(Func_App $App) |
|
| 50 | - { |
|
| 51 | - parent::__construct($App); |
|
| 52 | - |
|
| 53 | - $this->setDescription('Custom field'); |
|
| 54 | - |
|
| 55 | - $this->setPrimaryKey('id'); |
|
| 56 | - |
|
| 57 | - $this->addFields( |
|
| 58 | - ORM_StringField('name') |
|
| 59 | - ->setDescription('Name of field used for display'), |
|
| 60 | - ORM_StringField('fieldname') |
|
| 61 | - ->setDescription('Name of field used in table, not modifiable'), |
|
| 62 | - ORM_TextField('description') |
|
| 63 | - ->setDescription('Optional description'), |
|
| 64 | - ORM_EnumField('object', $this->getObjects()) |
|
| 65 | - ->setDescription('Name of object in App ex : Article, Contact, Organization...'), |
|
| 66 | - ORM_EnumField('fieldtype', $this->getFieldTypes()) |
|
| 67 | - ->setDescription('Name of ORM field ex : Enum, String, Text, Bool...'), |
|
| 68 | - ORM_TextField('enumvalues') |
|
| 69 | - ->setDescription('serialized array of values for enum fields'), |
|
| 70 | - ORM_BoolField('mandatory') |
|
| 71 | - ->setDescription('Mandatory') |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * List of objects where custom fields are applicable. |
|
| 79 | - * |
|
| 80 | - * @return string[] |
|
| 81 | - */ |
|
| 82 | - public function getObjects() |
|
| 83 | - { |
|
| 84 | - $App = $this->App(); |
|
| 85 | - |
|
| 86 | - $arr = array(); |
|
| 87 | - |
|
| 88 | - if (isset($App->Article)) { |
|
| 89 | - $arr['Article'] = $App->translate('Products database'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $arr; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * list of ORM fields to use for a custom field |
|
| 97 | - */ |
|
| 98 | - public function getFieldTypes() |
|
| 99 | - { |
|
| 100 | - $App = $this->App(); |
|
| 101 | - |
|
| 102 | - return array( |
|
| 103 | - 'String' => $App->translate('Line edit'), |
|
| 104 | - 'Text' => $App->translate('Text edit'), |
|
| 105 | - 'Bool' => $App->translate('Checkbox'), |
|
| 106 | - 'Int' => $App->translate('Integer number'), |
|
| 107 | - 'Decimal' => $App->translate('Decimal number'), |
|
| 108 | - 'Date' => $App->translate('Date'), |
|
| 109 | - 'DateTime' => $App->translate('Date and time'), |
|
| 110 | - 'Enum' => $App->translate('Selection list'), |
|
| 111 | - 'Url' => $App->translate('Url'), |
|
| 112 | - 'Email' => $App->translate('Email address'), |
|
| 113 | - ); |
|
| 114 | - } |
|
| 49 | + public function __construct(Func_App $App) |
|
| 50 | + { |
|
| 51 | + parent::__construct($App); |
|
| 52 | + |
|
| 53 | + $this->setDescription('Custom field'); |
|
| 54 | + |
|
| 55 | + $this->setPrimaryKey('id'); |
|
| 56 | + |
|
| 57 | + $this->addFields( |
|
| 58 | + ORM_StringField('name') |
|
| 59 | + ->setDescription('Name of field used for display'), |
|
| 60 | + ORM_StringField('fieldname') |
|
| 61 | + ->setDescription('Name of field used in table, not modifiable'), |
|
| 62 | + ORM_TextField('description') |
|
| 63 | + ->setDescription('Optional description'), |
|
| 64 | + ORM_EnumField('object', $this->getObjects()) |
|
| 65 | + ->setDescription('Name of object in App ex : Article, Contact, Organization...'), |
|
| 66 | + ORM_EnumField('fieldtype', $this->getFieldTypes()) |
|
| 67 | + ->setDescription('Name of ORM field ex : Enum, String, Text, Bool...'), |
|
| 68 | + ORM_TextField('enumvalues') |
|
| 69 | + ->setDescription('serialized array of values for enum fields'), |
|
| 70 | + ORM_BoolField('mandatory') |
|
| 71 | + ->setDescription('Mandatory') |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * List of objects where custom fields are applicable. |
|
| 79 | + * |
|
| 80 | + * @return string[] |
|
| 81 | + */ |
|
| 82 | + public function getObjects() |
|
| 83 | + { |
|
| 84 | + $App = $this->App(); |
|
| 85 | + |
|
| 86 | + $arr = array(); |
|
| 87 | + |
|
| 88 | + if (isset($App->Article)) { |
|
| 89 | + $arr['Article'] = $App->translate('Products database'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $arr; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * list of ORM fields to use for a custom field |
|
| 97 | + */ |
|
| 98 | + public function getFieldTypes() |
|
| 99 | + { |
|
| 100 | + $App = $this->App(); |
|
| 101 | + |
|
| 102 | + return array( |
|
| 103 | + 'String' => $App->translate('Line edit'), |
|
| 104 | + 'Text' => $App->translate('Text edit'), |
|
| 105 | + 'Bool' => $App->translate('Checkbox'), |
|
| 106 | + 'Int' => $App->translate('Integer number'), |
|
| 107 | + 'Decimal' => $App->translate('Decimal number'), |
|
| 108 | + 'Date' => $App->translate('Date'), |
|
| 109 | + 'DateTime' => $App->translate('Date and time'), |
|
| 110 | + 'Enum' => $App->translate('Selection list'), |
|
| 111 | + 'Url' => $App->translate('Url'), |
|
| 112 | + 'Email' => $App->translate('Email address'), |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * @return ORM_Criteria |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | case 'Bool': |
| 176 | 176 | $field = ORM_BoolField($this->fieldname); |
| 177 | 177 | $field->setOutputOptions( |
| 178 | - $this->App()->translate('No'), |
|
| 178 | + $this->App()->translate('No'), |
|
| 179 | 179 | $this->App()->translate('Yes') |
| 180 | 180 | ); |
| 181 | 181 | break; |
@@ -192,80 +192,80 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * @return string[] |
|
| 197 | - */ |
|
| 198 | - public function getEnumValues() |
|
| 199 | - { |
|
| 200 | - return unserialize($this->enumvalues); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @return Widget_LabelledWidget |
|
| 206 | - */ |
|
| 207 | - public function getWidget() |
|
| 208 | - { |
|
| 209 | - $W = bab_Widgets(); |
|
| 210 | - $App = $this->App(); |
|
| 211 | - |
|
| 212 | - switch ($this->fieldtype) { |
|
| 213 | - case 'Text': |
|
| 214 | - $widget = $W->TextEdit()->setLines(3)->setColumns(70); |
|
| 215 | - break; |
|
| 216 | - |
|
| 217 | - case 'Bool': |
|
| 218 | - $widget = $W->Checkbox(); |
|
| 219 | - break; |
|
| 220 | - |
|
| 221 | - case 'Enum': |
|
| 222 | - $options = array('' => '') + $this->getEnumValues(); |
|
| 223 | - $widget = $W->Select()->setOptions($options); |
|
| 224 | - break; |
|
| 225 | - |
|
| 226 | - case 'Date': |
|
| 227 | - $widget = $W->DatePicker(); |
|
| 228 | - break; |
|
| 229 | - |
|
| 230 | - case 'DateTime': |
|
| 231 | - $widget = $W->DateTimePicker(); |
|
| 232 | - break; |
|
| 233 | - |
|
| 234 | - case 'Int': |
|
| 235 | - $widget = $W->RegExpLineEdit(); |
|
| 236 | - $widget->setRegExp(Widget_RegExpLineEdit::INT_FORMAT) |
|
| 237 | - ->setSubmitMessage(sprintf($App->translate('The field %s should be a integer number'), $this->name)) |
|
| 238 | - ->setSize(10); |
|
| 239 | - break; |
|
| 240 | - |
|
| 241 | - case 'Decimal': |
|
| 242 | - $widget = $W->RegExpLineEdit(); |
|
| 243 | - $widget->setRegExp(Widget_RegExpLineEdit::FLOAT_FORMAT) |
|
| 244 | - ->setSubmitMessage(sprintf($App->translate('The field %s should be a decimal number'), $this->name)) |
|
| 245 | - ->setSize(10); |
|
| 246 | - break; |
|
| 247 | - |
|
| 248 | - case 'Url': |
|
| 249 | - $widget = $W->UrlLineEdit(); |
|
| 250 | - break; |
|
| 251 | - |
|
| 252 | - case 'Email': |
|
| 253 | - $widget = $W->EmailLineEdit(); |
|
| 254 | - break; |
|
| 255 | - |
|
| 256 | - default: |
|
| 257 | - case 'String': |
|
| 258 | - $widget = $W->LineEdit()->setSize(70)->setMaxSize(255); |
|
| 259 | - break; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - $labelledItem = $W->LabelledWidget($this->name, $widget, null); |
|
| 263 | - $labelledItem->setName($this->fieldname); |
|
| 264 | - |
|
| 265 | - if (!empty($this->description)) { |
|
| 266 | - $labelledItem->setDescription($this->description); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - return $labelledItem; |
|
| 270 | - } |
|
| 195 | + /** |
|
| 196 | + * @return string[] |
|
| 197 | + */ |
|
| 198 | + public function getEnumValues() |
|
| 199 | + { |
|
| 200 | + return unserialize($this->enumvalues); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @return Widget_LabelledWidget |
|
| 206 | + */ |
|
| 207 | + public function getWidget() |
|
| 208 | + { |
|
| 209 | + $W = bab_Widgets(); |
|
| 210 | + $App = $this->App(); |
|
| 211 | + |
|
| 212 | + switch ($this->fieldtype) { |
|
| 213 | + case 'Text': |
|
| 214 | + $widget = $W->TextEdit()->setLines(3)->setColumns(70); |
|
| 215 | + break; |
|
| 216 | + |
|
| 217 | + case 'Bool': |
|
| 218 | + $widget = $W->Checkbox(); |
|
| 219 | + break; |
|
| 220 | + |
|
| 221 | + case 'Enum': |
|
| 222 | + $options = array('' => '') + $this->getEnumValues(); |
|
| 223 | + $widget = $W->Select()->setOptions($options); |
|
| 224 | + break; |
|
| 225 | + |
|
| 226 | + case 'Date': |
|
| 227 | + $widget = $W->DatePicker(); |
|
| 228 | + break; |
|
| 229 | + |
|
| 230 | + case 'DateTime': |
|
| 231 | + $widget = $W->DateTimePicker(); |
|
| 232 | + break; |
|
| 233 | + |
|
| 234 | + case 'Int': |
|
| 235 | + $widget = $W->RegExpLineEdit(); |
|
| 236 | + $widget->setRegExp(Widget_RegExpLineEdit::INT_FORMAT) |
|
| 237 | + ->setSubmitMessage(sprintf($App->translate('The field %s should be a integer number'), $this->name)) |
|
| 238 | + ->setSize(10); |
|
| 239 | + break; |
|
| 240 | + |
|
| 241 | + case 'Decimal': |
|
| 242 | + $widget = $W->RegExpLineEdit(); |
|
| 243 | + $widget->setRegExp(Widget_RegExpLineEdit::FLOAT_FORMAT) |
|
| 244 | + ->setSubmitMessage(sprintf($App->translate('The field %s should be a decimal number'), $this->name)) |
|
| 245 | + ->setSize(10); |
|
| 246 | + break; |
|
| 247 | + |
|
| 248 | + case 'Url': |
|
| 249 | + $widget = $W->UrlLineEdit(); |
|
| 250 | + break; |
|
| 251 | + |
|
| 252 | + case 'Email': |
|
| 253 | + $widget = $W->EmailLineEdit(); |
|
| 254 | + break; |
|
| 255 | + |
|
| 256 | + default: |
|
| 257 | + case 'String': |
|
| 258 | + $widget = $W->LineEdit()->setSize(70)->setMaxSize(255); |
|
| 259 | + break; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + $labelledItem = $W->LabelledWidget($this->name, $widget, null); |
|
| 263 | + $labelledItem->setName($this->fieldname); |
|
| 264 | + |
|
| 265 | + if (!empty($this->description)) { |
|
| 266 | + $labelledItem->setDescription($this->description); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + return $labelledItem; |
|
| 270 | + } |
|
| 271 | 271 | } |