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 / twoweeks.php

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

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