PluginProbe
ShiftController Employee Shift Scheduling / 4.9.24
ShiftController Employee Shift Scheduling v4.9.24
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / sh4 / schedule / html / view / list.php

list.php in ShiftController Employee Shift Scheduling 4.9.24, at sh4/schedule/html/view/list.php

419 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 class SH4_Schedule_Html_View_List
3 {
4 public function __construct(
5 HC3_Hooks $hooks,
6
7 HC3_Ui $ui,
8 HC3_Request $request,
9 HC3_Time $t,
10
11 SH4_New_Acl $newAcl,
12
13 SH4_Shifts_Duration $shiftsDuration,
14 SH4_Calendars_Presenter $calendarsPresenter,
15 SH4_Employees_Presenter $employeesPresenter,
16 SH4_Shifts_View_Widget $widget,
17 SH4_Schedule_Html_View_Common $common,
18 SH4_Shifts_View_Common $shiftsCommon
19 )
20 {
21 $this->self = $hooks->wrap( $this );
22
23 $this->ui = $ui;
24 $this->t = $t;
25 $this->request = $request;
26 $this->newAcl = $hooks->wrap( $newAcl );
27
28 $this->shiftsDuration = $hooks->wrap( $shiftsDuration );
29 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
30 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
31
32 $this->widget = $hooks->wrap( $widget );
33 $this->common = $hooks->wrap( $common );
34 $this->shiftsCommon = $hooks->wrap( $shiftsCommon );
35 }
36
37 public function render()
38 {
39 $params = $this->request->getParams();
40 $startDate = $params['start'];
41
42 $hideui = $params['hideui'];
43 $noZoom = in_array('shiftdetails', $hideui);
44
45 $allEmployees = $this->common->findAllEmployees();
46 $allCalendars = $this->common->findAllCalendars();
47
48 $shifts = $this->common->getShifts();
49
50 $iknow = array();
51 if( count($allCalendars) <= 1 ) $iknow[] = 'calendar';
52
53 $hori = TRUE;
54
55 $this->shiftsDuration->reset();
56 $thisOut = array();
57 foreach( $shifts as $shift ){
58 $id = $shift->getId();
59 $thisView = $this->renderShift( $shift, $iknow, $hori, $noZoom );
60
61 $menu = array();
62 $fullMenu = $this->shiftsCommon->menu( $shift );
63 foreach( $fullMenu as $k0 => $thisMenu ){
64 foreach( $thisMenu as $k1 => $actionArray ){
65 $k = $k0 . '_' . $k1;
66 $menu[$k] = $actionArray;
67 }
68 }
69 if( $menu ){
70 $menu = $this->ui->helperActionsFromArray( $menu, TRUE );
71 $menu = $this->ui->makeCollection( $menu );
72
73 $checkbox = $this->ui->makeInputCheckbox( 'id[]', NULL, $id, TRUE );
74 $checkbox = $this->ui->makeBlock( $checkbox )
75 ->addAttr('class', 'sh4-shift-checker')
76 ->addAttr('style', 'display: none;')
77 ;
78 $thisView = $this->ui->makeCollection( array($thisView, $checkbox, $menu) );
79 }
80
81 $thisView = $this->ui->makeBlock( $thisView )
82 ->tag('block')
83 ->addAttr('class', 'sh4-shift-widget')
84 ;
85
86 $thisOut[] = $thisView;
87
88 $this->shiftsDuration->add( $shift );
89 }
90
91 $out = $this->ui->makeList( $thisOut );
92
93 return $out;
94 }
95
96 public function renderByCalendar()
97 {
98 $params = $this->request->getParams();
99 $startDate = $params['start'];
100
101 $calendars = $this->common->getCalendars();
102 $employees = $this->common->getEmployees();
103
104 $shifts = $this->common->getShifts();
105
106 $hideui = $params['hideui'];
107 $noZoom = in_array('shiftdetails', $hideui);
108
109 $viewCalendars = array();
110 foreach( $calendars as $calendar ){
111 $calendarId = $calendar->getId();
112 // $label = $this->calendarsPresenter->presentTitle( $calendar );
113 $label = $calendar->getTitle();
114 $viewCalendars[ $calendarId ] = $label;
115 }
116
117 $shiftsBy = array();
118
119 $iknow = array( 'calendar' );
120 $hori = TRUE;
121
122 $allEmployees = $this->common->findAllEmployees();
123 if( count($allEmployees) < 2 ){
124 $iknow[] = 'employee';
125 }
126
127 foreach( $shifts as $shift ){
128 $calendar = $shift->getCalendar();
129 $calendarId = $calendar ? $calendar->getId() : 0;
130 if( ! array_key_exists($calendarId, $shiftsBy) ){
131 $shiftsBy[$calendarId] = array();
132 }
133 $shiftsBy[$calendarId][] = $shift;
134 }
135
136 $out = array();
137 foreach( $viewCalendars as $calendarId => $calendarView ){
138 if( ! isset($shiftsBy[$calendarId]) ){
139 continue;
140 }
141
142 if( ! isset($calendars[$calendarId]) ){
143 continue;
144 }
145
146 $thisCalendar = $calendars[$calendarId];
147 $thisOut = array();
148
149 $this->shiftsDuration->reset();
150 $outShifts = array();
151 foreach( $shiftsBy[$calendarId] as $shift ){
152 $id = $shift->getId();
153 $thisView = $this->renderShift( $shift, $iknow, $hori, $noZoom );
154
155 $menu = array();
156 $fullMenu = $this->shiftsCommon->menu( $shift );
157 foreach( $fullMenu as $k0 => $thisMenu ){
158 foreach( $thisMenu as $k1 => $actionArray ){
159 $k = $k0 . '_' . $k1;
160 $menu[$k] = $actionArray;
161 }
162 }
163 if( $menu ){
164 $menu = $this->ui->helperActionsFromArray( $menu, TRUE );
165 $menu = $this->ui->makeCollection( $menu );
166
167 $checkbox = $this->ui->makeInputCheckbox( 'id[]', NULL, $id, TRUE );
168 $checkbox = $this->ui->makeBlock( $checkbox )
169 ->addAttr('class', 'sh4-shift-checker')
170 ->addAttr('style', 'display: none;')
171 ;
172 $thisView = $this->ui->makeCollection( array($thisView, $checkbox, $menu) );
173 }
174
175 $thisView = $this->ui->makeBlock( $thisView )
176 ->tag('block')
177 ->addAttr('class', 'sh4-shift-widget')
178 ;
179 $outShifts[] = $thisView;
180
181 $this->shiftsDuration->add( $shift );
182 }
183 $outShifts = $this->ui->makeList( $outShifts )->gutter(1);
184
185 $thisOut[] = $outShifts;
186
187 // report
188 $outReport = $this->common->renderReport( $this->shiftsDuration );
189
190 // new links
191 $links = array();
192
193 if( $thisCalendar->isTimeOff() ){
194 $label = '+' . ' ' . '__Time Off__';
195 }
196 elseif( $thisCalendar->isAvailability() ){
197 $label = '+' . ' ' . '__Availability__';
198 }
199 else {
200 $label = '+' . ' ' . '__Shift__';
201 }
202
203 $to = 'new';
204 $toParams = array(
205 'calendar' => $calendarId
206 );
207 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
208 $toParams['employee'] = $params['employee'][0];
209 }
210
211 $allowed = $this->newAcl->checkNewShift( $toParams );
212 if( $allowed ){
213 $to = array( $to, $toParams );
214 $newLink = $this->ui->makeAhref( $to, $label )
215 ->tag('secondary')
216 ;
217 $links[] = $newLink;
218 }
219
220 if( $links ){
221 $links = $this->ui->makeListInline( $links )
222 ->gutter(1)
223 ;
224 $calendarView = $this->ui->makeListInline( array($calendarView, $links) );
225 }
226
227 $onTop = $this->ui->makeGrid()
228 ->add( $calendarView, 4, 12 )
229 ->add( $outReport, 8, 12 )
230 ;
231
232 $thisOut = $this->ui->makeList( $thisOut );
233 $thisOut = $this->ui->makeList( array($onTop, $thisOut) );
234
235 $out[] = $thisOut;
236 }
237
238 $out = $this->ui->makeList( $out )
239 ->gutter(4)
240 ;
241
242 return $out;
243 }
244
245 public function renderByEmployee()
246 {
247 $params = $this->request->getParams();
248 $startDate = $params['start'];
249
250 $calendars = $this->common->getCalendars();
251 $employees = $this->common->getEmployees();
252
253 $shifts = $this->common->getShifts();
254
255 $hideui = $params['hideui'];
256 $noZoom = in_array('shiftdetails', $hideui);
257
258 $viewEmployees = array();
259 foreach( $employees as $employee ){
260 $label = $this->employeesPresenter->presentTitle( $employee );
261 $label = $this->ui->makeSpan( $label )
262 ->tag('font-size', 5)
263 ;
264 $viewEmployees[ $employee->getId() ] = $label;
265 }
266
267 $shiftsBy = array();
268
269 $iknow = array( 'employee' );
270
271 $allCalendars = $this->common->findAllCalendars();
272 if( count($allCalendars) <= 1 ) $iknow[] = 'calendar';
273
274 $hori = TRUE;
275
276 foreach( $shifts as $shift ){
277 $employee = $shift->getEmployee();
278 $employeeId = $employee ? $employee->getId() : 0;
279 if( ! array_key_exists($employeeId, $shiftsBy) ){
280 $shiftsBy[$employeeId] = array();
281 }
282 $shiftsBy[$employeeId][] = $shift;
283 }
284
285 $out = array();
286 foreach( $viewEmployees as $employeeId => $employeeView ){
287 if( ! isset($shiftsBy[$employeeId]) ){
288 continue;
289 }
290
291 $thisOut = array();
292
293 $this->shiftsDuration->reset();
294 $counted = 0;
295 $outShifts = array();
296
297 foreach( $shiftsBy[$employeeId] as $shift ){
298 $id = $shift->getId();
299 $thisView = $this->renderShift( $shift, $iknow, $hori, $noZoom );
300
301 $menu = array();
302 $fullMenu = $this->shiftsCommon->menu( $shift );
303 foreach( $fullMenu as $k0 => $thisMenu ){
304 foreach( $thisMenu as $k1 => $actionArray ){
305 $k = $k0 . '_' . $k1;
306 $menu[$k] = $actionArray;
307 }
308 }
309 if( $menu ){
310 $menu = $this->ui->helperActionsFromArray( $menu, TRUE );
311 $menu = $this->ui->makeCollection( $menu );
312
313 $checkbox = $this->ui->makeInputCheckbox( 'id[]', NULL, $id, TRUE );
314 $checkbox = $this->ui->makeBlock( $checkbox )
315 ->addAttr('class', 'sh4-shift-checker')
316 ->addAttr('style', 'display: none;')
317 ;
318 $thisView = $this->ui->makeCollection( array($thisView, $checkbox, $menu) );
319 }
320
321 $thisView = $this->ui->makeBlock( $thisView )
322 ->tag('block')
323 ->addAttr('class', 'sh4-shift-widget')
324 ;
325
326 $outShifts[] = $thisView;
327
328 $shiftCalendar = $shift->getCalendar();
329 // if( ! $shiftCalendar->isShift() ){
330 // continue;
331 // }
332 $this->shiftsDuration->add( $shift );
333 $counted++;
334 }
335
336 $outShifts = $this->ui->makeList( $outShifts )->gutter(1);
337 $thisOut[] = $outShifts;
338
339 // report
340 $outReport = NULL;
341 if( $counted ){
342 $outReport = $this->common->renderReport( $this->shiftsDuration );
343 }
344
345 // new links
346 $newLinks = array();
347
348 $label = '+' . ' ' . '__Shift__';
349 $to = 'new/shift';
350 $toParams = array(
351 'employee' => $employeeId
352 );
353
354 $allowed = $this->newAcl->checkNewShift( $toParams );
355 if( $allowed ){
356 $to = array( $to, $toParams );
357 $link = $this->ui->makeAhref( $to, $label )
358 ->tag('secondary')
359 ;
360 $newLinks[] = $link;
361 }
362
363 $label = '+' . ' ' . '__Time Off__';
364 $to = 'new/timeoff';
365 $toParams = array(
366 'employee' => $employeeId
367 );
368
369 $allowed = $this->newAcl->checkNewTimeoff( $toParams );
370 if( $allowed ){
371 $to = array( $to, $toParams );
372 $link = $this->ui->makeAhref( $to, $label )
373 ->tag('secondary')
374 ;
375 $newLinks[] = $link;
376 }
377
378 if( $newLinks ){
379 $newLinks = $this->ui->makeListInline( $newLinks )
380 ->gutter(1)
381 ;
382 $employeeView = $this->ui->makeListInline( array($employeeView, $newLinks) );
383 }
384
385 $onTop = $this->ui->makeGrid()
386 ->add( $employeeView, 4, 12 )
387 ->add( $outReport, 8, 12 )
388 ;
389
390 $thisOut = $this->ui->makeList( $thisOut );
391 $thisOut = $this->ui->makeList( array($onTop, $thisOut) );
392
393 $out[] = $thisOut;
394 }
395
396 $out = $this->ui->makeList( $out )
397 ->gutter(4)
398 ;
399
400 return $out;
401 }
402
403 public function renderShift( $shift, $iknow, $hori )
404 {
405 $params = $this->request->getParams();
406
407 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
408 if( ! in_array(-1, $params['employee']) ){
409 $iknow[] = 'employee';
410 }
411 }
412 if( array_key_exists('calendar', $params) && (count($params['calendar']) == 1) ){
413 $iknow[] = 'calendar';
414 }
415
416 $out = $this->widget->render( $shift, $iknow, $hori );
417 return $out;
418 }
419 }