PluginProbe
ShiftController Employee Shift Scheduling / 4.9.67
ShiftController Employee Shift Scheduling v4.9.67
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 / twoweeks.php

twoweeks.php in ShiftController Employee Shift Scheduling 4.9.67, at sh4/schedule/html/view/twoweeks.php

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