PluginProbe
ShiftController Employee Shift Scheduling / 4.9.24
ShiftController Employee Shift Scheduling v4.9.24
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 / month.php

month.php in ShiftController Employee Shift Scheduling 4.9.24, at sh4/schedule/html/view/month.php

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