PluginProbe
ShiftController Employee Shift Scheduling / 4.9.59
ShiftController Employee Shift Scheduling v4.9.59
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.59, at sh4/schedule/html/view/controloptions.php

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