PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
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 / month.php

month.php in ShiftController Employee Shift Scheduling 4.9.66, at sh4/schedule/html/view/month.php

854 lines 22.2 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 #[AllowDynamicProperties]
3 class SH4_Schedule_Html_View_Month
4 {
5 protected $borderColor = 'gray';
6 protected $allCombos = array();
7 protected $allCombosShift = array();
8 protected $allCombosTimeoff = array();
9 protected $slimView = true;
10
11 public function __construct(
12 HC3_Hooks $hooks,
13 HC3_Ui $ui,
14 HC3_Request $request,
15 HC3_Time $t,
16 HC3_Settings $settings,
17
18 HC3_Uri $uri,
19
20 SH4_New_Acl $newAcl,
21
22 SH4_Shifts_Duration $shiftsDuration,
23 SH4_Schedule_Html_View_Week $viewWeek,
24 SH4_Shifts_View_Widget $widget,
25 SH4_Calendars_Presenter $calendarsPresenter,
26 SH4_Employees_Presenter $employeesPresenter,
27 SH4_Schedule_Html_View_Common $common,
28 SH4_Shifts_View_Common $shiftsCommon
29 )
30 {
31 $this->self = $hooks->wrap($this);
32
33 $this->ui = $ui;
34
35 $this->uri = $uri;
36 $this->t = $t;
37 $this->request = $request;
38
39 $this->settings = $hooks->wrap( $settings );
40 $this->newAcl = $hooks->wrap( $newAcl );
41
42 $this->viewWeek = $hooks->wrap( $viewWeek );
43 $this->shiftsDuration = $hooks->wrap( $shiftsDuration );
44 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
45 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
46
47 $this->widget = $hooks->wrap( $widget );
48 $this->common = $hooks->wrap( $common );
49 $this->shiftsCommon = $hooks->wrap( $shiftsCommon );
50
51 $this->allCombos = $this->newAcl->findAllCombos();
52 $this->allCombosShift = $this->newAcl->findAllCombosShift();
53 $this->allCombosTimeoff = $this->newAcl->findAllCombosTimeoff();
54
55 $this->slimView = $this->settings->get( 'datetime_month_slim_view' ) ? true : false;
56 }
57
58 public function render()
59 {
60 $slug = $this->request->getSlug();
61 $today = $this->t->setNow()->formatDateDb();
62
63 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
64
65 $shifts = $this->common->getShifts();
66
67 $params = $this->request->getParams();
68 $startDate = $params['start'];
69
70 $startDate = $this->t->setDateDb( $startDate )->setStartMonth()->formatDateDb();
71 $endDate = $this->t->modify('+1 month')->modify('-1 day')->formatDateDb();
72
73 $this->t->setDateDb( $startDate );
74 $dates = array();
75 $rexDate = $startDate;
76 while( $rexDate <= $endDate ){
77 if( $disabledWeekdays ){
78 $wkd = $this->t->getWeekday();
79 if( in_array($wkd, $disabledWeekdays) ){
80 $rexDate = $this->t->modify('+1 day')->formatDateDb();
81 continue;
82 }
83 }
84
85 $dates[] = $rexDate;
86 $rexDate = $this->t->modify('+1 day')->formatDateDb();
87 }
88
89 $viewShifts = array();
90 $iknow = array('date');
91
92 $allCalendars = $this->common->findAllCalendars();
93 if( count($allCalendars) <= 1 ) $iknow[] = 'calendar';
94
95 $this->shiftsDuration->reset();
96 foreach( $shifts as $shift ){
97 $this->shiftsDuration->add( $shift );
98 $start = $shift->getStart();
99 $end = $shift->getEnd();
100
101 $startDayTime = substr($start, 8, 4);
102 $endDayTime = substr($end, 8, 4);
103 $shiftAllDay = ( (0 == $startDayTime) && (0 == $endDayTime) ) ? TRUE : FALSE;
104
105 $this->t->setDateTimeDb( $end )->modify('-1 second');
106 $shiftEndDate = $this->t->formatDateDb();
107
108 $this->t->setDateTimeDb( $start );
109 $shiftStartDate = $this->t->formatDateDb();
110
111 $rexDate = $shiftStartDate;
112 while( $rexDate <= $shiftEndDate ){
113 if( in_array($rexDate, $dates) ){
114 if( ! array_key_exists($rexDate, $viewShifts) ){
115 $viewShifts[$rexDate] = array();
116 }
117 $viewShifts[$rexDate][] = $shift;
118 }
119
120 if( ! $shiftAllDay ){
121 break;
122 }
123 $this->t->modify( '+1 day' );
124 $rexDate = $this->t->formatDateDb();
125 }
126 }
127
128 $this->t->setDateDb( $startDate );
129 $monthMatrix = $this->t->getMonthMatrix( $disabledWeekdays );
130
131 $rows = array();
132 foreach( $monthMatrix as $week => $days ){
133 $row = array();
134
135 foreach( $days as $date ){
136 if( ! $date ){
137 $row[] = NULL;
138 continue;
139 }
140
141 $cell = array();
142
143 $dateView = $this->common->renderDateLabel( $date );
144 $cell[] = $dateView;
145
146 if( isset($viewShifts[$date]) ){
147 $shiftsView = $this->viewWeek->renderDay( $viewShifts[$date], $iknow );
148 $cell[] = $shiftsView;
149 }
150
151 $to = 'new';
152 $toParams = array(
153 'date' => $date
154 );
155 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
156 if( ! in_array(-1, $params['employee']) ){
157 $toParams['employee'] = $params['employee'][0];
158 }
159 }
160
161 $links = array();
162
163 if( $this->allCombosShift ){
164 $label = '+' . ' ' . '__Shift__';
165 $thisTo = 'new/shift';
166 $thisTo = array( $thisTo, $toParams );
167 $link = $this->ui->makeAhref( $thisTo, $label )
168 ->tag('tab-link')
169 ->tag('align', 'center')
170 // ->addAttr('title', '__Add New__')
171 ;
172 if( $today > $date ){
173 $link->tag('muted', 3);
174 }
175 $links[] = $link;
176 }
177
178 if( $this->allCombosTimeoff ){
179 $label = '+' . ' ' . '__Time Off__';
180 $thisTo = 'new/timeoff';
181 $thisTo = array( $thisTo, $toParams );
182 $link = $this->ui->makeAhref( $thisTo, $label )
183 ->tag('tab-link')
184 ->tag('align', 'center')
185 // ->addAttr('title', '__Add New__')
186 ;
187 if( $today > $date ){
188 $link->tag('muted', 3);
189 }
190 $links[] = $link;
191 }
192
193 $links = $this->ui->makeList( $links )->gutter(0);
194
195 $cell[] = $links;
196
197 $cell = $this->ui->makeList( $cell )
198 ->gutter(1)
199 ->tag('margin', 1)
200 ;
201
202 $row[] = $cell;
203 }
204
205 $rows[] = $row;
206 }
207
208 $out = $this->ui->makeTable( NULL, $rows, FALSE )
209 ->gutter(0)
210 ->setBordered( $this->borderColor )
211 // ->setSegments( $weekSegments )
212 ;
213
214 return $out;
215 }
216
217 public function renderByCalendar()
218 {
219 $slug = $this->request->getSlug();
220 $today = $this->t->setNow()->formatDateDb();
221
222 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
223
224 $calendars = $this->common->getCalendars();
225 $employees = $this->common->getEmployees();
226 $shifts = $this->common->getShifts();
227
228 // finalize calendars to include those that employee was removed from but still have shifts in
229 $listCalendarId = array_keys( $calendars );
230 $dictCalendarId = array_combine( $listCalendarId, $listCalendarId );
231 foreach( $shifts as $shift ){
232 $calendar = $shift->getCalendar();
233 if( ! $calendar ) continue;
234 $calendarId = $calendar->getId();
235 $dictCalendarId[ $calendarId ] = $calendarId;
236 }
237 if( count($dictCalendarId) > count($calendars) ){
238 $allCalendars = $this->common->findAllCalendars();
239 $calendars = array_intersect_key( $allCalendars, $dictCalendarId );
240 }
241
242 // we can probably have archived calendars so if such calendars have no shifts then skip them
243 $removeArchivedCalendars = array();
244 foreach( $calendars as $calendar ){
245 if( $calendar->isArchived() ){
246 $removeArchivedCalendars[ $calendar->getId() ] = $calendar->getId();
247 }
248 }
249 if( $removeArchivedCalendars ){
250 foreach( $shifts as $shift ){
251 $calendar = $shift->getCalendar();
252 $id = $calendar ? $calendar->getId() : 0;
253 if( isset($removeArchivedCalendars[$id]) ){
254 unset( $removeArchivedCalendars[$id] );
255 }
256 if( ! $removeArchivedCalendars ){
257 break;
258 }
259 }
260 foreach( $removeArchivedCalendars as $id ){
261 unset( $calendars[$id] );
262 }
263 reset( $shifts );
264 }
265
266 $params = $this->request->getParams();
267 $startDate = $params['start'];
268
269 $startDate = $this->t->setDateDb( $startDate )->setStartMonth()->formatDateDb();
270 $endDate = $this->t->modify('+1 month')->modify('-1 day')->formatDateDb();
271
272 $this->t->setDateDb( $startDate );
273 $dates = array();
274 $rexDate = $startDate;
275 while( $rexDate <= $endDate ){
276 if( $disabledWeekdays ){
277 $wkd = $this->t->getWeekday();
278 if( in_array($wkd, $disabledWeekdays) ){
279 $rexDate = $this->t->modify('+1 day')->formatDateDb();
280 continue;
281 }
282 }
283
284 $dates[] = $rexDate;
285 $rexDate = $this->t->modify('+1 day')->formatDateDb();
286 }
287
288 $viewCalendars = array();
289 foreach( $calendars as $calendar ){
290 $label = $this->calendarsPresenter->presentTitle( $calendar );
291 $title = htmlspecialchars( $calendar->getTitle() );
292 $description = $calendar->getDescription();
293 if( strlen($description) ){
294 $description = htmlspecialchars( $description );
295 $title .= "\n" . $description;
296 }
297
298 $label = $this->ui->makeSpan( $label )
299 ->addAttr( 'title', $title )
300 ;
301
302 $viewCalendars[ $calendar->getId() ] = $label;
303 }
304
305 $viewShifts = array();
306
307 $iknow = array('calendar', 'date');
308 foreach( $shifts as $shift ){
309 $calendar = $shift->getCalendar();
310 $id = $calendar ? $calendar->getId() : 0;
311
312 if( ! array_key_exists($id, $viewShifts) ){
313 $viewShifts[$id] = array();
314 }
315
316 $start = $shift->getStart();
317 $end = $shift->getEnd();
318
319 $startDayTime = substr($start, 8, 4);
320 $endDayTime = substr($end, 8, 4);
321 $shiftAllDay = ( (0 == $startDayTime) && (0 == $endDayTime) ) ? TRUE : FALSE;
322
323 $this->t->setDateTimeDb( $end )->modify('-1 second');
324 $shiftEndDate = $this->t->formatDateDb();
325
326 $this->t->setDateTimeDb( $start );
327 $shiftStartDate = $this->t->formatDateDb();
328
329 $rexDate = $shiftStartDate;
330 while( $rexDate <= $shiftEndDate ){
331 if( in_array($rexDate, $dates) ){
332 if( ! array_key_exists($rexDate, $viewShifts[$id]) ){
333 $viewShifts[$id][$rexDate] = array();
334 }
335 $viewShifts[$id][$rexDate][] = $shift;
336 }
337
338 if( ! $shiftAllDay ){
339 break;
340 }
341 $this->t->modify( '+1 day' );
342 $rexDate = $this->t->formatDateDb();
343 }
344 }
345
346 $header = array();
347 $header[] = NULL;
348
349 $weekStartsOn = $this->t->getWeekStartsOn();
350 $weekSegments = array();
351
352 $this->t->setDateDb( $startDate );
353 $monthMatrix = $this->t->getMonthMatrix( $disabledWeekdays );
354
355 foreach( $monthMatrix as $week => $days ){
356 $wdi = 0;
357 foreach( $days as $date ){
358 if( ! $date ){
359 continue;
360 }
361
362 $dateView = $this->common->renderDateLabelGrouped( $date );
363 $header[] = $dateView;
364
365 if( ! $wdi ){
366 $weekSegments[] = count($header);
367 }
368
369 $wdi++;
370 }
371 }
372
373 // while( count($header) < 32 ){
374 // $header[] = NULL;
375 // }
376
377 $rows = array();
378 foreach( $viewCalendars as $id => $calendarView ){
379 $row = array();
380
381 $this->shiftsDuration->reset();
382 if( isset($viewShifts[$id]) ){
383 foreach( $viewShifts[$id] as $date => $dateShifts ){
384 foreach( $dateShifts as $shift ){
385 $this->shiftsDuration->add( $shift );
386 }
387 }
388
389 $outReport = $this->common->renderReport( $this->shiftsDuration, FALSE );
390 $outReport = $this->ui->makeSpan( $outReport )
391 ->tag('font-size', 2)
392 ;
393 $calendarView = $this->ui->makeList( array($calendarView, $outReport) )
394 ->gutter(1)
395 ;
396 }
397
398 $calendarView = $this->ui->makeBlock( $calendarView )
399 ->tag('padding', array('x1', 'y2'))
400 ->tag('nowrap')
401 ;
402 $row[] = $calendarView;
403
404 $countDates = count( $dates );
405 foreach( $dates as $date ){
406 $cell = array();
407
408 if( isset($viewShifts[$id][$date]) ){
409 if( $countDates <= 10 ){
410 $shiftsView = $this->viewWeek->renderDay( $viewShifts[$id][$date], $iknow );
411 }
412 else {
413 $shiftsView = $this->self->renderDay( $viewShifts[$id][$date], $iknow );
414 }
415 $cell[] = $shiftsView;
416 }
417
418 $label = '+';
419
420 $to = 'new';
421 $toParams = array(
422 'date' => $date,
423 'calendar' => $id,
424 );
425 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
426 if( ! in_array(-1, $params['employee']) ){
427 $toParams['employee'] = $params['employee'][0];
428 }
429 }
430 $to = array( $to, $toParams );
431
432 $addOk = FALSE;
433 if( isset($toParams['employee']) ){
434 $testComboId = $id . '-' . $toParams['employee'];
435 if( isset($this->allCombos[$testComboId]) ){
436 $addOk = TRUE;
437 }
438 }
439 else {
440 $testComboId = $id . '-';
441 reset( $this->allCombos );
442 foreach( $this->allCombos as $comboId ){
443 if( $testComboId == substr($comboId, 0, strlen($testComboId)) ){
444 $addOk = TRUE;
445 break;
446 }
447 }
448 }
449
450 if( $addOk ){
451 $link = $this->ui->makeAhref( $to, $label )
452 ->tag('tab-link')
453 ->tag('align', 'center')
454 ->addAttr('title', '__Add New__')
455 ;
456
457 if( $today > $date ){
458 $link->tag('muted', 3);
459 }
460
461 $cell[] = $link;
462 }
463
464 $cell = $this->ui->makeList( $cell )
465 ->gutter(1)
466 ->tag('margin', '05')
467 ;
468
469 $row[] = $cell;
470 }
471
472 // while( count($row) < 32 ){
473 // $row[] = NULL;
474 // }
475 $rows[] = $row;
476 }
477
478 $out = $this->ui->makeTable( $header, $rows, FALSE )
479 ->gutter(0)
480 ->setBordered( $this->borderColor )
481 ->setSegments( $weekSegments )
482 ->setLabelled( TRUE )
483 ;
484
485 if( ! $this->slimView ){
486 $out->forceColWidth( '6rem' );
487 $out->forceRowHeaderWidth( '10rem' );
488 }
489
490 return $out;
491 }
492
493 public function renderByEmployee()
494 {
495 $slug = $this->request->getSlug();
496 $today = $this->t->setNow()->formatDateDb();
497
498 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
499
500 $calendars = $this->common->getCalendars();
501 $employees = $this->common->getEmployees();
502 $shifts = $this->common->getShifts();
503
504 // finalize employees to include those that employee was removed from but still have shifts in
505 $listEmployeeId = array_keys( $employees );
506 $dictEmployeeId = array_combine( $listEmployeeId, $listEmployeeId );
507 foreach( $shifts as $shift ){
508 $employee = $shift->getEmployee();
509 if( ! $employee ) continue;
510 $employeeId = $employee->getId();
511 $dictEmployeeId[ $employeeId ] = $employeeId;
512 }
513 if( count($dictEmployeeId) > count($employees) ){
514 $allEmployees = $this->common->findAllEmployees();
515 $employees = array_intersect_key( $allEmployees, $dictEmployeeId );
516 }
517
518 // we can probably have archived employees so if such employees have no shifts then skip them
519 $removeArchivedEmployees = array();
520 foreach( $employees as $employee ){
521 if( $employee->isArchived() ){
522 $removeArchivedEmployees[ $employee->getId() ] = $employee->getId();
523 }
524 }
525 if( $removeArchivedEmployees ){
526 foreach( $shifts as $shift ){
527 $employee = $shift->getEmployee();
528 $id = $employee ? $employee->getId() : 0;
529 if( isset($removeArchivedEmployees[$id]) ){
530 unset( $removeArchivedEmployees[$id] );
531 }
532 if( ! $removeArchivedEmployees ){
533 break;
534 }
535 }
536 foreach( $removeArchivedEmployees as $id ){
537 unset( $employees[$id] );
538 }
539 reset( $shifts );
540 }
541
542 $params = $this->request->getParams();
543 $startDate = $params['start'];
544
545 $startDate = $this->t->setDateDb( $startDate )->setStartMonth()->formatDateDb();
546 $endDate = $this->t->modify('+1 month')->modify('-1 day')->formatDateDb();
547
548 $this->t->setDateDb( $startDate );
549 $dates = array();
550 $rexDate = $startDate;
551 while( $rexDate <= $endDate ){
552 if( $disabledWeekdays ){
553 $wkd = $this->t->getWeekday();
554 if( in_array($wkd, $disabledWeekdays) ){
555 $rexDate = $this->t->modify('+1 day')->formatDateDb();
556 continue;
557 }
558 }
559
560 $dates[] = $rexDate;
561 $rexDate = $this->t->modify('+1 day')->formatDateDb();
562 }
563
564 $countDates = count( $dates );
565
566 $viewEmployees = array();
567 foreach( $employees as $employee ){
568 $label = $this->employeesPresenter->presentTitle( $employee );
569
570 $title = htmlspecialchars( $label );
571 $description = $employee->getDescription();
572 if( strlen($description) ){
573 $description = htmlspecialchars( $description );
574 $title .= "\n" . $description;
575 }
576
577 $label = $this->ui->makeSpan( $label )
578 ->tag( 'font-size', 4 )
579 ->addAttr( 'title', $title )
580 ;
581
582 $viewEmployees[ $employee->getId() ] = $label;
583 }
584
585 $viewShifts = array();
586
587 $iknow = array('employee', 'date');
588
589 $allCalendars = $this->common->findAllCalendars();
590 if( count($allCalendars) <= 1 ) $iknow[] = 'calendar';
591
592 foreach( $shifts as $shift ){
593 $employee = $shift->getEmployee();
594 $id = $employee ? $employee->getId() : 0;
595
596 if( ! array_key_exists($id, $viewShifts) ){
597 $viewShifts[$id] = array();
598 }
599
600 $start = $shift->getStart();
601 $end = $shift->getEnd();
602
603 $startDayTime = substr($start, 8, 4);
604 $endDayTime = substr($end, 8, 4);
605 $shiftAllDay = ( (0 == $startDayTime) && (0 == $endDayTime) ) ? TRUE : FALSE;
606
607 $this->t->setDateTimeDb( $end )->modify('-1 second');
608 $shiftEndDate = $this->t->formatDateDb();
609
610 $this->t->setDateTimeDb( $start );
611 $shiftStartDate = $this->t->formatDateDb();
612
613 $rexDate = $shiftStartDate;
614 while( $rexDate <= $shiftEndDate ){
615 if( in_array($rexDate, $dates) ){
616 if( ! array_key_exists($rexDate, $viewShifts[$id]) ){
617 $viewShifts[$id][$rexDate] = array();
618 }
619 $viewShifts[$id][$rexDate][] = $shift;
620 }
621
622 if( ! $shiftAllDay ){
623 break;
624 }
625 $this->t->modify( '+1 day' );
626 $rexDate = $this->t->formatDateDb();
627 }
628 }
629
630 $header = array();
631 $header[] = null;
632
633 $weekStartsOn = $this->t->getWeekStartsOn();
634 $weekSegments = array();
635
636 $this->t->setDateDb( $startDate );
637 $monthMatrix = $this->t->getMonthMatrix( $disabledWeekdays );
638
639 foreach( $monthMatrix as $week => $days ){
640 $wdi = 0;
641 foreach( $days as $date ){
642 if( ! $date ){
643 continue;
644 }
645
646 $dateView = $this->common->renderDateLabelGrouped( $date );
647 $header[] = $dateView;
648
649 if( ! $wdi ){
650 $weekSegments[] = count($header);
651 }
652
653 $wdi++;
654 }
655 }
656
657 // while( count($header) < 32 ){
658 // $header[] = NULL;
659 // }
660
661 $rows = array();
662 foreach( $viewEmployees as $id => $employeeView ){
663 $row = array();
664
665 $this->shiftsDuration->reset();
666 if( isset($viewShifts[$id]) ){
667 $counted = 0;
668 foreach( $viewShifts[$id] as $date => $dateShifts ){
669 foreach( $dateShifts as $shift ){
670 $shiftCalendar = $shift->getCalendar();
671 // if( $shiftCalendar->isTimeoff() ){
672 // continue;
673 // }
674 $this->shiftsDuration->add( $shift );
675 $counted++;
676 }
677 }
678
679 if( $counted ){
680 $outReport = $this->common->renderReport( $this->shiftsDuration, FALSE );
681 $outReport = $this->ui->makeSpan( $outReport )
682 ->tag('font-size', 2)
683 ;
684 $employeeView = $this->ui->makeList( array($employeeView, $outReport) )
685 ->gutter(1)
686 ;
687 }
688 }
689
690 $thisShifts = isset( $view_shifts[$id] ) ? $view_shifts[$id] : array();
691 $employeeView = $this->common->employeeRowLabel( $employeeView, $id, 'month', $dates, $thisShifts );
692
693 $employeeView = $this->ui->makeBlock( $employeeView )
694 ->tag('padding', array('x1', 'y2'))
695 ->tag('nowrap')
696 ;
697 $row[] = $employeeView;
698
699 foreach( $dates as $date ){
700 $cell = array();
701
702 if( isset($viewShifts[$id][$date]) ){
703 if( $this->slimView ){
704 $shiftsView = $this->self->renderDay( $viewShifts[$id][$date], $iknow );
705 }
706 else {
707 $shiftsView = $this->viewWeek->renderDay( $viewShifts[$id][$date], $iknow );
708 }
709 $cell[] = $shiftsView;
710 }
711
712 $comboId = 0 . '-' . $id;
713 if( isset($this->allCombos[$comboId]) ){
714 $label = '+';
715
716 $to = 'new';
717 $toParams = array(
718 'date' => $date,
719 'employee' => $id,
720 );
721 $to = array( $to, $toParams );
722
723 $link = $this->ui->makeAhref( $to, $label )
724 ->tag('tab-link')
725 ->tag('align', 'center')
726 ->addAttr('title', '__Add New__')
727 ;
728
729 if( $today > $date ){
730 $link->tag('muted', 3);
731 }
732
733 $cell[] = $link;
734 }
735
736 $cell = $this->ui->makeList( $cell )
737 ->gutter(1)
738 ->tag('margin', '05')
739 ;
740
741 $row[] = $cell;
742 }
743
744 // while( count($row) < 32 ){
745 // $row[] = NULL;
746 // }
747 $rows[] = $row;
748 }
749
750 $out = $this->ui->makeTable( $header, $rows, false )
751 ->gutter(0)
752 ->setBordered( $this->borderColor )
753 ->setSegments( $weekSegments )
754 ->setLabelled( true )
755 ;
756
757 if( ! $this->slimView ){
758 $out->forceColWidth( '6rem' );
759 $out->forceRowHeaderWidth( '10rem' );
760 }
761
762 return $out;
763 }
764
765 public function renderDay( $shifts, $iknow )
766 {
767 $return = NULL;
768 if( ! $shifts ){
769 return $return;
770 }
771
772 $params = $this->request->getParams();
773
774 $hideui = $params['hideui'];
775 $noZoom = in_array('shiftdetails', $hideui);
776
777 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
778 if( ! in_array(-1, $params['employee']) ){
779 $iknow[] = 'employee';
780 }
781 }
782 if( array_key_exists('calendar', $params) && (count($params['calendar']) == 1) ){
783 $iknow[] = 'calendar';
784 }
785
786 // groups?
787 $groups = array();
788 $groupedShifts = array();
789 reset( $shifts );
790 foreach( $shifts as $shift ){
791 if( ! $shift->isOpen() ){
792 continue;
793 }
794
795 $groupId = $shift->getGroupingId();
796
797 if( ! isset($groups[$groupId]) ){
798 $groups[ $groupId ] = $shift->getId();
799 $groupedShifts[ $shift->getId() ] = array( $shift->getId() => $shift );
800 }
801 else {
802 $mainShiftId = $groups[ $groupId ];
803 $groupedShifts[ $mainShiftId ][ $shift->getId() ] = $shift;
804 $groupedShifts[ $shift->getId() ] = 0;
805 }
806 }
807
808 $return = array();
809 reset( $shifts );
810 foreach( $shifts as $shift ){
811 $id = $shift->getId();
812
813 if( isset($groupedShifts[$id]) && (! $groupedShifts[$id]) ){
814 continue;
815 }
816
817 $groupedQty = NULL;
818 if( isset($groupedShifts[$id]) && (count($groupedShifts[$id]) > 1) ){
819 $groupedQty = count($groupedShifts[$id]);
820 }
821
822 $thisView = $this->widget->renderCompact( $shift, $iknow, $groupedQty );
823
824 if( ! $noZoom ){
825 $to = 'shifts/' . $id;
826 $thisView = $this->ui->makeAhref( $to, $thisView )
827 ->tag('unstyled-link')
828 ->tag('block')
829 ->tag('print')
830 ->addAttr('class', 'sh4-widget-loader')
831 ;
832 }
833
834 $buildMenuFromShifts = isset($groupedShifts[$id]) ? $groupedShifts[$id] : array( $shift );
835 $menu = $this->shiftsCommon->bulkMenu( $buildMenuFromShifts );
836 if( $menu ){
837 $thisView = $this->ui->makeCollection( array($thisView, $menu) );
838 }
839
840 $thisView = $this->ui->makeBlock( $thisView )
841 ->tag('block')
842 ->addAttr('class', 'sh4-shift-widget')
843 ;
844
845 $return[] = $thisView;
846 }
847
848 $return = $this->ui->makeList( $return )
849 ->gutter(1)
850 ;
851
852 return $return;
853 }
854 }