PluginProbe
ShiftController Employee Shift Scheduling / 4.9.65
ShiftController Employee Shift Scheduling v4.9.65
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 / day.php

day.php in ShiftController Employee Shift Scheduling 4.9.65, at sh4/schedule/html/view/day.php

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