PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / week.php

week.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/schedule/html/view/week.php

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