1
|
|
|
<?php |
2
|
|
|
/************************************************************************ |
3
|
|
|
* OVIDENTIA http://www.ovidentia.org * |
4
|
|
|
************************************************************************ |
5
|
|
|
* Copyright (c) 2003 by CANTICO ( http://www.cantico.fr ) * |
6
|
|
|
* * |
7
|
|
|
* This file is part of Ovidentia. * |
8
|
|
|
* * |
9
|
|
|
* Ovidentia is free software; you can redistribute it and/or modify * |
10
|
|
|
* it under the terms of the GNU General Public License as published by * |
11
|
|
|
* the Free Software Foundation; either version 2, or (at your option) * |
12
|
|
|
* any later version. * |
13
|
|
|
* * |
14
|
|
|
* This program is distributed in the hope that it will be useful, but * |
15
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
17
|
|
|
* See the GNU General Public License for more details. * |
18
|
|
|
* * |
19
|
|
|
* You should have received a copy of the GNU General Public License * |
20
|
|
|
* along with this program; if not, write to the Free Software * |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,* |
22
|
|
|
* USA. * |
23
|
|
|
************************************************************************/ |
24
|
|
|
|
25
|
|
|
bab_Widgets()->includePhpClass('Widget_Form'); |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class absences_WorkperiodRecoverRequestEditor extends Widget_Form |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var absences_WorkperiodRecoverRequest |
32
|
|
|
*/ |
33
|
|
|
protected $workperiod; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
protected $withCardFrame; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Display the quantity field |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
protected $quantityField; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* |
49
|
|
|
* @param absences_WorkperiodRecoverRequest $wd |
50
|
|
|
* @param bool $withCardFrame Display the appliquant card frame (approval, manager) |
51
|
|
|
* @param bool $quantityField Display the quantity field (approval, manager) |
52
|
|
|
*/ |
53
|
|
|
public function __construct(absences_WorkperiodRecoverRequest $wd = null, $withCardFrame = null, $quantityField = null) |
54
|
|
|
{ |
55
|
|
|
$W = bab_Widgets(); |
56
|
|
|
|
57
|
|
|
$this->workperiod = $wd; |
58
|
|
|
|
59
|
|
|
$this->withCardFrame = isset($withCardFrame) ? $withCardFrame : isset($wd); |
60
|
|
|
$this->quantityField = isset($quantityField) ? $quantityField : isset($wd); |
61
|
|
|
|
62
|
|
|
parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(2,'em')); |
63
|
|
|
|
64
|
|
|
bab_functionality::includefile('Icons'); |
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
$this->setName('workperiod'); |
68
|
|
|
$this->addClass('widget-bordered'); |
69
|
|
|
$this->addClass('BabLoginMenuBackground'); |
70
|
|
|
$this->addClass('widget-centered'); |
71
|
|
|
$this->addClass(Func_Icons::ICON_LEFT_24); |
72
|
|
|
$this->colon(); |
73
|
|
|
|
74
|
|
|
$this->setCanvasOptions($this->Options()->width(60,'em')); |
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->addFields(); |
80
|
|
|
$this->addButtons(); |
81
|
|
|
$this->setSelfPageHiddenFields(); |
82
|
|
|
$this->loadValues(); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
protected function loadValues() |
88
|
|
|
{ |
89
|
|
|
if (isset($_POST['workperiod'])) |
90
|
|
|
{ |
91
|
|
|
$this->setValues(array('workperiod' => $_POST['workperiod'])); |
92
|
|
|
|
93
|
|
|
if (isset($_POST['workperiod']['id'])) |
94
|
|
|
{ |
95
|
|
|
$this->setHiddenValue('workperiod[id]', $_POST['workperiod']['id']); |
96
|
|
|
} |
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if (isset($this->workperiod)) |
101
|
|
|
{ |
102
|
|
|
$values = $this->workperiod->getRow(); |
103
|
|
|
if (isset($values['date_begin'])) { |
104
|
|
|
$values['datebegin'] = mb_substr($values['date_begin'], 0, 10); |
105
|
|
|
$values['hourbegin'] = mb_substr($values['date_begin'], 11); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if (isset($values['date_end'])) { |
109
|
|
|
$values['dateend'] = mb_substr($values['date_end'], 0, 10); |
110
|
|
|
$values['hourend'] = mb_substr($values['date_end'], 11); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$this->setValues(array('workperiod' => $values)); |
114
|
|
|
|
115
|
|
|
if (isset($values['id_user'])) { |
116
|
|
|
$this->setHiddenValue('workperiod[id_user]', $values['id_user']); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if (isset($values['id'])) { |
120
|
|
|
$this->setHiddenValue('workperiod[id]', $values['id']); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
protected function addFields() |
128
|
|
|
{ |
129
|
|
|
$W = bab_Widgets(); |
130
|
|
|
|
131
|
|
|
if (isset($this->workperiod) && $this->withCardFrame) |
132
|
|
|
{ |
133
|
|
|
require_once dirname(__FILE__).'/agent.class.php'; |
134
|
|
|
require_once dirname(__FILE__).'/agent.ui.php'; |
135
|
|
|
|
136
|
|
|
$agent = absences_Agent::getFromIdUser($this->workperiod->id_user); |
137
|
|
|
$cardFrame = new absences_AgentCardFrame($agent); |
138
|
|
|
$this->addItem($cardFrame); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$this->addItem($this->period()); |
142
|
|
|
$this->addItem($this->id_type()); |
143
|
|
|
|
144
|
|
|
if ($this->quantityField) |
145
|
|
|
{ |
146
|
|
|
if ($this->workperiod->status === '') |
147
|
|
|
{ |
148
|
|
|
// waiting request |
149
|
|
|
$this->addItem($this->quantity()); |
150
|
|
|
} else { |
151
|
|
|
|
152
|
|
|
// confirmed or rejected |
153
|
|
|
$this->addItem( |
154
|
|
|
$W->Label( |
155
|
|
|
sprintf( |
156
|
|
|
absences_translate('Quantity used in the recovery creation : %s'), |
157
|
|
|
absences_quantity($this->workperiod->quantity, $this->workperiod->quantity_unit) |
158
|
|
|
) |
159
|
|
|
) |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$this->addItem($this->comment()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
View Code Duplication |
protected function id_type() |
|
|
|
|
169
|
|
|
{ |
170
|
|
|
$W = bab_Widgets(); |
171
|
|
|
$select = $W->Select(); |
172
|
|
|
|
173
|
|
|
require_once dirname(__FILE__).'/workperiod_type.class.php'; |
174
|
|
|
|
175
|
|
|
$I = new absences_WorkperiodTypeIterator; |
176
|
|
|
foreach($I as $workperiodType) |
177
|
|
|
{ |
178
|
|
|
$select->addOption($workperiodType->id, $workperiodType->name); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $W->LabelledWidget(absences_translate('Working day type'), $select, __FUNCTION__); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* quantity & quantity_unit |
187
|
|
|
* @return Widget_FlowLayout |
188
|
|
|
*/ |
189
|
|
View Code Duplication |
protected function quantity() |
|
|
|
|
190
|
|
|
{ |
191
|
|
|
$W = bab_Widgets(); |
192
|
|
|
|
193
|
|
|
$lineedit = $W->LineEdit()->setSize(2)->setMaxSize(5)->setMandatory(true, absences_translate('The quantity is mandatory'))->setName('quantity'); |
194
|
|
|
$select = $W->Select()->setName('quantity_unit') |
195
|
|
|
->addOption('D', absences_translate('Day(s)')) |
196
|
|
|
->addOption('H', absences_translate('Hour(s)')); |
197
|
|
|
|
198
|
|
|
return $W->VBoxItems( |
199
|
|
|
$W->Label(absences_translate('Quantity'))->setAssociatedWidget($lineedit)->addClass('widget-strong'), |
200
|
|
|
$W->FlowItems($lineedit, $select) |
201
|
|
|
)->setVerticalSpacing(.2,'em'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
|
206
|
|
View Code Duplication |
protected function comment() |
|
|
|
|
207
|
|
|
{ |
208
|
|
|
$W = bab_Widgets(); |
209
|
|
|
|
210
|
|
|
return $W->LabelledWidget( |
211
|
|
|
absences_translate('Reason for the request'), |
212
|
|
|
$W->TextEdit()->setColumns(80)->setLines(5)->setMandatory(true, absences_translate('The reason is mandatory')), |
213
|
|
|
__FUNCTION__ |
214
|
|
|
); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* |
220
|
|
|
* @return Widget_VBoxLayout |
221
|
|
|
*/ |
222
|
|
View Code Duplication |
protected function period() |
|
|
|
|
223
|
|
|
{ |
224
|
|
|
$W = bab_Widgets(); |
225
|
|
|
|
226
|
|
|
return $W->VBoxItems( |
227
|
|
|
$W->Label(absences_translate('Worked period')), |
228
|
|
|
$W->FlowItems($this->date_begin(), $this->date_end()) |
229
|
|
|
)->setVerticalSpacing(1,'em'); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
View Code Duplication |
protected function date_begin() |
|
|
|
|
234
|
|
|
{ |
235
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
236
|
|
|
|
237
|
|
|
$delay = BAB_DateTime::now(); |
238
|
|
|
$delay->add(absences_getVacationOption('delay_recovery'), BAB_DATETIME_DAY); |
239
|
|
|
|
240
|
|
|
$W = bab_Widgets(); |
241
|
|
|
$date = $W->DatePicker()->setMaxDate($delay)->setMandatory(true)->setName('datebegin'); |
242
|
|
|
$hours = $W->Select()->setName('hourbegin')->setOptions(absences_hoursList()); |
243
|
|
|
|
244
|
|
|
$this->beginDate = $date; |
|
|
|
|
245
|
|
|
|
246
|
|
|
return $W->FlowItems( |
247
|
|
|
$W->Label(absences_translate('from date'))->setAssociatedWidget($date), |
248
|
|
|
$date, |
249
|
|
|
$hours |
250
|
|
|
)->setSpacing(.5,'em'); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
|
254
|
|
View Code Duplication |
protected function date_end() |
|
|
|
|
255
|
|
|
{ |
256
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
257
|
|
|
|
258
|
|
|
$delay = BAB_DateTime::now(); |
259
|
|
|
$delay->add(absences_getVacationOption('delay_recovery'), BAB_DATETIME_DAY); |
260
|
|
|
|
261
|
|
|
$W = bab_Widgets(); |
262
|
|
|
$date = $W->DatePicker()->setMinDate($this->beginDate)->setMaxDate($delay)->setMandatory(true)->setName('dateend'); |
263
|
|
|
$hours = $W->Select()->setName('hourend')->setOptions(absences_hoursList()); |
264
|
|
|
|
265
|
|
|
return $W->FlowItems( |
266
|
|
|
$W->Label(absences_translate('to date'))->setAssociatedWidget($date), |
267
|
|
|
$date, |
268
|
|
|
$hours |
269
|
|
|
)->setSpacing(.5,'em'); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
|
273
|
|
|
|
274
|
|
View Code Duplication |
protected function addButtons() |
|
|
|
|
275
|
|
|
{ |
276
|
|
|
$W = bab_Widgets(); |
277
|
|
|
|
278
|
|
|
$button = $W->FlowItems( |
279
|
|
|
$W->SubmitButton()->setName('cancel')->setLabel(absences_translate('Cancel')), |
280
|
|
|
$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save'))->validate() |
281
|
|
|
)->setSpacing(1,'em'); |
282
|
|
|
|
283
|
|
|
$this->addItem($button); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
|
290
|
|
|
|
291
|
|
|
|
292
|
|
|
|
293
|
|
|
class absences_WorkperiodRecoverApprobEditor extends absences_WorkperiodRecoverRequestEditor { |
294
|
|
|
|
295
|
|
|
|
296
|
|
|
public function __construct(absences_WorkperiodRecoverRequest $workperiod) |
297
|
|
|
{ |
298
|
|
|
|
299
|
|
|
parent::__construct($workperiod); |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Load values into editor |
306
|
|
|
* |
307
|
|
|
*/ |
308
|
|
View Code Duplication |
protected function loadValues() |
|
|
|
|
309
|
|
|
{ |
310
|
|
|
if (isset($_POST['workperiod'])) |
311
|
|
|
{ |
312
|
|
|
$this->setValues(array('workperiod' => $_POST['workperiod'])); |
313
|
|
|
} else { |
314
|
|
|
if (isset($this->workperiod)) |
315
|
|
|
{ |
316
|
|
|
$this->setValues(array('workperiod' => $this->workperiod->getRow())); |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
if (isset($this->workperiod)) |
321
|
|
|
{ |
322
|
|
|
$this->setHiddenValue('workperiod[id]', $this->workperiod->id); |
323
|
|
|
$this->setHiddenValue('id_workperiod', $this->workperiod->id); |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
protected function addFields() |
329
|
|
|
{ |
330
|
|
|
$W = bab_Widgets(); |
331
|
|
|
|
332
|
|
|
require_once dirname(__FILE__).'/agent.ui.php'; |
333
|
|
|
|
334
|
|
|
$agent = $this->workperiod->getAgent(); |
335
|
|
|
$card = new absences_AgentCardFrame($agent); |
336
|
|
|
|
337
|
|
|
$this->addItem($card); |
338
|
|
|
|
339
|
|
|
$this->addItem($this->period()); |
340
|
|
|
|
341
|
|
|
if ($type = $this->type()) |
342
|
|
|
{ |
343
|
|
|
$this->addItem($type); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
$this->addItem($this->computed_quantity()); |
347
|
|
|
$this->addItem($this->quantity()); |
348
|
|
|
$this->addItem($this->validity_end()); |
349
|
|
|
|
350
|
|
|
if ($comment = $this->comment()) |
351
|
|
|
{ |
352
|
|
|
$this->addItem($comment); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
$this->addItem($this->comment2()); |
356
|
|
|
|
357
|
|
|
if (!$this->workperiod->todelete) { |
358
|
|
|
$this->addItem($W->Icon( |
359
|
|
|
absences_translate('The acceptation will open a recovery vacation right for the applicant with the specified quantity'), Func_Icons::STATUS_DIALOG_INFORMATION) |
360
|
|
|
); |
361
|
|
|
} |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
|
365
|
|
|
|
366
|
|
|
protected function validity_end() |
367
|
|
|
{ |
368
|
|
|
$W = bab_Widgets(); |
369
|
|
|
|
370
|
|
|
return $W->LabelledWidget( |
371
|
|
|
absences_translate('Recovery right validity end date'), |
372
|
|
|
$W->DatePicker(), |
373
|
|
|
__FUNCTION__ |
374
|
|
|
); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
|
378
|
|
View Code Duplication |
protected function computed_quantity() |
|
|
|
|
379
|
|
|
{ |
380
|
|
|
$W = bab_Widgets(); |
381
|
|
|
|
382
|
|
|
$type = $this->workperiod->getType(); |
383
|
|
|
|
384
|
|
|
return $W->VBoxItems( |
385
|
|
|
$W->Label(absences_translate('Computed quantity on period'))->colon()->addClass('widget-strong'), |
386
|
|
|
$W->Label(absences_quantity($this->workperiod->getComputedDuration(), $type->quantity_unit)) |
|
|
|
|
387
|
|
|
); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* |
393
|
|
|
* |
394
|
|
|
*/ |
395
|
|
|
protected function period() |
396
|
|
|
{ |
397
|
|
|
$W = bab_Widgets(); |
398
|
|
|
|
399
|
|
|
return $W->VBoxItems( |
400
|
|
|
$W->Label(absences_translate('Working period'))->colon()->addClass('widget-strong'), |
401
|
|
|
$W->Label(absences_DateTimePeriod($this->workperiod->date_begin, $this->workperiod->date_end, 'bab_longDate')) |
402
|
|
|
); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* |
407
|
|
|
*/ |
408
|
|
|
protected function type() |
409
|
|
|
{ |
410
|
|
|
$W = bab_Widgets(); |
411
|
|
|
|
412
|
|
|
$type = $this->workperiod->getType(); |
413
|
|
|
|
414
|
|
|
if (!isset($type)) |
415
|
|
|
{ |
416
|
|
|
return null; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
return $W->VBoxItems( |
420
|
|
|
$W->Label(absences_translate('Working day type'))->colon()->addClass('widget-strong'), |
421
|
|
|
$W->Label($type->name) |
|
|
|
|
422
|
|
|
); |
423
|
|
|
|
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* |
428
|
|
|
*/ |
429
|
|
|
protected function comment() |
430
|
|
|
{ |
431
|
|
|
$W = bab_Widgets(); |
432
|
|
|
|
433
|
|
|
if (empty($this->workperiod->comment)) |
434
|
|
|
{ |
435
|
|
|
return null; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
return $W->VBoxItems( |
|
|
|
|
439
|
|
|
$W->Label(absences_translate('Reason for the request'))->colon()->addClass('widget-strong'), |
440
|
|
|
$W->RichText($this->workperiod->comment)->setRenderingOptions(BAB_HTML_ALL ^ BAB_HTML_P) |
441
|
|
|
); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
|
445
|
|
|
|
446
|
|
View Code Duplication |
protected function duration() |
|
|
|
|
447
|
|
|
{ |
448
|
|
|
$W = bab_Widgets(); |
449
|
|
|
|
450
|
|
|
return $W->VBoxItems( |
451
|
|
|
$W->Label(absences_translate('Computed duration'))->colon(), |
452
|
|
|
$W->Label(absences_quantity($this->workperiod->getComputedDuration(), $this->workperiod->getType()->quantity_unit)) |
|
|
|
|
453
|
|
|
); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
|
457
|
|
View Code Duplication |
protected function comment2() |
|
|
|
|
458
|
|
|
{ |
459
|
|
|
$W = bab_Widgets(); |
460
|
|
|
|
461
|
|
|
return $W->LabelledWidget( |
462
|
|
|
absences_translate('Approver comment'), |
463
|
|
|
$W->TextEdit()->setColumns(80)->setLines(5), |
464
|
|
|
__FUNCTION__ |
465
|
|
|
); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
|
469
|
|
|
|
470
|
|
|
protected function addButtons() |
471
|
|
|
{ |
472
|
|
|
$W = bab_Widgets(); |
473
|
|
|
|
474
|
|
|
if ($this->workperiod->todelete) { |
475
|
|
|
$label = absences_translate('Confirm deletion'); |
476
|
|
|
} else { |
477
|
|
|
$label = absences_translate('Confirm'); |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
$button = $W->FlowItems( |
481
|
|
|
|
482
|
|
|
$W->SubmitButton()->setName('confirm')->setLabel($label), |
483
|
|
|
$W->SubmitButton()->setName('refuse')->setLabel(absences_translate('Refuse')) |
484
|
|
|
)->setSpacing(1,'em'); |
485
|
|
|
|
486
|
|
|
$this->addItem($button); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
} |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: