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 / controloptions.php

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

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