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

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

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