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
|
1 |
|
require_once dirname(__FILE__).'/request.class.php'; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Work period recovery request |
31
|
|
|
* |
32
|
|
|
* |
33
|
|
|
* @property int $id_user |
34
|
|
|
* @property string $date_begin |
35
|
|
|
* @property string $date_end |
36
|
|
|
* @property int $id_type |
37
|
|
|
* @property int $idfai |
38
|
|
|
* @property string $comment |
39
|
|
|
* @property string $createdOn |
40
|
|
|
* @property string $modifiedOn |
41
|
|
|
* @property string $status |
42
|
|
|
* @property int $id_approver |
43
|
|
|
* @property int $id_right |
44
|
|
|
* @property float $quantity |
45
|
|
|
* @property string $quantity_unit |
46
|
|
|
* @property string validity_end |
47
|
|
|
* @property int $archived |
48
|
|
|
*/ |
49
|
|
|
class absences_WorkperiodRecoverRequest extends absences_Request |
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* @var absences_WorkperiodType |
53
|
|
|
*/ |
54
|
|
|
private $type; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $id |
59
|
|
|
* @return absences_WorkperiodRecoverRequest |
60
|
|
|
*/ |
61
|
|
|
public static function getById($id) |
62
|
|
|
{ |
63
|
|
|
$request = new absences_WorkperiodRecoverRequest(); |
64
|
|
|
$request->id = $id; |
65
|
|
|
|
66
|
|
|
return $request; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function getRow() |
76
|
|
|
{ |
77
|
|
|
if (null === $this->row) |
78
|
|
|
{ |
79
|
|
|
global $babDB; |
80
|
|
|
$query = 'SELECT * FROM absences_workperiod_recover_request WHERE id='.$babDB->quote($this->id); |
81
|
|
|
|
82
|
|
|
$res = $babDB->db_query($query); |
83
|
|
|
$this->setRow($babDB->db_fetch_assoc($res)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this->row; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* |
92
|
|
|
* @param absences_WorkperiodType $type |
93
|
|
|
* @return absences_WorkperiodRecoverRequest |
94
|
|
|
*/ |
95
|
|
|
public function setType(absences_WorkperiodType $type) |
96
|
|
|
{ |
97
|
|
|
$this->type = $type; |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* |
104
|
|
|
* @return absences_WorkperiodType |
105
|
|
|
*/ |
106
|
|
|
public function getType() |
107
|
|
|
{ |
108
|
|
|
if (!isset($this->type)) |
109
|
|
|
{ |
110
|
|
|
require_once dirname(__FILE__).'/workperiod_type.class.php'; |
111
|
|
|
|
112
|
|
|
$row = $this->getRow(); |
113
|
|
|
$this->type = absences_WorkperiodType::getFromId($row['id_type']); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $this->type; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* (non-PHPdoc) |
124
|
|
|
* @see absences_Request::getRequestType() |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getRequestType() |
129
|
|
|
{ |
130
|
|
|
return absences_translate('Worked day entitling recovery'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* |
137
|
|
|
*/ |
138
|
|
|
public function save() |
139
|
|
|
{ |
140
|
|
|
global $babDB; |
141
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
142
|
|
|
|
143
|
|
|
if (!isset($this->validity_end) || '0000-00-00' === $this->validity_end) |
144
|
|
|
{ |
145
|
|
|
$end = BAB_DateTime::fromIsoDateTime($this->date_end); |
146
|
|
|
$days = absences_getVacationOption('end_recup'); |
147
|
|
|
|
148
|
|
|
if (!$days) { |
149
|
|
|
$days = 365; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
// les annees ne foncitonnent pas avec cette API ? |
153
|
|
|
|
154
|
|
|
if (($days / 365) >= 1) { |
155
|
|
|
$years = (int)($days / 365); |
156
|
|
|
$days = $days % 365; |
157
|
|
|
|
158
|
|
|
$end->add($years, BAB_DATETIME_YEAR); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$end->add($days, BAB_DATETIME_DAY); |
162
|
|
|
|
163
|
|
|
$this->validity_end = $end->getIsoDate(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
|
167
|
|
|
|
168
|
|
|
if (isset($this->id)) |
169
|
|
|
{ |
170
|
|
|
$query = 'UPDATE absences_workperiod_recover_request SET |
171
|
|
|
id_user='.$babDB->quote($this->id_user).', |
172
|
|
|
date_begin='.$babDB->quote($this->date_begin).', |
173
|
|
|
date_end='.$babDB->quote($this->date_end).', |
174
|
|
|
id_type='.$babDB->quote($this->id_type).', |
175
|
|
|
idfai='.$babDB->quote($this->idfai).', |
176
|
|
|
comment='.$babDB->quote($this->comment).', |
177
|
|
|
modifiedOn=NOW(), |
178
|
|
|
status='.$babDB->quote($this->status).', |
179
|
|
|
comment2='.$babDB->quote($this->comment2).', |
180
|
|
|
id_approver='.$babDB->quote($this->id_approver).', |
181
|
|
|
id_right='.$babDB->quote($this->id_right).', |
182
|
|
|
quantity='.$babDB->quote($this->quantity).', |
183
|
|
|
quantity_unit='.$babDB->quote($this->quantity_unit).', |
184
|
|
|
validity_end='.$babDB->quote($this->validity_end).' |
185
|
|
|
'; |
186
|
|
|
|
187
|
|
|
if (isset($this->todelete)) { |
188
|
|
|
$query .= ', todelete='.$babDB->quote($this->todelete); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$query .= 'WHERE id='.$babDB->quote($this->id); |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
$babDB->db_query($query); |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
} else { |
198
|
|
|
|
199
|
|
|
$babDB->db_query('INSERT INTO absences_workperiod_recover_request ( |
200
|
|
|
id_user, |
201
|
|
|
date_begin, |
202
|
|
|
date_end, |
203
|
|
|
id_type, |
204
|
|
|
comment, |
205
|
|
|
createdOn, |
206
|
|
|
modifiedOn, |
207
|
|
|
status, |
208
|
|
|
quantity, |
209
|
|
|
quantity_unit, |
210
|
|
|
validity_end |
211
|
|
|
) VALUES ( |
212
|
|
|
|
213
|
|
|
'.$babDB->quote($this->id_user).', |
214
|
|
|
'.$babDB->quote($this->date_begin).', |
215
|
|
|
'.$babDB->quote($this->date_end).', |
216
|
|
|
'.$babDB->quote($this->id_type).', |
217
|
|
|
'.$babDB->quote($this->comment).', |
218
|
|
|
NOW(), |
219
|
|
|
NOW(), |
220
|
|
|
'.$babDB->quote($this->status).', |
221
|
|
|
'.$babDB->quote($this->quantity).', |
222
|
|
|
'.$babDB->quote($this->quantity_unit).', |
223
|
|
|
'.$babDB->quote($this->validity_end).' |
224
|
|
|
) |
225
|
|
|
'); |
226
|
|
|
|
227
|
|
|
$this->id = $babDB->db_insert_id(); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
|
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Trouver la duree en calculee dans la meme unite que le type associe |
236
|
|
|
* |
237
|
|
|
* duree en jour precis a la demie-journee ou duree en heuress precis a l'heure |
238
|
|
|
* |
239
|
|
|
* |
240
|
|
|
* @return float | int |
241
|
|
|
*/ |
242
|
|
|
public function getComputedDuration() |
243
|
|
|
{ |
244
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
245
|
|
|
$unit = $this->getType()->quantity_unit; |
|
|
|
|
246
|
|
|
|
247
|
|
|
if ('H' === $unit) |
248
|
|
|
{ |
249
|
|
|
return (int) floor((bab_mktime($this->date_end) - bab_mktime($this->date_begin)) / 3600); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
// trouver les jours complets |
253
|
|
|
|
254
|
|
|
list($day1, $hour1) = explode(' ', $this->date_begin); |
|
|
|
|
255
|
|
|
$full1 = BAB_DateTime::fromIsoDateTime($day1.' 00:00:00'); |
256
|
|
|
$full1->add(1, BAB_DATETIME_DAY); |
257
|
|
|
|
258
|
|
|
list($day2, $hour2) = explode(' ', $this->date_end); |
|
|
|
|
259
|
|
|
$full2 = BAB_DateTime::fromIsoDateTime($day2.' 00:00:00'); |
260
|
|
|
|
261
|
|
|
$date_begin = BAB_DateTime::fromIsoDateTime($this->date_begin); |
262
|
|
|
$date_end = BAB_DateTime::fromIsoDateTime($this->date_end); |
263
|
|
|
|
264
|
|
|
if ($full1->getIsoDate() > $full2->getIsoDate()) |
265
|
|
|
{ |
266
|
|
|
$full_days = 0; |
|
|
|
|
267
|
|
|
|
268
|
|
|
$diff_hour = round(($date_end->getTimeStamp() - $date_begin->getTimeStamp()) / 3600); |
269
|
|
|
$diff_days = $diff_hour > 4 ? 1 : .5; |
270
|
|
|
|
271
|
|
|
return $diff_days; |
272
|
|
|
|
273
|
|
|
} else { |
274
|
|
|
$full_days = $full2->dateDiffIso($full1->getIsoDate(), $full2->getIsoDate()); |
275
|
|
|
|
276
|
|
|
bab_debug('Full days : '.$full_days); |
277
|
|
|
|
278
|
|
|
$diff_hour1 = round(($full1->getTimeStamp() - $date_begin->getTimeStamp()) / 3600); |
279
|
|
|
$diff_hour2 = round(($date_end->getTimeStamp() - $full2->getTimeStamp()) / 3600); |
280
|
|
|
|
281
|
|
|
bab_debug('before first complete day : '.$diff_hour1.' h'); |
282
|
|
|
bab_debug('after last complete day : '.$diff_hour2.' h'); |
283
|
|
|
|
284
|
|
|
|
285
|
|
|
$diff_days1 = $diff_hour1 > 12 ? 1 : .5; |
286
|
|
|
$diff_days2 = $diff_hour2 > 12 ? 1 : .5; |
287
|
|
|
|
288
|
|
|
return ($diff_days1 + $full_days + $diff_days2); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
|
294
|
|
|
|
295
|
|
|
|
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* (non-PHPdoc) |
299
|
|
|
* @see absences_Request::getApprobationId() |
300
|
|
|
* |
301
|
|
|
* @return int |
302
|
|
|
*/ |
303
|
|
|
public function getApprobationId() |
304
|
|
|
{ |
305
|
|
|
if ($agent = $this->getAgent()) |
306
|
|
|
{ |
307
|
|
|
return $agent->getRecoverApprobationId(); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
return null; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Process specific code when the request is rejected |
315
|
|
|
* |
316
|
|
|
*/ |
317
|
|
|
protected function onReject() |
318
|
|
|
{ |
319
|
|
|
|
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* programme de reprise des declaration de jours travaille approuvees par auto-approbation sans droit cree |
325
|
|
|
*/ |
326
|
|
|
public function restoreMissingRight() |
327
|
|
|
{ |
328
|
|
|
if ($this->id_right) { |
329
|
|
|
return false; |
330
|
|
|
} |
331
|
|
|
$this->onConfirm(); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
|
335
|
|
|
|
336
|
|
|
public function getRight() |
337
|
|
|
{ |
338
|
|
|
if (!$this->id_right) { |
339
|
|
|
return null; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
require_once dirname(__FILE__).'/right.class.php'; |
343
|
|
|
|
344
|
|
|
$right = new absences_Right($this->id_right); |
345
|
|
|
|
346
|
|
|
if (!$right->getRow()) { |
347
|
|
|
return null; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
|
351
|
|
|
return $right; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Process specific code when the request is confirmed |
358
|
|
|
* |
359
|
|
|
*/ |
360
|
|
|
protected function onConfirm() |
361
|
|
|
{ |
362
|
|
|
if (null !== $this->getRight()) { |
363
|
|
|
return; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
// create right access for recovery only if not allready created |
367
|
|
|
|
368
|
|
|
global $babDB; |
369
|
|
|
require_once dirname(__FILE__).'/right.class.php'; |
370
|
|
|
|
371
|
|
|
$agent = $this->getAgent(); |
372
|
|
|
|
373
|
|
|
$begin = mb_substr($this->date_end, 0, 10); |
374
|
|
|
$end = $this->validity_end; |
375
|
|
|
|
376
|
|
|
$date = bab_shortDate(bab_mktime($this->date_begin), false); |
377
|
|
|
|
378
|
|
|
$description = $agent->getName().' '.$date; |
379
|
|
|
|
380
|
|
|
// si un droit avec cette description existe deja on ne le cree pas |
381
|
|
|
// mais on fait la liaison avec la periode travaillee |
382
|
|
|
|
383
|
|
|
$res = $babDB->db_query('SELECT id FROM absences_rights WHERE description='.$babDB->quote($description)); |
384
|
|
|
$existingRight = $babDB->db_fetch_assoc($res); |
385
|
|
|
|
386
|
|
|
if ($existingRight) { |
387
|
|
|
$id_right = $existingRight['id']; |
388
|
|
|
} else { |
389
|
|
|
$id_right = $agent->createRecoveryRight($begin, $end, $description, $this->quantity, $this->quantity_unit); |
|
|
|
|
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
$babDB->db_query('UPDATE absences_workperiod_recover_request |
393
|
|
|
SET id_right='.$babDB->quote($id_right).' |
394
|
|
|
WHERE id='.$babDB->quote($this->id) |
395
|
|
|
); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
public function getTitle() |
399
|
|
|
{ |
400
|
|
|
if (isset($this->todelete) && $this->todelete) { |
401
|
|
|
return absences_translate('worked period entitling recovery to delete'); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
return absences_translate('worked period entitling recovery'); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
|
408
|
|
View Code Duplication |
public function getNotifyFields() |
|
|
|
|
409
|
|
|
{ |
410
|
|
|
return array( |
411
|
|
|
absences_translate('From') => bab_shortDate(bab_mktime($this->date_begin)), |
412
|
|
|
absences_translate('Until') => bab_shortDate(bab_mktime($this->date_end)), |
413
|
|
|
absences_translate('Quantity') => absences_quantity($this->quantity, $this->quantity_unit) |
414
|
|
|
); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
|
418
|
|
|
|
419
|
|
View Code Duplication |
public function getYear() |
|
|
|
|
420
|
|
|
{ |
421
|
|
|
$year = (int) substr($this->date_begin, 0, 4); |
422
|
|
|
|
423
|
|
|
if (0 === $year) |
424
|
|
|
{ |
425
|
|
|
return null; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
return $year; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
|
432
|
|
View Code Duplication |
public function getArchiveYear() |
|
|
|
|
433
|
|
|
{ |
434
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
435
|
|
|
$year = (int) substr($this->date_begin, 0, 4); |
436
|
|
|
|
437
|
|
|
if (0 === $year) |
438
|
|
|
{ |
439
|
|
|
return null; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
$day = absences_getVacationOption('archivage_day'); |
443
|
|
|
$month = absences_getVacationOption('archivage_month'); |
444
|
|
|
|
445
|
|
|
$currentYear = new BAB_DateTime($year, $month, $day); |
446
|
|
|
if($this->date_begin < $currentYear->getIsoDate()){ |
447
|
|
|
$year = $year-1; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
return $year; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
|
454
|
|
View Code Duplication |
public function archive() |
|
|
|
|
455
|
|
|
{ |
456
|
|
|
global $babDB; |
457
|
|
|
|
458
|
|
|
$babDB->db_query(" |
459
|
|
|
UPDATE absences_workperiod_recover_request |
460
|
|
|
SET |
461
|
|
|
archived=".$babDB->quote(1)." |
462
|
|
|
WHERE |
463
|
|
|
id=".$babDB->quote($this->id)." |
464
|
|
|
"); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
|
468
|
|
|
|
469
|
|
View Code Duplication |
public function setNotified() |
|
|
|
|
470
|
|
|
{ |
471
|
|
|
global $babDB; |
472
|
|
|
|
473
|
|
|
$babDB->db_query(" |
474
|
|
|
UPDATE absences_workperiod_recover_request |
475
|
|
|
SET |
476
|
|
|
appr_notified=".$babDB->quote(1)." |
477
|
|
|
WHERE |
478
|
|
|
id=".$babDB->quote($this->id)." |
479
|
|
|
"); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
|
483
|
|
|
public function getManagerEditUrl() |
484
|
|
|
{ |
485
|
|
|
$addon = bab_getAddonInfosInstance('absences'); |
486
|
|
|
return $addon->getUrl().'vacadmwd&idx=edit&id='.$this->id; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
public function getManagerDeleteUrl() |
490
|
|
|
{ |
491
|
|
|
$addon = bab_getAddonInfosInstance('absences'); |
492
|
|
|
return $addon->getUrl().'vacadmwd&idx=delete&id='.$this->id; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
|
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* @return string |
499
|
|
|
*/ |
500
|
|
View Code Duplication |
public function getEditUrl($rfrom, $ide = null) |
|
|
|
|
501
|
|
|
{ |
502
|
|
|
$url = absences_addon()->getUrl()."vacuser&idx=workperiod&id=".$this->id; |
503
|
|
|
|
504
|
|
|
if (isset($rfrom)) |
505
|
|
|
{ |
506
|
|
|
$url .= '&rfrom='.$rfrom; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
if (isset($ide)) |
510
|
|
|
{ |
511
|
|
|
$url .= '&ide='.$ide; |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
return $url; |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
|
518
|
|
|
|
519
|
|
|
|
520
|
|
|
public function getManagerFrame() |
521
|
|
|
{ |
522
|
|
|
$W = bab_Widgets(); |
523
|
|
|
|
524
|
|
|
return $W->Link($W->Icon(absences_translate('Worked day entitling recovery'), Func_Icons::ACTIONS_VIEW_CALENDAR_WORKWEEK), absences_addon()->getUrl()."vacadmwd&idx=edit&id=".$this->id ); |
|
|
|
|
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* Get request card frame to display in requests list |
530
|
|
|
* @param bool $display_username Affiche le nom du demandeur dans la card frame ou non, utile pour les listes contenant plusieurs demandeurs possibles |
531
|
|
|
* @param int $rfrom si les demandes de la liste sont modifiee par un gestionnaire ou gestionnaire delegue |
532
|
|
|
* @param int $ide id entite de l'organigramme >0 si gestionnaire delegue seulement |
533
|
|
|
* @return Widget_Frame |
534
|
|
|
*/ |
535
|
|
|
public function getCardFrame($display_username, $rfrom, $ide) |
536
|
|
|
{ |
537
|
|
|
bab_functionality::includeOriginal('Icons'); |
|
|
|
|
538
|
|
|
$W = bab_Widgets(); |
539
|
|
|
$layout = $W->HBoxLayout()->setHorizontalSpacing(2,'em')->addClass('widget-full-width'); |
540
|
|
|
$frame = $W->Frame(null, $layout); |
541
|
|
|
$frame->addClass(Func_Icons::ICON_LEFT_16); |
542
|
|
|
|
543
|
|
|
$layout->addItem($col1 = $W->VBoxLayout()->setVerticalSpacing(.5,'em')); |
544
|
|
|
$layout->addItem($col2 = $W->VBoxLayout()->setVerticalSpacing(.5,'em')); |
545
|
|
|
$layout->addItem($col3 = $W->VBoxLayout()->setVerticalSpacing(.5,'em')); |
546
|
|
|
|
547
|
|
|
|
548
|
|
|
$col1->addItem($W->Link($W->Icon(absences_translate('Worked day entitling recovery'), Func_Icons::ACTIONS_VIEW_CALENDAR_WORKWEEK), absences_addon()->getUrl()."vacuser&idx=view_wp_recovery&id=".$this->id)); |
549
|
|
|
$col1->setCanvasOptions($col1->Options()->width(25,'em')); |
|
|
|
|
550
|
|
|
$col2->setCanvasOptions($col1->Options()->width(25,'em')); |
|
|
|
|
551
|
|
|
$layout->addItem($col3 = $W->VBoxLayout()->setVerticalSpacing(.5,'em')); |
552
|
|
|
$col2->setSizePolicy(Widget_SizePolicy::MAXIMUM); |
553
|
|
|
|
554
|
|
|
$col1->addItem($this->getStatusIcon()); |
555
|
|
|
|
556
|
|
|
$col2->addItem($W->Title(absences_DateTimePeriod($this->date_begin, $this->date_end), 5)); |
557
|
|
|
|
558
|
|
|
if ($display_username) |
559
|
|
|
{ |
560
|
|
|
$col2->addItem($this->labelledValue(absences_translate('Owner'), $this->getUserName())); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
$type = $this->getType(); |
564
|
|
|
if ($type && $type->getRow()) |
565
|
|
|
{ |
566
|
|
|
$col2->addItem($this->labelledValue(absences_translate('Type'), $type->name)); |
|
|
|
|
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
|
570
|
|
View Code Duplication |
if ($this->canModify()) |
|
|
|
|
571
|
|
|
{ |
572
|
|
|
$col3->addItem($W->Link($W->Icon(absences_translate('Modify'), Func_Icons::ACTIONS_DOCUMENT_EDIT), $this->getEditUrl($rfrom, $ide))); |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
if ($this->canDelete()) |
576
|
|
|
{ |
577
|
|
|
$urldelete = absences_addon()->getUrl()."vacuser&idx=delete&id_recovery=".$this->id; |
578
|
|
|
$col3->addItem($W->Link($W->Icon(absences_translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), $urldelete)); |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
$frame->setTitle(sprintf(absences_translate('Created the %s'), bab_shortDate(bab_mktime($this->createdOn())))); |
582
|
|
|
|
583
|
|
|
return $frame; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
|
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* Delete request |
590
|
|
|
*/ |
591
|
|
|
public function delete() |
592
|
|
|
{ |
593
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
594
|
|
|
|
595
|
|
|
$date_begin = BAB_DateTime::fromIsoDateTime($this->date_begin); |
596
|
|
|
$date_end = BAB_DateTime::fromIsoDateTime($this->date_end); |
597
|
|
|
|
598
|
|
|
parent::delete(); |
599
|
|
|
|
600
|
|
|
global $babDB; |
601
|
|
|
$babDB->db_query("delete from absences_workperiod_recover_request where id=".$babDB->quote($this->id)); |
602
|
|
|
|
603
|
|
|
$this->addMovement( |
604
|
|
|
sprintf( |
605
|
|
|
absences_translate('The workperiod recover request from the %s to the %s has been deleted'), |
606
|
|
|
$date_begin->shortFormat(true), |
607
|
|
|
$date_end->shortFormat(true) |
608
|
|
|
) |
609
|
|
|
); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Test form validity |
615
|
|
|
* |
616
|
|
|
* @throws Exception |
617
|
|
|
* |
618
|
|
|
* @return bool |
619
|
|
|
*/ |
620
|
|
|
public static function checkForm(Array $workperiod, absences_WorkperiodRecoverRequest $wd = null) |
621
|
|
|
{ |
622
|
|
|
// il ne doit pas exister de periode de conges sur la meme periode |
623
|
|
|
// TODO la periode ne doit pas etre travaillee ?? |
624
|
|
|
// il ne doit pas deja exister de periode travaillee donnant droit a recuperation |
625
|
|
|
|
626
|
|
|
require_once dirname(__FILE__).'/workperiod_type.class.php'; |
627
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
628
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
629
|
|
|
|
630
|
|
|
|
631
|
|
|
if (isset($wd)) |
632
|
|
|
{ |
633
|
|
|
$id_user = $wd->id_user; |
634
|
|
|
} else { |
635
|
|
|
$id_user = bab_getUserId(); |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
|
639
|
|
|
global $babDB; |
640
|
|
|
$W = bab_Widgets(); |
641
|
|
|
$datePicker = $W->DatePicker(); |
642
|
|
|
|
643
|
|
|
$datebegin = $datePicker->getISODate($workperiod['datebegin']); |
644
|
|
|
$dateend = $datePicker->getISODate($workperiod['dateend']); |
645
|
|
|
|
646
|
|
|
if ('0000-00-00' === $datebegin || '0000-00-00' === $dateend) |
647
|
|
|
{ |
648
|
|
|
throw new Exception(absences_translate('The begin and end dates are mandatory')); |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
if (!$datebegin || !$dateend) |
|
|
|
|
652
|
|
|
{ |
653
|
|
|
throw new Exception(absences_translate('Begin and end date are not correct')); |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
$begin = $datebegin.' '.$workperiod['hourbegin']; |
657
|
|
|
$end = $dateend.' '.$workperiod['hourend']; |
658
|
|
|
|
659
|
|
|
if ($begin >= $end) |
660
|
|
|
{ |
661
|
|
|
throw new Exception(absences_translate('Start date must be prior to the end date')); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
|
665
|
|
|
$delay_recovery = absences_getVacationOption('delay_recovery'); |
666
|
|
|
$delay = BAB_DateTime::now(); |
667
|
|
|
if ($delay_recovery) { |
668
|
|
|
// 1 is added for the last 24H in the same day |
669
|
|
|
$delay->add(1 + $delay_recovery, BAB_DATETIME_DAY); |
670
|
|
|
} |
671
|
|
|
if ($end > $delay->getIsoDateTime()) |
672
|
|
|
{ |
673
|
|
|
if ($delay_recovery) { |
674
|
|
|
throw new Exception(sprintf(absences_translate('The request dates must be in the next %d days'), $delay_recovery)); |
675
|
|
|
} else { |
676
|
|
|
throw new Exception(absences_translate('The request dates must be over')); |
677
|
|
|
} |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
|
681
|
|
|
|
682
|
|
|
$res = $babDB->db_query('SELECT * FROM absences_entries WHERE |
683
|
|
|
id_user='.$babDB->quote($id_user).' |
684
|
|
|
AND !(date_begin > '.$babDB->quote($end).' OR date_end < '.$babDB->quote($begin).')' |
685
|
|
|
); |
686
|
|
|
|
687
|
|
|
if (0 != $babDB->db_num_rows($res)) |
688
|
|
|
{ |
689
|
|
|
throw new Exception(absences_translate('A vacation request already exist on this period')); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
|
693
|
|
|
$query = 'SELECT * FROM absences_workperiod_recover_request WHERE |
694
|
|
|
id_user='.$babDB->quote($id_user).' |
695
|
|
|
AND !(date_begin > '.$babDB->quote($end).' OR date_end < '.$babDB->quote($begin).') |
696
|
|
|
AND status<>'.$babDB->quote('N'); |
697
|
|
|
|
698
|
|
|
if (isset($wd)) |
699
|
|
|
{ |
700
|
|
|
$query .= ' AND id<>'.$babDB->quote($wd->id); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
$res = $babDB->db_query($query); |
704
|
|
|
|
705
|
|
|
if (0 != $babDB->db_num_rows($res)) |
706
|
|
|
{ |
707
|
|
|
throw new Exception(absences_translate('A workperiod recover request already exist on this period')); |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
if (!isset($workperiod['id_type'])) |
711
|
|
|
{ |
712
|
|
|
throw new Exception(absences_translate('The type is mandatory')); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
$type = absences_WorkperiodType::getFromId($workperiod['id_type']); |
716
|
|
|
|
717
|
|
|
if (!$type->getRow()) |
718
|
|
|
{ |
719
|
|
|
throw new Exception(absences_translate('The type is mandatory')); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
|
723
|
|
|
return true; |
724
|
|
|
} |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
|
728
|
|
|
|
729
|
|
|
|
730
|
|
|
|
731
|
|
|
|
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* Vacation requests |
735
|
|
|
* |
736
|
|
|
*/ |
737
|
|
|
class absences_WorkperiodRecoverRequestIterator extends absences_Iterator |
738
|
|
|
{ |
739
|
|
|
|
740
|
|
|
/** |
741
|
|
|
* |
742
|
|
|
* @var array |
743
|
|
|
*/ |
744
|
|
|
public $users; |
745
|
|
|
|
746
|
|
|
|
747
|
|
|
/** |
748
|
|
|
* Organization filter |
749
|
|
|
* @var int |
750
|
|
|
*/ |
751
|
|
|
public $organization; |
752
|
|
|
|
753
|
|
|
|
754
|
|
|
/** |
755
|
|
|
* Filtrer les demandes necessitant ou pas un email aux approbateurs |
756
|
|
|
* @var int |
757
|
|
|
*/ |
758
|
|
|
public $appr_notified; |
759
|
|
|
|
760
|
|
|
|
761
|
|
|
/** |
762
|
|
|
* Filtrer les demandes avec unes instance d'approbation |
763
|
|
|
* @var bool |
764
|
|
|
*/ |
765
|
|
|
public $idfai_set; |
766
|
|
|
|
767
|
|
|
/** |
768
|
|
|
* |
769
|
|
|
* @var string |
770
|
|
|
*/ |
771
|
|
|
public $status; |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* Search all request created before this date time |
775
|
|
|
* @var string |
776
|
|
|
*/ |
777
|
|
|
public $createdOn; |
778
|
|
|
|
779
|
|
|
|
780
|
|
|
/** |
781
|
|
|
* Search all request modified before this date |
782
|
|
|
* @var string |
783
|
|
|
*/ |
784
|
|
|
public $modifiedOn; |
785
|
|
|
|
786
|
|
|
|
787
|
|
|
/** |
788
|
|
|
* Filtrer les demandes par date de debut superieur |
789
|
|
|
* @var int |
790
|
|
|
*/ |
791
|
|
|
public $startFrom; |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* Filtrer les demandes par date de debut inferieur |
795
|
|
|
* @var int |
796
|
|
|
*/ |
797
|
|
|
public $startTo; |
798
|
|
|
|
799
|
|
|
/** |
800
|
|
|
* Filtrer les demandes par annee |
801
|
|
|
* @var int |
802
|
|
|
*/ |
803
|
|
|
public $year; |
804
|
|
|
|
805
|
|
|
|
806
|
|
|
/** |
807
|
|
|
* Filtrer les demandes par statut d'archivage |
808
|
|
|
* @var int |
809
|
|
|
*/ |
810
|
|
|
public $archived = 0; |
811
|
|
|
|
812
|
|
|
|
813
|
|
|
public function getObject($data) |
814
|
|
|
{ |
815
|
|
|
|
816
|
|
|
$entry = new absences_WorkperiodRecoverRequest; |
817
|
|
|
$entry->setRow($data); |
818
|
|
|
return $entry; |
819
|
|
|
|
820
|
|
|
} |
821
|
|
|
|
822
|
|
|
|
823
|
|
|
|
824
|
|
|
public function executeQuery() |
825
|
|
|
{ |
826
|
|
|
if(is_null($this->_oResult)) |
827
|
|
|
{ |
828
|
|
|
global $babDB; |
829
|
|
|
$req = 'SELECT r.* |
830
|
|
|
FROM |
831
|
|
|
absences_workperiod_recover_request r |
832
|
|
|
LEFT JOIN absences_personnel p ON p.id_user=r.id_user |
833
|
|
|
'; |
834
|
|
|
|
835
|
|
|
|
836
|
|
|
$where = array(); |
837
|
|
|
|
838
|
|
|
if (isset($this->users)) |
839
|
|
|
{ |
840
|
|
|
$where[] = 'r.id_user IN('.$babDB->quote($this->users).')'; |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
if (isset($this->organization)) |
844
|
|
|
{ |
845
|
|
|
$where[] = 'p.id_organization='.$babDB->quote($this->organization); |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
if (isset($this->appr_notified)) |
849
|
|
|
{ |
850
|
|
|
$where[] = 'r.appr_notified='.$babDB->quote($this->appr_notified); |
851
|
|
|
} |
852
|
|
|
|
853
|
|
|
if (isset($this->idfai_set) && $this->idfai_set) |
854
|
|
|
{ |
855
|
|
|
$where[] = 'r.idfai>'.$babDB->quote(0); |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
if (isset($this->status)) |
859
|
|
|
{ |
860
|
|
|
$where[] = 'r.status='.$babDB->quote($this->status); |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
if (isset($this->createdOn)) |
864
|
|
|
{ |
865
|
|
|
$where[] = 'r.createdOn<='.$babDB->quote($this->createdOn); |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
if (isset($this->modifiedOn)) |
869
|
|
|
{ |
870
|
|
|
$where[] = 'r.modifiedOn<='.$babDB->quote($this->modifiedOn); |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
if (isset($this->year)) |
874
|
|
|
{ |
875
|
|
|
$where[] = 'YEAR(r.date_begin)='.$babDB->quote($this->year); |
876
|
|
|
} |
877
|
|
|
|
878
|
|
|
if (isset($this->startTo) && $this->startTo != '0000-00-00') |
879
|
|
|
{ |
880
|
|
|
$where[] = 'r.date_begin <='.$babDB->quote($this->startTo); |
881
|
|
|
} |
882
|
|
|
|
883
|
|
|
if (isset($this->startFrom) && $this->startFrom != '0000-00-00') |
884
|
|
|
{ |
885
|
|
|
$where[] = 'r.date_begin >='.$babDB->quote($this->startFrom); |
886
|
|
|
} |
887
|
|
|
|
888
|
|
|
if (isset($this->archived)) |
889
|
|
|
{ |
890
|
|
|
$where[] = 'r.archived='.$babDB->quote($this->archived); |
891
|
|
|
} |
892
|
|
|
|
893
|
|
|
if ($where) |
|
|
|
|
894
|
|
|
{ |
895
|
|
|
$req .= ' WHERE '.implode(' AND ', $where); |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
$this->setMySqlResult($this->getDataBaseAdapter()->db_query($req)); |
899
|
|
|
} |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.