1
|
|
|
<?php |
2
|
|
|
//------------------------------------------------------------------------- |
3
|
|
|
// OVIDENTIA http://www.ovidentia.org |
4
|
|
|
// Ovidentia is free software; you can redistribute it and/or modify |
5
|
|
|
// it under the terms of the GNU General Public License as published by |
6
|
|
|
// the Free Software Foundation; either version 2, or (at your option) |
7
|
|
|
// any later version. |
8
|
|
|
// |
9
|
|
|
// This program is distributed in the hope that it will be useful, but |
10
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12
|
|
|
// See the GNU General Public License for more details. |
13
|
|
|
// |
14
|
|
|
// You should have received a copy of the GNU General Public License |
15
|
|
|
// along with this program; if not, write to the Free Software |
16
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
17
|
|
|
// USA. |
18
|
|
|
//------------------------------------------------------------------------- |
19
|
|
|
/** |
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
21
|
|
|
* @copyright Copyright (c) 2006 by CANTICO ({@link http://www.cantico.fr}) |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Capwelton\LibApp\Ui; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Creates a generic form fragment for the specified set. |
28
|
|
|
* |
29
|
|
|
* @param ORMRecordSet $set |
30
|
|
|
* @return WidgetItem |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
use Capwelton\LibApp\Set\AppRecordSet; |
34
|
|
|
use Capwelton\Widgets\Widgets\Abstracts\WidgetBoxLayout; |
|
|
|
|
35
|
|
|
use Capwelton\Widgets\Widgets\Abstracts\WidgetInputWidget; |
|
|
|
|
36
|
|
|
use Capwelton\Widgets\Widgets\Abstracts\WidgetItem; |
|
|
|
|
37
|
|
|
use Capwelton\Widgets\Widgets\Form\WidgetCheckBox; |
|
|
|
|
38
|
|
|
use Capwelton\Widgets\Widgets\Interfaces\WidgetDisplayableInterface; |
|
|
|
|
39
|
|
|
use Capwelton\Widgets\Widgets\Helpers\WidgetSizePolicy; |
|
|
|
|
40
|
|
|
use Capwelton\Widgets\Widgets\Item\WidgetLabel; |
|
|
|
|
41
|
|
|
use Capwelton\LibOrm\ORMRecordSet; |
|
|
|
|
42
|
|
|
use Capwelton\LibOrm\Field\ORMDateField; |
|
|
|
|
43
|
|
|
use Capwelton\LibOrm\Field\ORMTimeField; |
|
|
|
|
44
|
|
|
use Capwelton\LibOrm\Field\ORMStringField; |
|
|
|
|
45
|
|
|
use Capwelton\LibOrm\Field\ORMEnumField; |
|
|
|
|
46
|
|
|
use Capwelton\LibOrm\Field\ORMIntField; |
|
|
|
|
47
|
|
|
use Capwelton\LibOrm\Field\ORMTextField; |
|
|
|
|
48
|
|
|
use Capwelton\LibOrm\MySql\ORMMySqlIterator; |
|
|
|
|
49
|
|
|
use Capwelton\LibOrm\Field\ORMField; |
|
|
|
|
50
|
|
|
use Capwelton\LibOrm\Field\ORMDatetimeField; |
|
|
|
|
51
|
|
|
use Capwelton\LibOrm\Field\ORMSetField; |
|
|
|
|
52
|
|
|
use Capwelton\LibOrm\Field\ORMUserField; |
|
|
|
|
53
|
|
|
use Capwelton\LibOrm\Field\ORMCurrencyField; |
|
|
|
|
54
|
|
|
use Capwelton\LibOrm\Field\ORMBoolField; |
|
|
|
|
55
|
|
|
use Capwelton\LibOrm\Field\ORMEmailField; |
|
|
|
|
56
|
|
|
use Capwelton\LibOrm\Field\ORMFileField; |
|
|
|
|
57
|
|
|
use Capwelton\LibOrm\Field\ORMPkField; |
|
|
|
|
58
|
|
|
use Capwelton\LibOrm\Field\ORMFkField; |
|
|
|
|
59
|
|
|
|
60
|
|
|
function app_genericSetEditor(ORMRecordSet $set) |
61
|
|
|
{ |
62
|
|
|
$O = \bab_functionality::get('LibOrm'); |
63
|
|
|
$O->init(); |
|
|
|
|
64
|
|
|
$W = \bab_Widgets(); |
65
|
|
|
$layout = $W->VBoxLayout(); |
66
|
|
|
$layout->setVerticalSpacing(1, 'em'); |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
$fields = $set->getFields(); |
70
|
|
|
|
71
|
|
|
foreach ($fields as $field) { |
72
|
|
|
$description = $field->getDescription(); |
73
|
|
|
if (empty($description)) { |
74
|
|
|
$description = $field->getName(); |
75
|
|
|
} |
76
|
|
|
$fieldLabel = $W->Label($description . ':'); |
77
|
|
|
|
78
|
|
|
if ($field instanceof ORMDateField) { |
79
|
|
|
$widget = $W->DatePicker(); |
80
|
|
|
} else if ($field instanceof ORMTimeField) { |
81
|
|
|
$widget = $W->LineEdit()->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); |
82
|
|
|
} else if ($field instanceof ORMStringField) { |
83
|
|
|
$widget = $W->LineEdit()->setSize(min(array(80, $field->getMaxLength()))); |
84
|
|
|
} else if ($field instanceof ORMEnumField) { |
85
|
|
|
$widget = $W->Select(); |
86
|
|
|
$widget->addOption('', ''); |
87
|
|
|
foreach ($field->getValues() as $key => $text) { |
88
|
|
|
$widget->addOption($key, $text); |
89
|
|
|
} |
90
|
|
|
} else if ($field instanceof ORMIntField) { |
91
|
|
|
$widget = $W->LineEdit()->setSize(9); |
92
|
|
|
} else if ($field instanceof ORMTextField) { |
93
|
|
|
$widget = $W->TextEdit()->setColumns(80)->setLines(5); |
94
|
|
|
} else if ($field instanceof ORMRecordSet) { |
95
|
|
|
$widget = app_genericSetEditor($field); |
96
|
|
|
$widget->addClass('sub-form'); |
97
|
|
|
} else { |
98
|
|
|
$widget = null; |
99
|
|
|
} |
100
|
|
|
if (isset($widget)) { |
101
|
|
|
$layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $layout; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Creates a generic form fragment for the specified set. |
112
|
|
|
* |
113
|
|
|
* @param ORMRecordSet $set |
114
|
|
|
* @return WidgetItem |
115
|
|
|
*/ |
116
|
|
|
function app_genericSetFilterForm(ORMRecordSet $set) |
117
|
|
|
{ |
118
|
|
|
$O = \bab_functionality::get('LibOrm'); |
119
|
|
|
$O->init(); |
120
|
|
|
$W = \bab_Widgets(); |
121
|
|
|
$layout = $W->FlowLayout(); |
122
|
|
|
$layout->setVerticalSpacing(1, 'em')->setHorizontalSpacing(1, 'em'); |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
$fields = $set->getFields(); |
126
|
|
|
|
127
|
|
|
foreach ($fields as $field) { |
128
|
|
|
$description = $field->getDescription(); |
129
|
|
|
if (empty($description)) { |
130
|
|
|
$description = $field->getName(); |
131
|
|
|
} |
132
|
|
|
$fieldLabel = $W->Label($description . ':'); |
133
|
|
|
|
134
|
|
|
if ($field instanceof ORMDateField) { |
135
|
|
|
$widget = $W->PeriodPicker(); |
136
|
|
|
} else if ($field instanceof ORMTimeField) { |
137
|
|
|
$widget = $W->TimePicker(); |
138
|
|
|
} else if ($field instanceof ORMStringField) { |
139
|
|
|
$widget = $W->LineEdit()->setSize(min(array(15, $field->getMaxLength()))); |
140
|
|
|
} else if ($field instanceof ORMEnumField) { |
141
|
|
|
$widget = $W->Select(); |
142
|
|
|
$widget->addOption('', ''); |
143
|
|
|
foreach ($field->getValues() as $key => $text) { |
144
|
|
|
$widget->addOption($key, $text); |
145
|
|
|
} |
146
|
|
|
} else if ($field instanceof ORMIntField) { |
147
|
|
|
$widget = $W->LineEdit()->setSize(9); |
148
|
|
|
} else if ($field instanceof ORMTextField) { |
149
|
|
|
$widget = $widget = $W->LineEdit()->setSize(15); |
|
|
|
|
150
|
|
|
} else if ($field instanceof ORMRecordSet) { |
151
|
|
|
$widget = app_genericSetFilterForm($field); |
152
|
|
|
$widget->addClass('sub-form'); |
153
|
|
|
} else { |
154
|
|
|
$widget = null; |
155
|
|
|
} |
156
|
|
|
if (isset($widget)) { |
157
|
|
|
$layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
return $layout; |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Associates a label to an input widget. |
167
|
|
|
* |
168
|
|
|
* @param string $labelText |
169
|
|
|
* @param WidgetInputWidget $widget |
170
|
|
|
* @return WidgetBoxLayout |
171
|
|
|
*/ |
172
|
|
|
function app_LabelledWidget($labelText, WidgetDisplayableInterface $widget) |
173
|
|
|
{ |
174
|
|
|
$W = \bab_Widgets(); |
175
|
|
|
|
176
|
|
|
$label = $W->Label($labelText); |
177
|
|
|
if ($widget instanceof WidgetInputWidget) { |
178
|
|
|
$label->setAssociatedWidget($widget); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if ($widget instanceof WidgetCheckBox) { |
182
|
|
|
$layout = $W->HBoxItems( |
183
|
|
|
$widget->setSizePolicy(WidgetSizePolicy::MINIMUM), |
184
|
|
|
$label |
185
|
|
|
)->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); |
|
|
|
|
186
|
|
|
} else { |
187
|
|
|
$layout = $W->VBoxItems( |
188
|
|
|
$label, |
189
|
|
|
$widget |
190
|
|
|
)->setVerticalSpacing(0.5, 'em'); |
|
|
|
|
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $layout; |
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
|
198
|
|
|
function app_LabelledCheckbox($labelText, $checkboxName, $options = null) |
199
|
|
|
{ |
200
|
|
|
$W = \bab_Widgets(); |
201
|
|
|
|
202
|
|
|
$label = $W->Label($labelText)->colon(false); |
203
|
|
|
$checkbox = $W->Checkbox()->setName($checkboxName); |
204
|
|
|
$label->setAssociatedWidget($checkbox); |
205
|
|
|
if (isset($options)) { |
206
|
|
|
$label->setSizePolicy(WidgetSizePolicy::FIXED)->setCanvasOptions($options); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
$layout = $W->HBoxItems( |
210
|
|
|
$checkbox->setSizePolicy(WidgetSizePolicy::MINIMUM), |
211
|
|
|
$label |
212
|
|
|
)->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); |
|
|
|
|
213
|
|
|
|
214
|
|
|
return $layout; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
|
219
|
|
|
|
220
|
|
|
function app_LabelledOrmSelect(ORMMySqlIterator $iterator, $fieldName, $selectName, $label, $hidden = false, $groupFieldName = null) |
221
|
|
|
{ |
222
|
|
|
$W = \bab_Widgets(); |
223
|
|
|
|
224
|
|
|
if (isset($groupFieldName)) { |
225
|
|
|
$groupPathElements = explode('/', $groupFieldName); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$select = $W->Select()->setName($selectName); |
229
|
|
|
|
230
|
|
|
$select->addOption('', ''); |
231
|
|
|
|
232
|
|
|
$nbOptions = 0; |
233
|
|
|
foreach ($iterator as $record) { |
234
|
|
|
if (isset($record->code)) { |
235
|
|
|
$optionText = $record->code . ' - ' . $record->$fieldName; |
236
|
|
|
} else { |
237
|
|
|
$optionText = $record->$fieldName; |
238
|
|
|
} |
239
|
|
|
if (isset($groupFieldName)) { |
240
|
|
|
$group = $record; |
241
|
|
|
foreach ($groupPathElements as $groupPathElement) { |
|
|
|
|
242
|
|
|
$group = $group->$groupPathElement; |
243
|
|
|
} |
244
|
|
|
$select->addOption($record->id, $optionText, $group); |
245
|
|
|
} else { |
246
|
|
|
$select->addOption($record->id, $optionText); |
247
|
|
|
} |
248
|
|
|
$nbOptions++; |
249
|
|
|
$lastId = $record->id; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
if ($nbOptions == 1) { |
253
|
|
|
$select->setValue($lastId); |
|
|
|
|
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
|
257
|
|
|
return app_LabelledWidget($label, $select); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
|
261
|
|
|
function app_OrmWidget(ORMField $field) |
262
|
|
|
{ |
263
|
|
|
$W = \bab_Widgets(); |
264
|
|
|
if ($field instanceof ORMDateField) { |
265
|
|
|
$widget = $W->DatePicker(); |
266
|
|
|
} else if ($field instanceof ORMTimeField) { |
267
|
|
|
$widget = $W->TimeEdit(); //->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); |
268
|
|
|
} else if ($field instanceof ORMDatetimeField) { |
269
|
|
|
$widget = $W->DateTimePicker(); //->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); |
270
|
|
|
} else if ($field instanceof ORMEnumField) { |
271
|
|
|
$widget = $W->Select(); |
272
|
|
|
//// $widget = $W->MultiSelect()->setSingleSelect(); |
273
|
|
|
$widget->addOption('', ''); |
274
|
|
|
$values = $field->getValues(); |
275
|
|
|
foreach ($values as $key => $value) { |
276
|
|
|
$widget->addOption($key, $value); |
277
|
|
|
} |
278
|
|
|
} else if ($field instanceof ORMSetField) { |
279
|
|
|
$widget = $W->MultiSelect()->setSelectedList(2); |
280
|
|
|
$values = $field->getValues(); |
281
|
|
|
foreach ($values as $key => $value) { |
282
|
|
|
$widget->addOption($key, $value); |
283
|
|
|
} |
284
|
|
|
} else if ($field instanceof ORMUserField) { |
285
|
|
|
$widget = $W->SuggestUser() |
286
|
|
|
->setMinChars(0) |
287
|
|
|
->setSizePolicy(\Func_Icons::ICON_LEFT_16); |
288
|
|
|
} else if ($field instanceof ORMCurrencyField) { |
289
|
|
|
$widget = $W->LineEdit()->setSize(6)->addClass('widget-input-currency'); |
290
|
|
|
} else if ($field instanceof ORMBoolField) { |
291
|
|
|
$widget = $W->CheckBox()->setCheckedValue('1'); |
292
|
|
|
} else if ($field instanceof ORMIntField) { |
293
|
|
|
$widget = $W->LineEdit() |
294
|
|
|
->setSize(6)->addClass('widget-input-numeric'); |
295
|
|
|
} else if ($field instanceof ORMEmailField) { |
296
|
|
|
$widget = $W->EmailLineEdit() |
297
|
|
|
->setMaxSize($field->getMaxLength()); |
298
|
|
|
} else if ($field instanceof ORMFileField) { |
299
|
|
|
$widget = $W->FilePicker(); |
300
|
|
|
} else if ($field instanceof ORMStringField) { |
301
|
|
|
$widget = $W->LineEdit() |
302
|
|
|
->setMaxSize($field->getMaxLength()); |
303
|
|
|
} else if ($field instanceof ORMTextField) { |
304
|
|
|
$widget = $W->TextEdit() |
305
|
|
|
->addClass('widget-autoresize'); |
306
|
|
|
} else if ($field instanceof ORMPkField) { |
307
|
|
|
$widget = $W->Hidden(); |
308
|
|
|
} else if ($field instanceof ORMFkField) { |
309
|
|
|
|
310
|
|
|
$fieldName = $field->getName(); |
311
|
|
|
/** @var AppRecordSet $parentSet */ |
312
|
|
|
$parentSet = clone $field->getParentSet(); |
313
|
|
|
$parentSet->join($fieldName); |
314
|
|
|
$set = $parentSet->$fieldName; |
315
|
|
|
$records = $set->select(); |
316
|
|
|
$pkName = $set->getPrimaryKey(); |
317
|
|
|
if($set->fieldExist("name")){ |
318
|
|
|
$displayField = $set->name->getName(); |
319
|
|
|
}else if(method_exists($set,"getDisplayNameField")){ |
320
|
|
|
$displayField = $set->getDisplayNameField()->getName(); |
321
|
|
|
}else{ |
322
|
|
|
$displayField = $pkName; |
323
|
|
|
} |
324
|
|
|
$records->orderAsc($set->$displayField); |
325
|
|
|
if($records->count() > 50){ |
326
|
|
|
$widget = bab_Widgets()->select2(); |
|
|
|
|
327
|
|
|
$widget->setDataSource($set->getController()->search()); |
328
|
|
|
}else{ |
329
|
|
|
$widget = $W->Select(); |
330
|
|
|
$widget->addOption('', ''); |
331
|
|
|
foreach ($records as $record) { |
332
|
|
|
$widget->addOption($record->$pkName, $record->$displayField); |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
} else if ($field instanceof ORMRecordSet) { |
336
|
|
|
$widget = $W->Select(); |
337
|
|
|
//// $widget = $W->MultiSelect()->setSingleSelect(); |
338
|
|
|
// $fieldName = $field->getName(); |
339
|
|
|
// $parentSet = $field->getParentSet(); |
340
|
|
|
// $parentSet->join($fieldName); |
341
|
|
|
// $set = $parentSet->$fieldName; |
342
|
|
|
$records = $field->select(); |
343
|
|
|
$records->orderAsc($field->name); |
344
|
|
|
$pkName = $field->getPrimaryKey(); |
345
|
|
|
$widget->addOption('', ''); |
346
|
|
|
foreach ($records as $record) { |
347
|
|
|
$widget->addOption($record->$pkName, $record->name); |
348
|
|
|
} |
349
|
|
|
} else { |
350
|
|
|
$widget = $W->LineEdit(); |
351
|
|
|
} |
352
|
|
|
$widget->setName($field->getName()); |
353
|
|
|
return $widget; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
|
357
|
|
|
|
358
|
|
|
function app_LabelledOrmWidget(ORMField $field, $label = null, $hidden = false) |
359
|
|
|
{ |
360
|
|
|
$W = \bab_Widgets(); |
361
|
|
|
|
362
|
|
|
if ($hidden) { |
363
|
|
|
$widget = $W->Hidden(); |
364
|
|
|
$widget->setName($field->getName()); |
365
|
|
|
return $widget; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
if (is_null($label)) { |
369
|
|
|
$label = $field->getDescription(); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
$widget = app_OrmWidget($field); |
373
|
|
|
|
374
|
|
|
return app_LabelledWidget($label, $widget); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
|
378
|
|
|
|
379
|
|
|
|
380
|
|
|
|
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* |
384
|
|
|
* |
385
|
|
|
* @param ORMField $field |
386
|
|
|
* @param string $value ISO date time |
387
|
|
|
*/ |
388
|
|
|
function app_dateTime(ORMField $field, $value) { |
389
|
|
|
|
390
|
|
|
$W = \bab_functionality::get('Widgets'); |
391
|
|
|
$name = $field->getName(); |
392
|
|
|
$label = $W->Label($field->getDescription()); |
|
|
|
|
393
|
|
|
|
394
|
|
|
$frame = app_dateTimeField($name, $label, $value); |
395
|
|
|
|
396
|
|
|
return $W->VBoxItems( |
|
|
|
|
397
|
|
|
$label, |
398
|
|
|
$frame |
399
|
|
|
); |
400
|
|
|
|
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* |
406
|
|
|
* |
407
|
|
|
* @param string $fieldName |
408
|
|
|
* @param WidgetLabel $label |
409
|
|
|
* @param string $value ISO date time |
410
|
|
|
*/ |
411
|
|
|
function app_dateTimeField($fieldName, WidgetLabel $label, $value = null) |
412
|
|
|
{ |
413
|
|
|
$W = \bab_functionality::get('Widgets'); |
414
|
|
|
|
415
|
|
|
$datepart = $W->DatePicker()->setAssociatedLabel($label)->setName('date'); |
|
|
|
|
416
|
|
|
$timepart = $W->TimePicker()->setName('time'); |
|
|
|
|
417
|
|
|
|
418
|
|
|
if (isset($value)) { |
419
|
|
|
|
420
|
|
|
$value = explode(' ', $value); |
421
|
|
|
|
422
|
|
|
$datepart->setValue($value[0]); |
423
|
|
|
$timepart->setValue($value[1]); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
$datetime = $W->Frame(null, $W->HBoxLayout())->setName($fieldName) |
|
|
|
|
427
|
|
|
->addItem($datepart) |
428
|
|
|
->addItem($timepart); |
429
|
|
|
|
430
|
|
|
return $datetime; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
|
434
|
|
|
|
435
|
|
|
|
436
|
|
|
|
437
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths