PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
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 / fourweeks.php

fourweeks.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/schedule/html/view/fourweeks.php

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