PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
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 / controloptions.php

controloptions.php in ShiftController Employee Shift Scheduling 4.9.66, at sh4/schedule/html/view/controloptions.php

711 lines 17.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 interface SH4_Schedule_Html_View_IControlOptions
3 {
4 public function render();
5 public function renderMore();
6 public function renderFilterEmployees();
7 public function renderFilterCalendars();
8 public function renderFilter();
9 public function renderGroupBy();
10 public function filterViewTypes( $return );
11 public function renderType();
12 }
13
14 #[AllowDynamicProperties]
15 class SH4_Schedule_Html_View_ControlOptions implements SH4_Schedule_Html_View_IControlOptions
16 {
17 public function __construct(
18 HC3_Hooks $hooks,
19 HC3_Ui $ui,
20 HC3_Request $request,
21 HC3_UriAction $uriAction,
22 HC3_Time $t,
23 HC3_Auth $auth,
24 HC3_Settings $settings,
25
26 SH4_Employees_Query $employeesQuery,
27 SH4_Schedule_Html_View_Common $viewCommon
28 )
29 {
30 $this->self = $hooks->wrap( $this );
31 $this->ui = $ui;
32 $this->request = $request;
33 $this->uriAction = $uriAction;
34 $this->t = $t;
35 $this->auth = $hooks->wrap( $auth );
36 $this->settings = $hooks->wrap( $settings );
37
38 $this->viewCommon = $hooks->wrap( $viewCommon );
39 $this->employeesQuery = $hooks->wrap( $employeesQuery );
40 }
41
42 public function render()
43 {
44 // view options
45 $out = array();
46
47 $type = $this->self->renderType();
48 if( NULL !== $type ){
49 $out[] = $type;
50 }
51
52 $groupBy = $this->self->renderGroupBy();
53 if( NULL !== $groupBy ){
54 $out[] = $groupBy;
55 }
56
57 $filter = $this->self->renderFilter();
58 if( NULL !== $filter ){
59 $out[] = $filter;
60 }
61
62 $more = $this->self->renderMore();
63 if( NULL !== $more ){
64 $out[] = $more;
65 }
66
67 $out = $this->ui->makeGrid( $out );
68
69 return $out;
70 }
71
72 public function renderMore()
73 {
74 $out = null;
75 if( $this->request->isPrintView() ){
76 return $out;
77 }
78
79 $slug = $this->request->getSlug();
80 $params = $this->request->getParams();
81 $toParams = $this->request->getParams('withoutdefault');
82
83 $hideui = $params['hideui'];
84
85 $options = array();
86
87 if( ! array_intersect(array('download', 'all'), $hideui) ){
88 $thisParams = $toParams;
89 $thisParams['download'] = 1;
90
91 // $options['download'] = $this->ui->makeAhref( array($slug, $thisParams), '__Download__' )
92 // ->tag('tab-link')
93 // ;
94
95 $to = $this->uriAction->makeUrl( array($slug, $thisParams) );
96 $options['download'] = $this->ui->makeAhref( $to, '__Download__' )
97 ->tag('tab-link')
98 ;
99 }
100
101 if( ! array_intersect(array('print', 'all'), $hideui) ){
102 $thisParams = $toParams;
103 $thisParams['print'] = 1;
104
105 // $options['print'] = $this->ui->makeAhref( array($slug, $thisParams), '__Print__' )
106 // ->tag('tab-link')
107 // ->newWindow()
108 // ->actionMode()
109 // ;
110
111 $to = $this->uriAction->makeUrl( array($slug, $thisParams) );
112 $options['print'] = $this->ui->makeAhref( $to, '__Print__' )
113 ->newWindow()
114 ->tag('tab-link')
115 ;
116 }
117
118 if( ! $options ){
119 return $out;
120 }
121
122 if( count($options) == 1 ){
123 $out = array_shift( $options );
124 return $out;
125 }
126
127 $out = $this->ui->makeList( $options )
128 ->gutter(1)
129 ;
130
131 $label = '__More__';
132 $label = $this->ui->makeSpan($label)
133 ->tag('font-size', 2)
134 ->tag('muted')
135 ;
136
137 $out = $this->ui->makeCollapse( $label, $out )
138 ->border(FALSE)
139 ;
140 return $out;
141 }
142
143 public function renderFilterEmployees()
144 {
145 $return = NULL;
146
147 $slug = $this->request->getSlug();
148 $params = $this->request->getParams();
149 $toParams = $this->request->getParams('withoutdefault');
150
151 $hideui = $params['hideui'];
152 if( array_intersect(array('filter-employee', 'all'), $hideui) ){
153 return $return;
154 }
155
156 if( ! array_key_exists('employee', $toParams) ){
157 $toParams['employee'] = array();
158 }
159
160 $all = $this->viewCommon->findAllEmployees();
161 // remove archived
162 $ids = array_keys( $all );
163 foreach( $ids as $id ){
164 if( $all[$id]->isArchived() ){
165 unset( $all[$id] );
166 }
167 }
168
169 $assignedShiftEmployee = $this->employeesQuery->findById( -1 );
170 if( isset($all[0]) ){
171 $openShiftEmployee = $all[0];
172 $all[ $assignedShiftEmployee->getId() ] = $assignedShiftEmployee;
173 unset( $all[0] );
174 $all = array(
175 $openShiftEmployee->getId() => $openShiftEmployee,
176 $assignedShiftEmployee->getId() => $assignedShiftEmployee
177 ) + $all;
178 }
179
180 if( count($all) < 2 && (! $toParams['employee']) ){
181 return $return;
182 }
183
184 $allIds = array_keys($all);
185 $selectedEmployees = array();
186 foreach( $allIds as $id ){
187 if( in_array($id, $toParams['employee']) ){
188 $selectedEmployees[$id] = $all[$id];
189 unset($all[$id]);
190 }
191 }
192
193 if( $this->request->isPrintView() ){
194 $ret = null;
195
196 if( $selectedEmployees ){
197 $ret = array();
198 foreach( $selectedEmployees as $e ){
199 $eView = $e->getTitle();
200 $ret[] = $eView;
201 }
202 $ret = $this->ui->makeList( $ret )->gutter(0);
203 $ret = $this->ui->makeLabelled( '__Employee__', $ret );
204 }
205
206 return $ret;
207 }
208
209 if( $selectedEmployees ){
210 $selectedView = array();
211 foreach( $selectedEmployees as $e ){
212 $thisParams = $toParams;
213
214 $eView = $e->getTitle();
215 $eView = $this->ui->makeListInline( array('&times', $eView) )->gutter(1);
216
217 $thisParams['employee'] = HC3_Functions::removeFromArray( $thisParams['employee'], $e->getId() );
218 if( ! $thisParams['employee'] ){
219 $thisParams['employee'] = array('x');
220 }
221
222 $eView = $this->ui->makeAhref( array($slug, $thisParams), $eView )
223 ->tag('tab-link')
224 ;
225
226 $selectedView[] = $eView;
227 }
228 $selectedView = $this->ui->makeList( $selectedView )->gutter(0);
229 }
230
231 $toSelectView = array();
232 foreach( $all as $e ){
233 $thisParams = $toParams;
234
235 $thisParams['employee'][] = $e->getId();
236 $label = $e->getTitle();
237 $eView = $this->ui->makeAhref( array($slug, $thisParams), $label )
238 ->tag('tab-link')
239 ;
240 $toSelectView[] = $eView;
241
242 // if( 0 == $e->getId() ){
243 // $thisParams = $toParams;
244 // $thisParams['employee'][] = $assignedShiftEmployee->getId();
245
246 // $label = $assignedShiftEmployee->getTitle();
247 // $eView = $this->ui->makeAhref( array($slug, $thisParams), $label )
248 // ->tag('tab-link')
249 // ;
250 // $toSelectView[] = $eView;
251 // }
252 }
253
254 if( ! ($selectedEmployees OR $toSelectView) ){
255 return $return;
256 }
257
258 $view = array();
259
260 if( $selectedEmployees ){
261 $view[] = $selectedView;
262 }
263
264 if( $toSelectView ){
265 $toSelectView = $this->ui->makeList( $toSelectView )
266 ->gutter(0)
267 ;
268
269 if( $selectedEmployees ){
270 $label = '&#43; ' . '__More Employees__';
271 $label = $this->ui->makeBlock($label)
272 ->tag('font-size', 2)
273 ;
274 }
275 else {
276 $label = '__All Employees__';
277 }
278
279 $toSelectView = $this->ui->makeCollapse( $label, $toSelectView );
280 $view[] = $toSelectView;
281 }
282
283 $view = $this->ui->makeList( $view )->gutter(1);
284 $return = $this->ui->makeLabelled( '__Employee__', $view );
285
286 return $return;
287 }
288
289 public function renderFilterCalendars()
290 {
291 $return = NULL;
292
293 $slug = $this->request->getSlug();
294 $params = $this->request->getParams();
295 $toParams = $this->request->getParams('withoutdefault');
296
297 $hideui = $params['hideui'];
298 if( array_intersect(array('filter-calendar', 'all'), $hideui) ){
299 return $return;
300 }
301
302 if( ! array_key_exists('calendar', $toParams) ){
303 $toParams['calendar'] = array();
304 }
305
306 $all = $this->viewCommon->findAllCalendars();
307 // remove archived
308 $ids = array_keys( $all );
309 foreach( $ids as $id ){
310 if( $all[$id]->isArchived() ){
311 unset( $all[$id] );
312 }
313 }
314
315 if( count($all) < 2 && (! $toParams['calendar']) ){
316 return $return;
317 }
318
319 $allIds = array_keys($all);
320 $selectedCalendars = array();
321
322 foreach( $allIds as $id ){
323 if( in_array($id, $toParams['calendar']) ){
324 $selectedCalendars[$id] = $all[$id];
325 unset($all[$id]);
326 }
327 }
328
329 if( $this->request->isPrintView() ){
330 $ret = null;
331
332 if( $selectedCalendars ){
333 $ret = array();
334 foreach( $selectedCalendars as $e ){
335 $eView = $e->getTitle();
336 $ret[] = $eView;
337 }
338 $ret = $this->ui->makeList( $ret )->gutter(0);
339 $ret = $this->ui->makeLabelled( '__Calendar__', $ret );
340 }
341
342 return $ret;
343 }
344
345 $selectedView = array();
346 if( $selectedCalendars ){
347 foreach( $selectedCalendars as $e ){
348 $thisParams = $toParams;
349
350 $eView = $e->getTitle();
351 $eView = $this->ui->makeListInline( array('&times', $eView) )->gutter(1);
352
353 $thisParams['calendar'] = HC3_Functions::removeFromArray( $thisParams['calendar'], $e->getId() );
354 if( ! $thisParams['calendar'] ){
355 $thisParams['calendar'] = array('x');
356 }
357
358 $eView = $this->ui->makeAhref( array($slug, $thisParams), $eView )
359 ->tag('tab-link')
360 ;
361
362 $selectedView[] = $eView;
363 }
364 $selectedView = $this->ui->makeList( $selectedView )->gutter(0);
365 }
366
367 $toSelectView = array();
368 foreach( $all as $e ){
369 $thisParams = $toParams;
370 $thisParams['calendar'][] = $e->getId();
371
372 $label = $e->getTitle();
373 $color = $this->ui->makeBlockInline('&nbsp;')->paddingX(1)->tag('bgcolor', $e->getColor() );
374 $label = $this->ui->makeListInline( array($color, $label) )->gutter(1);
375
376 $eView = $this->ui->makeAhref( array($slug, $thisParams), $label )
377 ->tag('tab-link')
378 ;
379
380 $toSelectView[] = $eView;
381 }
382
383 if( ! ($selectedCalendars OR $toSelectView) ){
384 return $return;
385 }
386
387 $view = array();
388
389 if( $selectedView ){
390 $view[] = $selectedView;
391 }
392
393 if( $toSelectView ){
394 $toSelectView = $this->ui->makeList( $toSelectView )
395 ->gutter(0)
396 ;
397
398 if( $selectedCalendars ){
399 $label = '&#43; ' . '__More Calendars__';
400 $label = $this->ui->makeBlock($label)
401 ->tag('font-size', 2)
402 ;
403 }
404 else {
405 $label = '__All Calendars__';
406 }
407
408 $toSelectView = $this->ui->makeCollapse( $label, $toSelectView );
409 $view[] = $toSelectView;
410 }
411
412 $view = $this->ui->makeList( $view )->gutter(1);
413 $return = $this->ui->makeLabelled( '__Calendar__', $view );
414
415 return $return;
416 }
417
418 public function renderFilterConflicts()
419 {
420 $ret = null;
421
422 $currentUser = $this->auth->getCurrentUser();
423 $currentUserId = $currentUser->getId();
424 if( ! $currentUserId ){
425 return $ret;
426 }
427
428 $slug = $this->request->getSlug();
429 $params = $this->request->getParams();
430 $toParams = $this->request->getParams('withoutdefault');
431
432 $hideui = $params['hideui'];
433 if( array_intersect(array('filter-conflict', 'all'), $hideui) ){
434 return $ret;
435 }
436
437 if( ! array_key_exists('conflict', $toParams) ){
438 $toParams['conflict'] = null;
439 }
440
441 $thisParams['conflict'] = 1;
442 $label = '__Shifts With Conflicts__';
443
444 if( $toParams['conflict'] ){
445 $thisParams['conflict'] = null;
446 $label = $this->ui->makeListInline( array('&times', $label) )->gutter(1);
447 $view = $this->ui->makeAhref( array($slug, $thisParams), $label )
448 ->tag('tab-link')
449 ;
450 }
451 else {
452 $thisParams['conflict'] = 1;
453 $view = $this->ui->makeAhref( array($slug, $thisParams), $label )
454 ->tag('tab-link')
455 ;
456 }
457
458 return $view;
459 }
460
461 public function renderFilter()
462 {
463 $return = NULL;
464
465 $params = $this->request->getParams();
466 $hideui = $params['hideui'];
467 if( array_intersect(array('filter', 'all'), $hideui) ){
468 return $return;
469 }
470
471 $params = $this->request->getParams('withoutdefault');
472
473 if( ! array_key_exists('conflict', $params) ){
474 $params['conflict'] = null;
475 }
476 if( ! array_key_exists('employee', $params) ){
477 $params['employee'] = array();
478 }
479 if( ! array_key_exists('calendar', $params) ){
480 $params['calendar'] = array();
481 }
482
483 $filterView = array();
484
485 // filter - employees
486 $filterViewEmployees = $this->self->renderFilterEmployees();
487 if( $filterViewEmployees ){
488 $filterView[] = $filterViewEmployees;
489 }
490
491 // calendars
492 $filterViewCalendars = $this->self->renderFilterCalendars();
493 if( $filterViewCalendars ){
494 $filterView[] = $filterViewCalendars;
495 }
496
497 // filter - conflicts
498 $filterViewConflicts = $this->renderFilterConflicts();
499 if( $filterViewConflicts ){
500 $filterView[] = $filterViewConflicts;
501 }
502
503 if( ! $filterView ){
504 return $return;
505 }
506
507 $filter = $this->ui->makeList( $filterView );
508
509 $label = '__Filter__';
510
511 if( $this->request->isPrintView() ){
512 $out = $filter;
513 // $out = $this->ui->makeLabelled( $label, $filter );
514 }
515 else {
516 $currentView = '';
517 $totalSelectedCount = count($params['calendar']) + count($params['employee']);
518 if( $params['conflict'] ) $totalSelectedCount += 1;
519 $currentView = $totalSelectedCount ? '(' . $totalSelectedCount . ')' : '__None__';
520
521 $label = '__Filter__';
522 $label = $this->ui->makeSpan($label)
523 ->tag('font-size', 2)
524 ->tag('muted')
525 ;
526 $currentView = $this->ui->makeSpan($currentView)
527 ->tag('font-style', 'bold')
528 ;
529 $label = $this->ui->makeListInline( array($label, $currentView) )->gutter(1);
530
531 $out = $this->ui->makeCollapse( $label, $filter )
532 ->border(false)
533 ;
534 }
535
536 return $out;
537 }
538
539 public function renderGroupBy()
540 {
541 $return = null;
542 if( $this->request->isPrintView() ){
543 return $return;
544 }
545
546 $slug = $this->request->getSlug();
547 $params = $this->request->getParams();
548
549 $hideui = $params['hideui'];
550 if( array_intersect(array('groupby', 'all'), $hideui) ){
551 return $return;
552 }
553
554 $current = $params['groupby'];
555 $currentView = $current;
556
557 $employees = $this->viewCommon->getEmployees();
558 $calendars = $this->viewCommon->getCalendars();
559
560 $options = array();
561
562 if( (count($employees) > 1) OR ('employee' == $current) ){
563 if( ! in_array('groupby-employee', $hideui) ){
564 $options[] = array( '__Employee__', 'employee' );
565 }
566 }
567 if( (count($calendars) > 1) OR ('calendar' == $current) ){
568 if( ! in_array('groupby-calendar', $hideui) ){
569 $options[] = array( '__Calendar__', 'calendar' );
570 }
571 }
572
573 if( ! $options ){
574 return $return;
575 }
576
577 array_unshift( $options, array( '__None__', 'none' ) );
578
579 $view = array();
580 foreach( $options as $option ){
581 list( $label, $k ) = $option;
582
583 if( $k == $current ){
584 $currentView = $label;
585 continue;
586 }
587
588 $params = $k ? array('groupby' => $k) : array('groupby' => NULL);
589 $this_option = $this->ui->makeAhref( array($slug, $params), $label )
590 ->tag('tab-link')
591 ;
592 $view[] = $this_option;
593 }
594
595 $out = $this->ui->makeList( $view )
596 ->gutter(1)
597 ;
598
599 $label = '__Group By__';
600 $label = $this->ui->makeSpan($label)
601 ->tag('font-size', 2)
602 ->tag('muted')
603 ;
604 $currentView = $this->ui->makeSpan($currentView)
605 ->tag('font-style', 'bold')
606 ;
607 $label = $this->ui->makeListInline( array($label, $currentView) )->gutter(1);
608
609 $out = $this->ui->makeCollapse( $label, $out )
610 ->border(FALSE)
611 ;
612 return $out;
613 }
614
615 public function filterViewTypes( $return )
616 {
617 return $return;
618 }
619
620 public function renderType()
621 {
622 $out = NULL;
623
624 $slug = $this->request->getSlug();
625 $params = $this->request->getParams();
626 $toParams = $this->request->getParams('withoutdefault');
627
628 $hideui = $params['hideui'];
629 if( array_intersect(array('type', 'all'), $hideui) ){
630 return $out;
631 }
632
633 $current = $params['type'];
634 $currentView = $current;
635
636 $nWeeks = $this->settings->get( 'datetime_n_weeks' );
637
638 $options = array(
639 'day' => '__Day__',
640 'week' => '__Week__',
641 '2weeks' => '__2 Weeks__',
642 '4weeks' => $nWeeks . ' ' . '__Weeks__',
643 'month' => '__Month__',
644 'list' => '__List__',
645 'report' => '__Report__'
646 );
647
648 $keys = array_keys( $options );
649 foreach( $keys as $key ){
650 $testKey = 'type-' . $key;
651 if( in_array($testKey, $hideui) ){
652 unset( $options[$key] );
653 }
654 }
655
656 if( count($options) < 2 ){
657 return $out;
658 }
659
660 $options = $this->viewCommon->filterViewTypes( $options );
661
662 $view = array();
663 foreach( $options as $k => $label ){
664 $thisParams = $toParams;
665 $thisParams['type'] = $k;
666 if( in_array($k, array('week', 'month', 'day', '2weeks', '4weeks')) ){
667 $thisParams['end'] = NULL;
668 $thisParams['time'] = NULL;
669 }
670
671 if( 'day' == $k ){
672 // if in current week/month then jump to today rather than the first day of week/month
673 $today = $this->t->setNow()->setStartDay()->formatDateDb();
674 if( isset($params['start']) && isset($params['end']) ){
675 if( ($today >= $params['start']) && ($today <= $params['end']) ){
676 $thisParams['start'] = $today;
677 }
678 }
679 }
680
681 if( $current == $k ){
682 $currentView = $label;
683 continue;
684 }
685
686 $thisOption = $this->ui->makeAhref( array($slug, $thisParams), $label )
687 ->tag('tab-link')
688 ;
689 $view[] = $thisOption;
690 }
691
692 $out = $this->ui->makeList( $view )
693 ->gutter(1)
694 ;
695
696 $label = '__View__';
697 $label = $this->ui->makeSpan($label)
698 ->tag('font-size', 2)
699 ->tag('muted')
700 ;
701 $currentView = $this->ui->makeSpan($currentView)
702 ->tag('font-style', 'bold')
703 ;
704 $label = $this->ui->makeListInline( array($label, $currentView) )->gutter(1);
705
706 $out = $this->ui->makeCollapse( $label, $out )
707 ->border(FALSE)
708 ;
709 return $out;
710 }
711 }