|
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) 2012 by CANTICO ({@link http://www.cantico.fr}) |
|
22
|
|
|
*/ |
|
23
|
|
|
require_once dirname(__FILE__).'/functions.php'; |
|
24
|
|
|
require_once dirname(__FILE__).'/utilit/agent.class.php'; |
|
25
|
|
|
require_once dirname(__FILE__).'/utilit/entry.class.php'; |
|
26
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
|
27
|
|
|
bab_Functionality::includeoriginal('PortletBackend'); |
|
|
|
|
|
|
28
|
|
|
bab_Functionality::includeoriginal('Icons'); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
class Func_PortletBackend_Absences extends Func_PortletBackend |
|
34
|
|
|
{ |
|
35
|
|
|
public function getDescription() |
|
36
|
|
|
{ |
|
37
|
|
|
return absences_translate("Absences"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function select($category = null) |
|
41
|
|
|
{ |
|
42
|
|
|
if (isset($category) && $category !== 'absences') |
|
43
|
|
|
{ |
|
44
|
|
|
return array(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$portlets = array( |
|
48
|
|
|
'absences_forthcoming' => $this->Portlet_forthcoming() |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
if (bab_isAccessValid('absences_public_planning_groups', 1)) |
|
52
|
|
|
{ |
|
53
|
|
|
$portlets['absences_publicPlanning'] = $this->Portlet_publicPlanning(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $portlets; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get portlet definition instance |
|
63
|
|
|
* @param string $portletId portlet definition ID |
|
64
|
|
|
* |
|
65
|
|
|
* @return portlet_PortletDefinitionInterface |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getPortletDefinition($portletId) |
|
68
|
|
|
{ |
|
69
|
|
|
$name = str_replace('absences_', '', $portletId); |
|
70
|
|
|
|
|
71
|
|
|
switch($name) |
|
72
|
|
|
{ |
|
73
|
|
|
case 'forthcoming': |
|
74
|
|
|
return $this->Portlet_forthcoming(); |
|
75
|
|
|
|
|
76
|
|
|
case 'publicPlanning': |
|
77
|
|
|
return $this->Portlet_publicPlanning(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return null; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
public function Portlet_forthcoming() |
|
85
|
|
|
{ |
|
86
|
|
|
return new PortletDefinition_forthcoming(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function Portlet_publicPlanning() |
|
90
|
|
|
{ |
|
91
|
|
|
return new absences_PublicPlanningDefinition(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* get a list of categories supported by the backend |
|
97
|
|
|
* @return Array |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getCategories() |
|
100
|
|
|
{ |
|
101
|
|
|
|
|
102
|
|
|
return array( |
|
103
|
|
|
'absences' => absences_translate('Absences') |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
///////////////////////////////////////// |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
class absences_PublicPlanningDefinition implements portlet_PortletDefinitionInterface |
|
115
|
|
|
{ |
|
116
|
|
|
|
|
117
|
|
|
private $id; |
|
118
|
|
|
private $name; |
|
119
|
|
|
private $description; |
|
120
|
|
|
|
|
121
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
|
|
122
|
|
|
{ |
|
123
|
|
|
$this->id = 'absences_publicPlanning'; |
|
124
|
|
|
$this->name = absences_translate('Absences planning'); |
|
125
|
|
|
$this->description = absences_translate('Public planning for absences'); |
|
126
|
|
|
$this->addon = bab_getAddonInfosInstance('absences'); |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function getId() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->id; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
public function getName() |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->name; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
public function getDescription() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->description; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
public function getPortlet() |
|
148
|
|
|
{ |
|
149
|
|
|
return new Portlet_publicPlanning; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Returns the widget rich icon URL. |
|
154
|
|
|
* |
|
155
|
|
|
* |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getRichIcon() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->addon->getImagesPath() . 'icon.png'; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Returns the widget icon URL. |
|
166
|
|
|
* |
|
167
|
|
|
* |
|
168
|
|
|
* @return string |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getIcon() |
|
171
|
|
|
{ |
|
172
|
|
|
return $this->addon->getImagesPath() . 'icon.png'; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Get thumbnail URL |
|
177
|
|
|
* max 120x60 |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getThumbnail() |
|
180
|
|
|
{ |
|
181
|
|
|
return null; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function getConfigurationActions() |
|
185
|
|
|
{ |
|
186
|
|
|
return array(); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function getPreferenceFields() |
|
190
|
|
|
{ |
|
191
|
|
|
return array( |
|
192
|
|
|
array( |
|
193
|
|
|
'label' => absences_translate('Start date shifted in months'), |
|
194
|
|
|
'type' => 'int', |
|
195
|
|
|
'name' => 'shiftmonth', |
|
196
|
|
|
'default' => 0 |
|
197
|
|
|
), |
|
198
|
|
|
|
|
199
|
|
|
array( |
|
200
|
|
|
'label' => absences_translate('Display the legend'), |
|
201
|
|
|
'type' => 'boolean', |
|
202
|
|
|
'name' => 'legend', |
|
203
|
|
|
'default' => true |
|
204
|
|
|
) |
|
205
|
|
|
); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
class Portlet_publicPlanning extends Widget_Item implements portlet_PortletInterface |
|
216
|
|
|
{ |
|
217
|
|
|
|
|
218
|
|
|
private $options = array(); |
|
219
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @param Widget_Canvas $canvas |
|
224
|
|
|
*/ |
|
225
|
|
|
public function display(Widget_Canvas $canvas) |
|
226
|
|
|
{ |
|
227
|
|
|
global $babDB; |
|
228
|
|
|
$W = bab_Widgets(); |
|
229
|
|
|
require_once dirname(__FILE__).'/utilit/planningincl.php'; |
|
230
|
|
|
|
|
231
|
|
|
$nbmonth = (int) bab_rp('nbmonth', 1); |
|
232
|
|
|
|
|
233
|
|
|
if (!bab_isAccessValid('absences_public_planning_groups', 1)) |
|
234
|
|
|
{ |
|
235
|
|
|
return ''; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
// preload the 30 first users |
|
239
|
|
|
$initusers = absences_getSearchLimit($nbmonth); |
|
240
|
|
|
|
|
241
|
|
|
$users = array(); |
|
242
|
|
|
$res = absences_publicCalendarUsers(bab_rp('keyword', null), bab_rp('departments', null), bab_rp('searchtype'), bab_rp('dateb'), bab_rp('datee'), bab_rp('date')); |
|
243
|
|
|
|
|
244
|
|
|
$i = 0; |
|
245
|
|
View Code Duplication |
while ($arr = $babDB->db_fetch_assoc($res)) |
|
|
|
|
|
|
246
|
|
|
{ |
|
247
|
|
|
$users[] = $arr['id']; |
|
248
|
|
|
if ($i > $initusers) |
|
249
|
|
|
{ |
|
250
|
|
|
break; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
$i++; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
if (empty($users) && '' === bab_rp('keyword') && '' === bab_rp('dateb') && '' === bab_rp('datee') && '' === bab_rp('date')) |
|
257
|
|
|
{ |
|
258
|
|
|
return $canvas->span(null, array(), array(absences_translate('No employees found, the public planning is empty'))); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
$shiftmonth = isset($this->options['shiftmonth']) ? $this->options['shiftmonth'] : 0; |
|
262
|
|
|
$legend = isset($this->options['legend']) ? (bool) $this->options['legend'] : true; |
|
263
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
$search = bab_rp('search'); // button clicked |
|
266
|
|
|
$month = (int) bab_rp('month'); |
|
267
|
|
|
$year = (int) bab_rp('year'); |
|
268
|
|
|
$searchDate = bab_rp('dateb'); |
|
269
|
|
|
if (empty($searchDate)) { |
|
270
|
|
|
$searchDate = bab_rp('date'); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
if (!empty($searchDate) && $search) { |
|
274
|
|
|
// try to replace month/year by elements from searchDate |
|
275
|
|
|
list($searchYear, $searchMmonth) = explode('-', $W->DatePicker()->getISODate($searchDate)); |
|
276
|
|
|
$searchYear = (int) $searchYear; |
|
277
|
|
|
$searchMmonth = (int) $searchMmonth; |
|
278
|
|
|
|
|
279
|
|
|
if ($searchYear !== $year) { |
|
280
|
|
|
$_REQUEST['year'] = $searchYear; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
if ($searchMmonth !== $month) { |
|
284
|
|
|
$_REQUEST['month'] = $searchMmonth; |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
|
|
289
|
|
|
$cls = new absences_viewVacationCalendarCls($users, false, true, $nbmonth, true, $shiftmonth, $legend); |
|
290
|
|
|
$cls->publiccalendar($babDB->db_num_rows($res)); |
|
291
|
|
|
|
|
292
|
|
|
$widget = $W->Html($cls->getHtml()); |
|
293
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
return $widget->display($canvas) |
|
296
|
|
|
.$canvas->loadScript($widget->getId(), absences_addon()->getTemplatePath().'calendar.jquery.js') |
|
297
|
|
|
.$canvas->loadStyleSheet(absences_addon()->getStylePath().'vacation.css'); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
|
|
301
|
|
|
public function getName() |
|
302
|
|
|
{ |
|
303
|
|
|
return get_class($this); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
public function getPortletDefinition() |
|
307
|
|
|
{ |
|
308
|
|
|
return new absences_PublicPlanningDefinition(); |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* receive current user configuration from portlet API |
|
313
|
|
|
*/ |
|
314
|
|
|
public function setPreferences(array $configuration) |
|
315
|
|
|
{ |
|
316
|
|
|
$this->options = $configuration; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
public function setPreference($name, $value) |
|
320
|
|
|
{ |
|
321
|
|
|
$this->options[$name] = $value; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
public function setPortletId($id) |
|
325
|
|
|
{ |
|
326
|
|
|
|
|
327
|
|
|
} |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
|
|
331
|
|
|
|
|
332
|
|
|
|
|
333
|
|
|
|
|
334
|
|
|
|
|
335
|
|
|
|
|
336
|
|
|
|
|
337
|
|
|
class PortletDefinition_forthcoming implements portlet_PortletDefinitionInterface |
|
338
|
|
|
{ |
|
339
|
|
|
|
|
340
|
|
|
private $id; |
|
341
|
|
|
private $name; |
|
342
|
|
|
private $description; |
|
343
|
|
|
|
|
344
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
|
|
345
|
|
|
{ |
|
346
|
|
|
$this->id = 'absences_forthcoming'; |
|
347
|
|
|
$this->name = absences_translate('Forthcomming absences'); |
|
348
|
|
|
$this->description = absences_translate('Forthcomming absences for users in the same department or for all personel members'); |
|
349
|
|
|
$this->addon = bab_getAddonInfosInstance('absences'); |
|
|
|
|
|
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
public function getId() |
|
353
|
|
|
{ |
|
354
|
|
|
return $this->id; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
|
|
358
|
|
|
public function getName() |
|
359
|
|
|
{ |
|
360
|
|
|
return $this->name; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
|
|
364
|
|
|
public function getDescription() |
|
365
|
|
|
{ |
|
366
|
|
|
return $this->description; |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
|
|
370
|
|
|
public function getPortlet() |
|
371
|
|
|
{ |
|
372
|
|
|
return new Portlet_forthcoming; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* Returns the widget rich icon URL. |
|
377
|
|
|
* |
|
378
|
|
|
* |
|
379
|
|
|
* @return string |
|
380
|
|
|
*/ |
|
381
|
|
|
public function getRichIcon() |
|
382
|
|
|
{ |
|
383
|
|
|
return $this->addon->getImagesPath() . 'icon.png'; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* Returns the widget icon URL. |
|
389
|
|
|
* |
|
390
|
|
|
* |
|
391
|
|
|
* @return string |
|
392
|
|
|
*/ |
|
393
|
|
|
public function getIcon() |
|
394
|
|
|
{ |
|
395
|
|
|
return $this->addon->getImagesPath() . 'icon.png'; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* Get thumbnail URL |
|
400
|
|
|
* max 120x60 |
|
401
|
|
|
*/ |
|
402
|
|
|
public function getThumbnail() |
|
403
|
|
|
{ |
|
404
|
|
|
return null; |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
public function getConfigurationActions() |
|
408
|
|
|
{ |
|
409
|
|
|
return array(); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
public function getPreferenceFields() |
|
413
|
|
|
{ |
|
414
|
|
|
|
|
415
|
|
|
|
|
416
|
|
|
$pop_options = array( |
|
417
|
|
|
array('value' => 'me', 'label' => absences_translate('Me only')), |
|
418
|
|
|
array('value' =>'all', 'label' => absences_translate('All users')) |
|
419
|
|
|
); |
|
420
|
|
|
|
|
421
|
|
|
|
|
422
|
|
|
try { |
|
423
|
|
|
$agent = absences_Agent::getCurrentUser(); |
|
424
|
|
|
if (null !== $entity = $agent->getMainEntity()) |
|
425
|
|
|
{ |
|
426
|
|
|
$pop_options[] = array('value' =>'department', 'label' => $entity['name']); |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
} catch (Exception $e) |
|
430
|
|
|
{ |
|
431
|
|
|
// user not logged in |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
|
|
435
|
|
|
|
|
436
|
|
|
return array( |
|
437
|
|
|
array( |
|
438
|
|
|
'label' => absences_translate('Number of days in future'), |
|
439
|
|
|
'type' => 'int', |
|
440
|
|
|
'name' => 'days' |
|
441
|
|
|
), |
|
442
|
|
|
array( |
|
443
|
|
|
'label' => absences_translate('Display absences for'), |
|
444
|
|
|
'type' => 'list', |
|
445
|
|
|
'name' => 'population', |
|
446
|
|
|
'options' => $pop_options |
|
447
|
|
|
), |
|
448
|
|
|
array( |
|
449
|
|
|
'label' => absences_translate('Long dates format'), |
|
450
|
|
|
'type' => 'boolean', |
|
451
|
|
|
'name' => 'longdates' |
|
452
|
|
|
), |
|
453
|
|
|
array( |
|
454
|
|
|
'label' => absences_translate('Display request status'), |
|
455
|
|
|
'type' => 'boolean', |
|
456
|
|
|
'name' => 'viewstatus' |
|
457
|
|
|
) |
|
458
|
|
|
); |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
|
|
463
|
|
|
|
|
464
|
|
|
|
|
465
|
|
|
class Portlet_forthcoming extends Widget_Item implements portlet_PortletInterface |
|
466
|
|
|
{ |
|
467
|
|
|
|
|
468
|
|
|
private $options = array(); |
|
469
|
|
|
|
|
470
|
|
|
|
|
471
|
|
|
|
|
472
|
|
|
/** |
|
473
|
|
|
* @return array |
|
474
|
|
|
*/ |
|
475
|
|
|
private function getDepartmentMembers() |
|
476
|
|
|
{ |
|
477
|
|
|
global $babDB; |
|
478
|
|
|
|
|
479
|
|
|
try { |
|
480
|
|
|
$agent = absences_Agent::getCurrentUser(); |
|
481
|
|
|
$entity = $agent->getMainEntity(); |
|
482
|
|
|
|
|
483
|
|
|
} catch(Exception $e) |
|
484
|
|
|
{ |
|
485
|
|
|
return null; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
if (null === $entity) |
|
489
|
|
|
{ |
|
490
|
|
|
return null; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
$members = array(); |
|
494
|
|
|
$res = bab_OCSelectEntityCollaborators($entity['id'], true); |
|
495
|
|
|
|
|
496
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) |
|
497
|
|
|
{ |
|
498
|
|
|
if (isset($arr['id_user'])) |
|
499
|
|
|
{ |
|
500
|
|
|
$members[] = (int) $arr['id_user']; |
|
501
|
|
|
} else { |
|
502
|
|
|
trigger_error('Missing id_user key, need ovidentia 8.0.97 version at least'); |
|
503
|
|
|
return null; |
|
504
|
|
|
} |
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
return $members; |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
|
|
511
|
|
|
/** |
|
512
|
|
|
* @param Widget_Canvas $canvas |
|
513
|
|
|
* @ignore |
|
514
|
|
|
*/ |
|
515
|
|
|
public function display(Widget_Canvas $canvas) |
|
516
|
|
|
{ |
|
517
|
|
|
$W = bab_Widgets(); |
|
518
|
|
|
|
|
519
|
|
|
|
|
520
|
|
|
|
|
521
|
|
|
|
|
522
|
|
|
$population = empty($this->options['population']) ? 'me' : $this->options['population']; |
|
523
|
|
|
$days = empty($this->options['days']) ? 7 : $this->options['days']; |
|
524
|
|
|
|
|
525
|
|
|
$to = BAB_DateTime::now(); |
|
526
|
|
|
$to->add($days, BAB_DATETIME_DAY); |
|
527
|
|
|
|
|
528
|
|
|
|
|
529
|
|
|
$users = null; |
|
530
|
|
|
|
|
531
|
|
|
if ($population === 'department') |
|
532
|
|
|
{ |
|
533
|
|
|
$users = $this->getDepartmentMembers(); |
|
534
|
|
|
if (null === $users) |
|
535
|
|
|
{ |
|
536
|
|
|
$population = 'me'; |
|
537
|
|
|
} |
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
|
|
541
|
|
|
if ($population === 'me') |
|
542
|
|
|
{ |
|
543
|
|
|
$users = array(bab_getUserId()); |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
|
|
547
|
|
|
$I = new absences_EntryIterator(); |
|
548
|
|
|
$I->users = $users; |
|
|
|
|
|
|
549
|
|
|
$I->from = date('Y-m-d H:i:s'); |
|
550
|
|
|
$I->to = $to->getIsoDateTime(); |
|
551
|
|
|
$I->status = array('', 'Y'); |
|
552
|
|
|
|
|
553
|
|
|
$I->orderby = 'date_begin ASC'; |
|
554
|
|
|
|
|
555
|
|
|
$list = $W->VBoxLayout()->addClass(Func_Icons::ICON_LEFT_32); |
|
556
|
|
|
|
|
557
|
|
|
foreach($I as $entry) |
|
558
|
|
|
{ |
|
559
|
|
|
$list->addItem($this->getEntryWidget($entry)); |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
return ' |
|
563
|
|
|
<style type="text/css" scoped> |
|
564
|
|
|
.icon-left-32 .icon { |
|
565
|
|
|
min-height: 15px; |
|
566
|
|
|
min-width: 0; |
|
567
|
|
|
padding: 1em 8px 1em 36px; |
|
568
|
|
|
} |
|
569
|
|
|
|
|
570
|
|
|
.widget-small { |
|
571
|
|
|
color:rgba(0,0,0,.5); |
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
.absences-portlet-forthcoming-entry { |
|
575
|
|
|
border-bottom:rgba(0,0,0,.19) 2px dotted; |
|
576
|
|
|
padding-bottom:.8em; |
|
577
|
|
|
margin-bottom:.8em; |
|
578
|
|
|
} |
|
579
|
|
|
</style> |
|
580
|
|
|
'. |
|
581
|
|
|
$list->display($canvas); |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
/** |
|
585
|
|
|
* @return string|false |
|
586
|
|
|
*/ |
|
587
|
|
|
private function getPhoto($id_user) |
|
588
|
|
|
{ |
|
589
|
|
|
$T = bab_functionality::get('Thumbnailer'); |
|
590
|
|
|
/*@var $T Func_Thumbnailer */ |
|
591
|
|
|
|
|
592
|
|
|
if (false === $T) |
|
593
|
|
|
{ |
|
594
|
|
|
return false; |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
|
|
598
|
|
|
$direntry = bab_getDirEntry($id_user, BAB_DIR_ENTRY_ID_USER); |
|
599
|
|
|
if (!$direntry || !isset($direntry['jpegphoto']['photo'])) |
|
|
|
|
|
|
600
|
|
|
{ |
|
601
|
|
|
return false; |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
$photo = $direntry['jpegphoto']['photo']; |
|
605
|
|
|
$data = $photo->getData(); |
|
606
|
|
|
|
|
607
|
|
|
if (null !== $data && '' !== $data) |
|
608
|
|
|
{ |
|
609
|
|
|
$T->setSourceBinary($data, $photo->lastUpdate()); |
|
610
|
|
|
$T->setResizeMode(Func_Thumbnailer::CROP_CENTER); |
|
611
|
|
|
return $T->getThumbnail(32, 32); |
|
612
|
|
|
} |
|
613
|
|
|
|
|
614
|
|
|
return false; |
|
615
|
|
|
} |
|
616
|
|
|
|
|
617
|
|
|
|
|
618
|
|
|
/** |
|
619
|
|
|
* @return Widget_DisplayableInterface |
|
620
|
|
|
*/ |
|
621
|
|
|
private function getEntryWidget(absences_Entry $entry) |
|
622
|
|
|
{ |
|
623
|
|
|
$W = bab_Widgets(); |
|
624
|
|
|
|
|
625
|
|
|
$icon = $W->Icon(null, Func_Icons::OBJECTS_USER); |
|
626
|
|
|
if ($photo = $this->getPhoto($entry->id_user)) |
|
627
|
|
|
{ |
|
628
|
|
|
$icon->setImageUrl($photo); |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
|
|
632
|
|
|
|
|
633
|
|
|
$url = bab_getUserDirEntryLink($entry->id_user, BAB_DIR_ENTRY_ID_USER); |
|
|
|
|
|
|
634
|
|
|
if (false === $url) |
|
635
|
|
|
{ |
|
636
|
|
|
$user = $W->Label(bab_getUserName($entry->id_user)); |
|
637
|
|
|
} else { |
|
638
|
|
|
$user = $W->Link(bab_getUserName($entry->id_user), $url)->setOpenMode(Widget_Link::OPEN_POPUP); |
|
639
|
|
|
} |
|
640
|
|
|
|
|
641
|
|
|
$datefunc = !empty($this->options['longdates']) ? 'bab_longDate' : 'bab_shortDate'; |
|
642
|
|
|
$period = $W->Label(absences_DateTimePeriod($entry->date_begin, $entry->date_end, $datefunc)); |
|
643
|
|
|
|
|
644
|
|
|
$status = null; |
|
645
|
|
|
if (!empty($this->options['viewstatus'])) |
|
646
|
|
|
{ |
|
647
|
|
|
$status = $W->Label($entry->getStatusStr())->addClass('widget-small'); |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
$layout = $W->HBoxItems($icon, $W->VBoxItems($user, $period, $status))->setVerticalAlign('top'); |
|
651
|
|
|
|
|
652
|
|
|
return $W->Frame(null, $layout)->addClass('absences-portlet-forthcoming-entry'); |
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
|
|
656
|
|
|
public function getName() |
|
657
|
|
|
{ |
|
658
|
|
|
return get_class($this); |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
public function getPortletDefinition() |
|
662
|
|
|
{ |
|
663
|
|
|
return new PortletDefinition_forthcoming(); |
|
664
|
|
|
} |
|
665
|
|
|
|
|
666
|
|
|
/** |
|
667
|
|
|
* Get the title defined in preferences or a default title for the widget frame |
|
668
|
|
|
* @return string |
|
669
|
|
|
*/ |
|
670
|
|
|
public function getPreferenceTitle() |
|
671
|
|
|
{ |
|
672
|
|
|
if (!empty($this->options['_blockTitle'])) |
|
673
|
|
|
{ |
|
674
|
|
|
return $this->options['_blockTitle']; |
|
675
|
|
|
} |
|
676
|
|
|
|
|
677
|
|
|
$days = empty($this->options['days']) ? 7 : $this->options['days']; |
|
678
|
|
|
|
|
679
|
|
|
return sprintf(absences_translate('Absences in the next %d days'), $days); |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
/** |
|
683
|
|
|
* receive current user configuration from portlet API |
|
684
|
|
|
*/ |
|
685
|
|
|
public function setPreferences(array $configuration) |
|
686
|
|
|
{ |
|
687
|
|
|
$this->options = $configuration; |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
public function setPreference($name, $value) |
|
691
|
|
|
{ |
|
692
|
|
|
$this->options[$name] = $value; |
|
693
|
|
|
} |
|
694
|
|
|
|
|
695
|
|
|
public function setPortletId($id) |
|
696
|
|
|
{ |
|
697
|
|
|
|
|
698
|
|
|
} |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
|
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: