PluginProbe
ShiftController Employee Shift Scheduling / 4.9.69
ShiftController Employee Shift Scheduling v4.9.69
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.69, at sh4/schedule/html/view/month.php

859 lines 22.3 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 $title = htmlspecialchars( $label );
570
571 $description = $employee->getDescription();
572 if( strlen($description) ){
573 $imgpos = strpos( $description, '<img' );
574 if( false !== $imgpos ){
575 $label = $this->ui->makeList( array($label, $description) );
576 }
577 else {
578 $title .= "\n" . htmlspecialchars( $description );
579 }
580 }
581
582 $label = $this->ui->makeSpan( $label )
583 ->tag( 'font-size', 4 )
584 ->addAttr( 'title', $title )
585 ;
586
587 $viewEmployees[ $employee->getId() ] = $label;
588 }
589
590 $viewShifts = array();
591
592 $iknow = array('employee', 'date');
593
594 $allCalendars = $this->common->findAllCalendars();
595 if( count($allCalendars) <= 1 ) $iknow[] = 'calendar';
596
597 foreach( $shifts as $shift ){
598 $employee = $shift->getEmployee();
599 $id = $employee ? $employee->getId() : 0;
600
601 if( ! array_key_exists($id, $viewShifts) ){
602 $viewShifts[$id] = array();
603 }
604
605 $start = $shift->getStart();
606 $end = $shift->getEnd();
607
608 $startDayTime = substr($start, 8, 4);
609 $endDayTime = substr($end, 8, 4);
610 $shiftAllDay = ( (0 == $startDayTime) && (0 == $endDayTime) ) ? TRUE : FALSE;
611
612 $this->t->setDateTimeDb( $end )->modify('-1 second');
613 $shiftEndDate = $this->t->formatDateDb();
614
615 $this->t->setDateTimeDb( $start );
616 $shiftStartDate = $this->t->formatDateDb();
617
618 $rexDate = $shiftStartDate;
619 while( $rexDate <= $shiftEndDate ){
620 if( in_array($rexDate, $dates) ){
621 if( ! array_key_exists($rexDate, $viewShifts[$id]) ){
622 $viewShifts[$id][$rexDate] = array();
623 }
624 $viewShifts[$id][$rexDate][] = $shift;
625 }
626
627 if( ! $shiftAllDay ){
628 break;
629 }
630 $this->t->modify( '+1 day' );
631 $rexDate = $this->t->formatDateDb();
632 }
633 }
634
635 $header = array();
636 $header[] = null;
637
638 $weekStartsOn = $this->t->getWeekStartsOn();
639 $weekSegments = array();
640
641 $this->t->setDateDb( $startDate );
642 $monthMatrix = $this->t->getMonthMatrix( $disabledWeekdays );
643
644 foreach( $monthMatrix as $week => $days ){
645 $wdi = 0;
646 foreach( $days as $date ){
647 if( ! $date ){
648 continue;
649 }
650
651 $dateView = $this->common->renderDateLabelGrouped( $date );
652 $header[] = $dateView;
653
654 if( ! $wdi ){
655 $weekSegments[] = count($header);
656 }
657
658 $wdi++;
659 }
660 }
661
662 // while( count($header) < 32 ){
663 // $header[] = NULL;
664 // }
665
666 $rows = array();
667 foreach( $viewEmployees as $id => $employeeView ){
668 $row = array();
669
670 $this->shiftsDuration->reset();
671 if( isset($viewShifts[$id]) ){
672 $counted = 0;
673 foreach( $viewShifts[$id] as $date => $dateShifts ){
674 foreach( $dateShifts as $shift ){
675 $shiftCalendar = $shift->getCalendar();
676 // if( $shiftCalendar->isTimeoff() ){
677 // continue;
678 // }
679 $this->shiftsDuration->add( $shift );
680 $counted++;
681 }
682 }
683
684 if( $counted ){
685 $outReport = $this->common->renderReport( $this->shiftsDuration, FALSE );
686 $outReport = $this->ui->makeSpan( $outReport )
687 ->tag('font-size', 2)
688 ;
689 $employeeView = $this->ui->makeList( array($employeeView, $outReport) )
690 ->gutter(1)
691 ;
692 }
693 }
694
695 $thisShifts = isset( $view_shifts[$id] ) ? $view_shifts[$id] : array();
696 $employeeView = $this->common->employeeRowLabel( $employeeView, $id, 'month', $dates, $thisShifts );
697
698 $employeeView = $this->ui->makeBlock( $employeeView )
699 ->tag('padding', array('x1', 'y2'))
700 ->tag('nowrap')
701 ;
702 $row[] = $employeeView;
703
704 foreach( $dates as $date ){
705 $cell = array();
706
707 if( isset($viewShifts[$id][$date]) ){
708 if( $this->slimView ){
709 $shiftsView = $this->self->renderDay( $viewShifts[$id][$date], $iknow );
710 }
711 else {
712 $shiftsView = $this->viewWeek->renderDay( $viewShifts[$id][$date], $iknow );
713 }
714 $cell[] = $shiftsView;
715 }
716
717 $comboId = 0 . '-' . $id;
718 if( isset($this->allCombos[$comboId]) ){
719 $label = '+';
720
721 $to = 'new';
722 $toParams = array(
723 'date' => $date,
724 'employee' => $id,
725 );
726 $to = array( $to, $toParams );
727
728 $link = $this->ui->makeAhref( $to, $label )
729 ->tag('tab-link')
730 ->tag('align', 'center')
731 ->addAttr('title', '__Add New__')
732 ;
733
734 if( $today > $date ){
735 $link->tag('muted', 3);
736 }
737
738 $cell[] = $link;
739 }
740
741 $cell = $this->ui->makeList( $cell )
742 ->gutter(1)
743 ->tag('margin', '05')
744 ;
745
746 $row[] = $cell;
747 }
748
749 // while( count($row) < 32 ){
750 // $row[] = NULL;
751 // }
752 $rows[] = $row;
753 }
754
755 $out = $this->ui->makeTable( $header, $rows, false )
756 ->gutter(0)
757 ->setBordered( $this->borderColor )
758 ->setSegments( $weekSegments )
759 ->setLabelled( true )
760 ;
761
762 if( ! $this->slimView ){
763 $out->forceColWidth( '6rem' );
764 $out->forceRowHeaderWidth( '10rem' );
765 }
766
767 return $out;
768 }
769
770 public function renderDay( $shifts, $iknow )
771 {
772 $return = NULL;
773 if( ! $shifts ){
774 return $return;
775 }
776
777 $params = $this->request->getParams();
778
779 $hideui = $params['hideui'];
780 $noZoom = in_array('shiftdetails', $hideui);
781
782 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
783 if( ! in_array(-1, $params['employee']) ){
784 $iknow[] = 'employee';
785 }
786 }
787 if( array_key_exists('calendar', $params) && (count($params['calendar']) == 1) ){
788 $iknow[] = 'calendar';
789 }
790
791 // groups?
792 $groups = array();
793 $groupedShifts = array();
794 reset( $shifts );
795 foreach( $shifts as $shift ){
796 if( ! $shift->isOpen() ){
797 continue;
798 }
799
800 $groupId = $shift->getGroupingId();
801
802 if( ! isset($groups[$groupId]) ){
803 $groups[ $groupId ] = $shift->getId();
804 $groupedShifts[ $shift->getId() ] = array( $shift->getId() => $shift );
805 }
806 else {
807 $mainShiftId = $groups[ $groupId ];
808 $groupedShifts[ $mainShiftId ][ $shift->getId() ] = $shift;
809 $groupedShifts[ $shift->getId() ] = 0;
810 }
811 }
812
813 $return = array();
814 reset( $shifts );
815 foreach( $shifts as $shift ){
816 $id = $shift->getId();
817
818 if( isset($groupedShifts[$id]) && (! $groupedShifts[$id]) ){
819 continue;
820 }
821
822 $groupedQty = NULL;
823 if( isset($groupedShifts[$id]) && (count($groupedShifts[$id]) > 1) ){
824 $groupedQty = count($groupedShifts[$id]);
825 }
826
827 $thisView = $this->widget->renderCompact( $shift, $iknow, $groupedQty );
828
829 if( ! $noZoom ){
830 $to = 'shifts/' . $id;
831 $thisView = $this->ui->makeAhref( $to, $thisView )
832 ->tag('unstyled-link')
833 ->tag('block')
834 ->tag('print')
835 ->addAttr('class', 'sh4-widget-loader')
836 ;
837 }
838
839 $buildMenuFromShifts = isset($groupedShifts[$id]) ? $groupedShifts[$id] : array( $shift );
840 $menu = $this->shiftsCommon->bulkMenu( $buildMenuFromShifts );
841 if( $menu ){
842 $thisView = $this->ui->makeCollection( array($thisView, $menu) );
843 }
844
845 $thisView = $this->ui->makeBlock( $thisView )
846 ->tag('block')
847 ->addAttr('class', 'sh4-shift-widget')
848 ;
849
850 $return[] = $thisView;
851 }
852
853 $return = $this->ui->makeList( $return )
854 ->gutter(1)
855 ;
856
857 return $return;
858 }
859 }