PluginProbe
ShiftController Employee Shift Scheduling / 4.9.69
ShiftController Employee Shift Scheduling v4.9.69
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.69, at sh4/schedule/html/view/day.php

848 lines 22.4 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 $title = htmlspecialchars( $label );
560
561 $description = $employee->getDescription();
562 if( strlen($description) ){
563 $imgpos = strpos( $description, '<img' );
564 if( false !== $imgpos ){
565 $label = $this->ui->makeList( array($label, $description) );
566 }
567 else {
568 $title .= "\n" . htmlspecialchars( $description );
569 }
570 }
571
572 $label = $this->ui->makeSpan( $label )
573 ->tag( 'font-size', 4 )
574 ->addAttr( 'title', $title )
575 ;
576
577 $viewEmployees[ $employee->getId() ] = $label;
578 }
579
580 $viewShifts = array();
581
582 $iknow = array('employee', 'date');
583 $hori = FALSE;
584
585 $out = array();
586
587 reset( $dates );
588 foreach( $dates as $date ){
589 $thisOut = array();
590
591 $thisOut = array();
592 $rows = array();
593
594 $this->t->setDateDb( $date );
595 $dateView = $this->self->renderDateLabel( $date );
596 $thisOut[] = $dateView;
597
598 $viewShifts = array();
599
600 foreach( $shifts as $shift ){
601 $employee = $shift->getEmployee();
602 $id = $employee ? $employee->getId() : 0;
603
604 if( ! array_key_exists($id, $viewShifts) ){
605 $viewShifts[$id] = array();
606 }
607
608 $viewShifts[$id][] = $shift;
609 }
610
611 $header = array();
612 $header[] = NULL;
613 $header[] = NULL;
614
615 $rows = array();
616
617 foreach( $viewEmployees as $id => $employeeView ){
618 $row = array();
619
620 $this->shiftsDuration->reset();
621 if( isset($viewShifts[$id]) ){
622 $counted = 0;
623 foreach( $viewShifts[$id] as $shift ){
624 $shiftCalendar = $shift->getCalendar();
625 // if( ! $shiftCalendar->isShift() ){
626 // continue;
627 // }
628 $this->shiftsDuration->add( $shift );
629 $counted++;
630 }
631
632 if( $counted ){
633 $outReport = $this->common->renderReport( $this->shiftsDuration, FALSE );
634 $outReport = $this->ui->makeSpan( $outReport )
635 ->tag('font-size', 2)
636 ;
637 $employeeView = $this->ui->makeList( array($employeeView, $outReport) )
638 ->gutter(1)
639 ;
640 }
641 }
642
643 $thisShifts = isset( $view_shifts[$id] ) ? $view_shifts[$id] : array();
644 $employeeView = $this->common->employeeRowLabel( $employeeView, $id, 'day', $dates, $thisShifts );
645
646 $employeeView = $this->ui->makeBlock( $employeeView )
647 ->tag('padding', 2)
648 ->tag('nowrap')
649 ;
650 $row[] = $employeeView;
651
652 $cell = array();
653
654 if( isset($viewShifts[$id]) ){
655 $gridView = $this->self->renderDay( $viewShifts[$id], $iknow, $date );
656 $cell[] = $gridView;
657 }
658
659 $toParams = array(
660 'employee' => $id,
661 'date' => $date
662 );
663
664 $links = array();
665
666 $comboId = 0 . '-' . $id;
667
668 if( isset($this->allCombosShift[$comboId]) ){
669 $label = '+' . ' ' . '__Shift__';
670 $thisTo = 'new/shift';
671 $thisTo = array( $thisTo, $toParams );
672 $link = $this->ui->makeAhref( $thisTo, $label )
673 ->tag('tab-link')
674 ->tag('align', 'center')
675 // ->addAttr('title', '__Add New__')
676 ;
677 if( $today > $date ){
678 $link->tag('muted', 3);
679 }
680 $links[] = $link;
681 }
682
683 if( isset($this->allCombosTimeoff[$comboId]) ){
684 $label = '+' . ' ' . '__Time Off__';
685 $thisTo = 'new/timeoff';
686 $thisTo = array( $thisTo, $toParams );
687 $link = $this->ui->makeAhref( $thisTo, $label )
688 ->tag('tab-link')
689 ->tag('align', 'center')
690 // ->addAttr('title', '__Add New__')
691 ;
692 if( $today > $date ){
693 $link->tag('muted', 3);
694 }
695 $links[] = $link;
696 }
697
698 $links = $this->ui->makeList( $links )->gutter(0);
699
700 $cell[] = $links;
701
702 $cell = $this->ui->makeList( $cell )
703 ->gutter(1)
704 ->tag('margin', 1)
705 ;
706
707 $row[] = $cell;
708
709 $rows[] = $row;
710 }
711
712
713 $thisOut[] = $this->ui->makeTable( $header, $rows, FALSE )
714 ->gutter(0)
715 ->setBordered( $this->borderColor )
716 // ->setSegments( $weekSegments )
717 ->setLabelled( TRUE )
718 ;
719
720 $thisOut = $this->ui->makeList( $thisOut );
721
722 $out[] = $thisOut;
723 }
724
725 $out = $this->ui->makeList( $out );
726
727 return $out;
728 }
729
730 public function renderDay( $shifts, $iknow, $startDate = NULL )
731 {
732 $hori = FALSE;
733 $params = $this->request->getParams();
734
735 $hideui = $params['hideui'];
736 $noZoom = in_array('shiftdetails', $hideui);
737
738 if( array_key_exists('employee', $params) && (count($params['employee']) == 1) ){
739 if( ! in_array(-1, $params['employee']) ){
740 $iknow[] = 'employee';
741 }
742 }
743 if( array_key_exists('calendar', $params) && (count($params['calendar']) == 1) ){
744 $iknow[] = 'calendar';
745 }
746
747 if( NULL === $startDate ){
748 $startDate = $params['start'];
749 }
750
751 $this->t->setDateDb( $startDate );
752 $minTime = $this->settings->get('datetime_min_time');
753 if( $minTime ){
754 $this->t->modify('+' . $minTime . ' seconds');
755 }
756 $dayStart = $this->t->formatDateTimeDb();
757
758 $this->t->setDateDb( $startDate );
759 $maxTime = $this->settings->get('datetime_max_time');
760 if( $maxTime ){
761 $this->t->modify('+' . $maxTime . ' seconds');
762 }
763 else {
764 $this->t->modify('+1 day');
765 }
766 $dayEnd = $this->t->formatDateTimeDb();
767
768 // check if we need to extend ranges to show overtime shifts
769 if( $shifts ){
770 $this->t->setDateDb( $startDate )->modify('+1 day');
771 $minCheckEnd = $this->t->formatDateTimeDb();
772
773 $this->t->modify('+1 day');
774 $maxCheckEnd = $this->t->formatDateTimeDb();
775
776 foreach( $shifts as $shift ){
777 $thisEnd = $shift->getEnd();
778 if( ($thisEnd > $minCheckEnd) && ($thisEnd < $maxCheckEnd) ){
779 if( $thisEnd > $dayEnd ){
780 $dayEnd = $thisEnd;
781 }
782 }
783 }
784 }
785
786 $grid = $this->widgetDayGrid
787 ->reset()
788 ;
789 $grid->setRange( $dayStart, $dayEnd );
790
791 // groups?
792 $groups = array();
793 $groupedShifts = array();
794 reset( $shifts );
795 foreach( $shifts as $shift ){
796 if( ! $shift->isOpen() ){
797 continue;
798 }
799
800 $groupId = $shift->getGroupingId();
801
802 if( ! isset($groups[$groupId]) ){
803 $groups[ $groupId ] = $shift->getId();
804 $groupedShifts[ $shift->getId() ] = array( $shift->getId() => $shift );
805 }
806 else {
807 $mainShiftId = $groups[ $groupId ];
808 $groupedShifts[ $mainShiftId ][ $shift->getId() ] = $shift;
809 $groupedShifts[ $shift->getId() ] = 0;
810 }
811 }
812
813 reset( $shifts );
814 foreach( $shifts as $shift ){
815 $id = $shift->getId();
816 if( isset($groupedShifts[$id]) && (! $groupedShifts[$id]) ){
817 continue;
818 }
819
820 $groupedQty = NULL;
821 if( isset($groupedShifts[$id]) && (count($groupedShifts[$id]) > 1) ){
822 $groupedQty = count($groupedShifts[$id]);
823 }
824
825 $thisView = $this->widget->render( $shift, $iknow, $hori, $noZoom, $groupedQty );
826 $shiftId = $shift->getId();
827
828 $buildMenuFromShifts = isset($groupedShifts[$id]) ? $groupedShifts[$id] : array( $shift );
829 $menu = $this->shiftsCommon->bulkMenu( $buildMenuFromShifts );
830 if( $menu ){
831 $thisView = $this->ui->makeCollection( array($thisView, $menu) );
832 }
833
834 $thisView = $this->ui->makeBlock( $thisView )
835 ->tag('block')
836 ->addAttr('class', 'sh4-shift-widget')
837 ->addAttr('style', 'padding-right: 1px;')
838 ;
839
840 $grid
841 ->add( $shift->getStart(), $shift->getEnd(), $thisView )
842 ;
843 }
844
845 $return = $grid->render();
846 return $return;
847 }
848 }