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

908 lines 24.0 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
379 // link templates to speed things up
380 $toParams = array(
381 'calendar' => '{CID}',
382 'date' => '{DATE}'
383 );
384 $thisTo = 'new';
385 $thisTo = array( $thisTo, $toParams );
386 $thisHref = $this->uri->makeUrl( $thisTo );
387
388 $linkTemplateShift = '<a title="__Add New__" class="hc-block hc-theme-tab-link hc-align-center" href="' . $thisHref . '">+</a>';
389 $linkTemplateShiftMuted = '<a title="__Add New__" class="hc-block hc-theme-tab-link hc-align-center hc-muted3" href="' . $thisHref . '">+</a>';
390 $isPrintView = $this->request->isPrintView();
391
392 foreach( $viewCalendars as $id => $calendarView ){
393 $row = array();
394
395 $this->shiftsDuration->reset();
396 if( isset($viewShifts[$id]) ){
397 foreach( $viewShifts[$id] as $date => $dateShifts ){
398 foreach( $dateShifts as $shift ){
399 $this->shiftsDuration->add( $shift );
400 }
401 }
402
403 $outReport = $this->common->renderReport( $this->shiftsDuration, FALSE );
404 $outReport = $this->ui->makeSpan( $outReport )
405 ->tag('font-size', 2)
406 ;
407 $calendarView = $this->ui->makeList( array($calendarView, $outReport) )
408 ->gutter(1)
409 ;
410 }
411
412 $calendarView = $this->ui->makeBlock( $calendarView )
413 ->tag('padding', array('x1', 'y2'))
414 ->tag('nowrap')
415 ;
416 $row[] = $calendarView;
417
418 $countDates = count( $dates );
419 foreach( $dates as $date ){
420 $cell = array();
421
422 if( isset($viewShifts[$id][$date]) ){
423 if( $countDates <= 10 ){
424 $shiftsView = $this->viewWeek->renderDay( $viewShifts[$id][$date], $iknow );
425 }
426 else {
427 $shiftsView = $this->self->renderDay( $viewShifts[$id][$date], $iknow );
428 }
429 $cell[] = $shiftsView;
430 }
431
432 $label = '+';
433
434 $to = 'new';
435 $toParams = array(
436 'date' => $date,
437 'calendar' => $id,
438 );
439 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
440 if( ! in_array(-1, $params['employee']) ){
441 $toParams['employee'] = $params['employee'][0];
442 }
443 }
444 $to = array( $to, $toParams );
445
446 $addOk = FALSE;
447 if( isset($toParams['employee']) ){
448 $testComboId = $id . '-' . $toParams['employee'];
449 if( isset($this->allCombos[$testComboId]) ){
450 $addOk = TRUE;
451 }
452 }
453 else {
454 $testComboId = $id . '-';
455 reset( $this->allCombos );
456 foreach( $this->allCombos as $comboId ){
457 if( $testComboId == substr($comboId, 0, strlen($testComboId)) ){
458 $addOk = TRUE;
459 break;
460 }
461 }
462 }
463
464 if( $isPrintView ) $addOk = false;
465
466 if( $addOk ){
467 /*
468 $link = $this->ui->makeAhref( $to, $label )
469 ->tag('tab-link')
470 ->tag('align', 'center')
471 ->addAttr('title', '__Add New__')
472 ;
473
474 if( $today > $date ){
475 $link->tag('muted', 3);
476 }
477 */
478
479 if( $today > $date ){
480 $link = str_replace( array('{CID}', '{DATE}'), array($id, $date), $linkTemplateShiftMuted );
481 }
482 else {
483 $link = str_replace( array('{CID}', '{DATE}'), array($id, $date), $linkTemplateShift );
484 }
485
486 $cell[] = $link;
487 }
488
489 $cell = $this->ui->makeList( $cell )
490 ->gutter(1)
491 ->tag('margin', '05')
492 ;
493
494 $row[] = $cell;
495 }
496
497 // while( count($row) < 32 ){
498 // $row[] = NULL;
499 // }
500 $rows[] = $row;
501 }
502
503 $out = $this->ui->makeTable( $header, $rows, FALSE )
504 ->gutter(0)
505 ->setBordered( $this->borderColor )
506 ->setSegments( $weekSegments )
507 ->setLabelled( TRUE )
508 ;
509
510 if( ! $this->slimView ){
511 $out->forceColWidth( '6rem' );
512 $out->forceRowHeaderWidth( '10rem' );
513 }
514
515 return $out;
516 }
517
518 public function renderByEmployee()
519 {
520 $slug = $this->request->getSlug();
521 $today = $this->t->setNow()->formatDateDb();
522
523 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
524
525 $calendars = $this->common->getCalendars();
526 $employees = $this->common->getEmployees();
527 $shifts = $this->common->getShifts();
528
529 // finalize employees to include those that employee was removed from but still have shifts in
530 $listEmployeeId = array_keys( $employees );
531 $dictEmployeeId = array_combine( $listEmployeeId, $listEmployeeId );
532 foreach( $shifts as $shift ){
533 $employee = $shift->getEmployee();
534 if( ! $employee ) continue;
535 $employeeId = $employee->getId();
536 $dictEmployeeId[ $employeeId ] = $employeeId;
537 }
538 if( count($dictEmployeeId) > count($employees) ){
539 $allEmployees = $this->common->findAllEmployees();
540 $employees = array_intersect_key( $allEmployees, $dictEmployeeId );
541 }
542
543 // we can probably have archived employees so if such employees have no shifts then skip them
544 $removeArchivedEmployees = array();
545 foreach( $employees as $employee ){
546 if( $employee->isArchived() ){
547 $removeArchivedEmployees[ $employee->getId() ] = $employee->getId();
548 }
549 }
550 if( $removeArchivedEmployees ){
551 foreach( $shifts as $shift ){
552 $employee = $shift->getEmployee();
553 $id = $employee ? $employee->getId() : 0;
554 if( isset($removeArchivedEmployees[$id]) ){
555 unset( $removeArchivedEmployees[$id] );
556 }
557 if( ! $removeArchivedEmployees ){
558 break;
559 }
560 }
561 foreach( $removeArchivedEmployees as $id ){
562 unset( $employees[$id] );
563 }
564 reset( $shifts );
565 }
566
567 $params = $this->request->getParams();
568 $startDate = $params['start'];
569
570 $startDate = $this->t->setDateDb( $startDate )->setStartMonth()->formatDateDb();
571 $endDate = $this->t->modify('+1 month')->modify('-1 day')->formatDateDb();
572
573 $this->t->setDateDb( $startDate );
574 $dates = array();
575 $rexDate = $startDate;
576 while( $rexDate <= $endDate ){
577 if( $disabledWeekdays ){
578 $wkd = $this->t->getWeekday();
579 if( in_array($wkd, $disabledWeekdays) ){
580 $rexDate = $this->t->modify('+1 day')->formatDateDb();
581 continue;
582 }
583 }
584
585 $dates[] = $rexDate;
586 $rexDate = $this->t->modify('+1 day')->formatDateDb();
587 }
588
589 $countDates = count( $dates );
590
591 $viewEmployees = array();
592 foreach( $employees as $employee ){
593 $label = $this->employeesPresenter->presentTitle( $employee );
594 $title = htmlspecialchars( $label );
595
596 $description = $employee->getDescription();
597 if( strlen($description) ){
598 $imgpos = strpos( $description, '<img' );
599 if( false !== $imgpos ){
600 $label = $this->ui->makeList( array($label, $description) );
601 }
602 else {
603 $title .= "\n" . htmlspecialchars( $description );
604 }
605 }
606
607 $label = $this->ui->makeSpan( $label )
608 ->tag( 'font-size', 4 )
609 ->addAttr( 'title', $title )
610 ;
611
612 $viewEmployees[ $employee->getId() ] = $label;
613 }
614
615 $viewShifts = array();
616
617 $iknow = array('employee', 'date');
618
619 $allCalendars = $this->common->findAllCalendars();
620 if( count($allCalendars) <= 1 ) $iknow[] = 'calendar';
621
622 foreach( $shifts as $shift ){
623 $employee = $shift->getEmployee();
624 $id = $employee ? $employee->getId() : 0;
625
626 if( ! array_key_exists($id, $viewShifts) ){
627 $viewShifts[$id] = array();
628 }
629
630 $start = $shift->getStart();
631 $end = $shift->getEnd();
632
633 $startDayTime = substr($start, 8, 4);
634 $endDayTime = substr($end, 8, 4);
635 $shiftAllDay = ( (0 == $startDayTime) && (0 == $endDayTime) ) ? TRUE : FALSE;
636
637 $this->t->setDateTimeDb( $end )->modify('-1 second');
638 $shiftEndDate = $this->t->formatDateDb();
639
640 $this->t->setDateTimeDb( $start );
641 $shiftStartDate = $this->t->formatDateDb();
642
643 $rexDate = $shiftStartDate;
644 while( $rexDate <= $shiftEndDate ){
645 if( in_array($rexDate, $dates) ){
646 if( ! array_key_exists($rexDate, $viewShifts[$id]) ){
647 $viewShifts[$id][$rexDate] = array();
648 }
649 $viewShifts[$id][$rexDate][] = $shift;
650 }
651
652 if( ! $shiftAllDay ){
653 break;
654 }
655 $this->t->modify( '+1 day' );
656 $rexDate = $this->t->formatDateDb();
657 }
658 }
659
660 $header = array();
661 $header[] = null;
662
663 $weekStartsOn = $this->t->getWeekStartsOn();
664 $weekSegments = array();
665
666 $this->t->setDateDb( $startDate );
667 $monthMatrix = $this->t->getMonthMatrix( $disabledWeekdays );
668
669 foreach( $monthMatrix as $week => $days ){
670 $wdi = 0;
671 foreach( $days as $date ){
672 if( ! $date ){
673 continue;
674 }
675
676 $dateView = $this->common->renderDateLabelGrouped( $date );
677 $header[] = $dateView;
678
679 if( ! $wdi ){
680 $weekSegments[] = count($header);
681 }
682
683 $wdi++;
684 }
685 }
686
687 // while( count($header) < 32 ){
688 // $header[] = NULL;
689 // }
690
691 $rows = array();
692
693 // link templates to speed things up
694 $toParams = array(
695 'employee' => '{EID}',
696 'date' => '{DATE}'
697 );
698 $thisTo = 'new';
699 $thisTo = array( $thisTo, $toParams );
700 $thisHref = $this->uri->makeUrl( $thisTo );
701
702 $linkTemplateShift = '<a title="__Add New__" class="hc-block hc-theme-tab-link hc-align-center" href="' . $thisHref . '">+</a>';
703 $linkTemplateShiftMuted = '<a title="__Add New__" class="hc-block hc-theme-tab-link hc-align-center hc-muted3" href="' . $thisHref . '">+</a>';
704 $isPrintView = $this->request->isPrintView();
705
706 foreach( $viewEmployees as $id => $employeeView ){
707 $row = array();
708
709 $this->shiftsDuration->reset();
710 if( isset($viewShifts[$id]) ){
711 $counted = 0;
712 foreach( $viewShifts[$id] as $date => $dateShifts ){
713 foreach( $dateShifts as $shift ){
714 $shiftCalendar = $shift->getCalendar();
715 // if( $shiftCalendar->isTimeoff() ){
716 // continue;
717 // }
718 $this->shiftsDuration->add( $shift );
719 $counted++;
720 }
721 }
722
723 if( $counted ){
724 $outReport = $this->common->renderReport( $this->shiftsDuration, FALSE );
725 $outReport = $this->ui->makeSpan( $outReport )
726 ->tag('font-size', 2)
727 ;
728 $employeeView = $this->ui->makeList( array($employeeView, $outReport) )
729 ->gutter(1)
730 ;
731 }
732 }
733
734 $thisShifts = isset( $view_shifts[$id] ) ? $view_shifts[$id] : array();
735 $employeeView = $this->common->employeeRowLabel( $employeeView, $id, 'month', $dates, $thisShifts );
736
737 $employeeView = $this->ui->makeBlock( $employeeView )
738 ->tag('padding', array('x1', 'y2'))
739 ->tag('nowrap')
740 ;
741 $row[] = $employeeView;
742
743 foreach( $dates as $date ){
744 $cell = array();
745
746 if( isset($viewShifts[$id][$date]) ){
747 if( $this->slimView ){
748 $shiftsView = $this->self->renderDay( $viewShifts[$id][$date], $iknow );
749 }
750 else {
751 $shiftsView = $this->viewWeek->renderDay( $viewShifts[$id][$date], $iknow );
752 }
753 $cell[] = $shiftsView;
754 }
755
756 $comboId = 0 . '-' . $id;
757 if( isset($this->allCombos[$comboId]) ){
758 /*
759 $label = '+';
760
761 $to = 'new';
762 $toParams = array(
763 'date' => $date,
764 'employee' => $id,
765 );
766 $to = array( $to, $toParams );
767
768 $link = $this->ui->makeAhref( $to, $label )
769 ->tag('tab-link')
770 ->tag('align', 'center')
771 ->addAttr('title', '__Add New__')
772 ;
773
774 if( $today > $date ){
775 $link->tag('muted', 3);
776 }
777 */
778 if( $today > $date ){
779 $link = str_replace( array('{EID}', '{DATE}'), array($id, $date), $linkTemplateShiftMuted );
780 }
781 else {
782 $link = str_replace( array('{EID}', '{DATE}'), array($id, $date), $linkTemplateShift );
783 }
784
785 if( ! $isPrintView ){
786 $cell[] = $link;
787 }
788 }
789
790 $cell = $this->ui->makeList( $cell )
791 ->gutter(1)
792 ->tag('margin', '05')
793 ;
794
795 $row[] = $cell;
796 }
797
798 // while( count($row) < 32 ){
799 // $row[] = NULL;
800 // }
801 $rows[] = $row;
802 }
803
804 $out = $this->ui->makeTable( $header, $rows, false )
805 ->gutter(0)
806 ->setBordered( $this->borderColor )
807 ->setSegments( $weekSegments )
808 ->setLabelled( true )
809 ;
810
811 if( ! $this->slimView ){
812 $out->forceColWidth( '6rem' );
813 $out->forceRowHeaderWidth( '10rem' );
814 }
815
816 return $out;
817 }
818
819 public function renderDay( $shifts, $iknow )
820 {
821 $return = NULL;
822 if( ! $shifts ){
823 return $return;
824 }
825
826 $params = $this->request->getParams();
827
828 $hideui = $params['hideui'];
829 $noZoom = in_array('shiftdetails', $hideui);
830
831 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
832 if( ! in_array(-1, $params['employee']) ){
833 $iknow[] = 'employee';
834 }
835 }
836 if( array_key_exists('calendar', $params) && (count($params['calendar']) == 1) ){
837 $iknow[] = 'calendar';
838 }
839
840 // groups?
841 $groups = array();
842 $groupedShifts = array();
843 reset( $shifts );
844 foreach( $shifts as $shift ){
845 if( ! $shift->isOpen() ){
846 continue;
847 }
848
849 $groupId = $shift->getGroupingId();
850
851 if( ! isset($groups[$groupId]) ){
852 $groups[ $groupId ] = $shift->getId();
853 $groupedShifts[ $shift->getId() ] = array( $shift->getId() => $shift );
854 }
855 else {
856 $mainShiftId = $groups[ $groupId ];
857 $groupedShifts[ $mainShiftId ][ $shift->getId() ] = $shift;
858 $groupedShifts[ $shift->getId() ] = 0;
859 }
860 }
861
862 $return = array();
863 reset( $shifts );
864 foreach( $shifts as $shift ){
865 $id = $shift->getId();
866
867 if( isset($groupedShifts[$id]) && (! $groupedShifts[$id]) ){
868 continue;
869 }
870
871 $groupedQty = NULL;
872 if( isset($groupedShifts[$id]) && (count($groupedShifts[$id]) > 1) ){
873 $groupedQty = count($groupedShifts[$id]);
874 }
875
876 $thisView = $this->widget->renderCompact( $shift, $iknow, $groupedQty );
877
878 if( ! $noZoom ){
879 $to = 'shifts/' . $id;
880 $thisView = $this->ui->makeAhref( $to, $thisView )
881 ->tag('unstyled-link')
882 ->tag('block')
883 ->tag('print')
884 ->addAttr('class', 'sh4-widget-loader')
885 ;
886 }
887
888 $buildMenuFromShifts = isset($groupedShifts[$id]) ? $groupedShifts[$id] : array( $shift );
889 $menu = $this->shiftsCommon->bulkMenu( $buildMenuFromShifts );
890 if( $menu ){
891 $thisView = $this->ui->makeCollection( array($thisView, $menu) );
892 }
893
894 $thisView = $this->ui->makeBlock( $thisView )
895 ->tag('block')
896 ->addAttr('class', 'sh4-shift-widget')
897 ;
898
899 $return[] = $thisView;
900 }
901
902 $return = $this->ui->makeList( $return )
903 ->gutter(1)
904 ;
905
906 return $return;
907 }
908 }