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 / new / acl.php

acl.php in ShiftController Employee Shift Scheduling 4.9.66, at sh4/new/acl.php

899 lines 23.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_New_IAcl
3 {
4 public function checkDraft( $calendarId, $typeId, $dateString, $employeeString );
5 public function checkPublish( $calendarId, $typeId, $dateString, $employeeString );
6
7 public function checkNewTimeoff( $params = array() );
8 public function checkNewAvailability( $params = array() );
9 public function checkNewShift( $params = array() );
10 public function checkNew( $params = array() );
11
12 public function check( $calendarId, $typeId, $employeeId, $date );
13 public function findAllCombos();
14 }
15
16 #[AllowDynamicProperties]
17 class SH4_New_Acl implements SH4_New_IAcl
18 {
19 public function __construct(
20 HC3_Hooks $hooks,
21 HC3_Time $t,
22
23 HC3_Settings $settings,
24
25 SH4_App_Query $appQuery,
26 SH4_Calendars_Permissions $calendarsPermissions,
27 SH4_ShiftTypes_Query $shiftTypesQuery,
28
29 SH4_Shifts_Availability $availability,
30 SH4_New_Query $newQuery,
31 SH4_Calendars_Query $calendarsQuery,
32 HC3_Auth $auth,
33 HC3_IPermission $permission
34 )
35 {
36 $this->self = $hooks->wrap( $this );
37 $this->t = $t;
38 $this->settings = $hooks->wrap($settings);
39
40 $this->availability = $hooks->wrap( $availability );
41 $this->newQuery = $hooks->wrap( $newQuery );
42 $this->appQuery = $hooks->wrap( $appQuery );
43 $this->auth = $hooks->wrap( $auth );
44 $this->permission = $hooks->wrap( $permission );
45 $this->calendarsPermissions = $hooks->wrap( $calendarsPermissions );
46
47 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
48 $this->shiftTypesQuery = $hooks->wrap( $shiftTypesQuery );
49 }
50
51 public function checkCreate( $calendarId, $typeId, $dateString, $employeeString )
52 {
53 $return = FALSE;
54
55 $return = $this->self->checkDraft( $calendarId, $typeId, $dateString, $employeeString );
56 if( $return ){
57 return $return;
58 }
59
60 $return = $this->self->checkPublish( $calendarId, $typeId, $dateString, $employeeString );
61 return $return;
62 }
63
64 public function checkDraft( $calendarId, $typeId, $dateString, $employeeString )
65 {
66 $return = FALSE;
67
68 $employeesIds = HC3_Functions::unglueArray( $employeeString );
69 $dates = HC3_Functions::unglueArray( $dateString );
70
71 foreach( $dates as $date ){
72 foreach( $employeesIds as $employeeId ){
73 $pos = strpos($employeeId, SH4_NEW_OPEN_SEPARATOR);
74 if( $pos ){
75 $employeeId = substr($employeeId, 0, $pos);
76 }
77
78 $preCheck = $this->self->check( $calendarId, $typeId, $employeeId, $date );
79 if( ! $preCheck ){
80 return $return;
81 }
82 }
83 }
84
85 $currentUser = $this->auth->getCurrentUser();
86 $currentUserId = $currentUser->getId();
87 if( ! $currentUserId ){
88 return $return;
89 }
90
91 if( $this->permission->isAdmin($currentUser) ){
92 $return = TRUE;
93 return $return;
94 }
95
96 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
97 if( isset($calendarsAsManager[$calendarId]) ){
98 $return = TRUE;
99 return $return;
100 }
101
102 $calendarsAsEmployee = array();
103 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
104 if( $meEmployee ){
105 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee );
106 foreach( $employeeCalendars as $thisCalendar ){
107 $thisCalendarId = $thisCalendar->getId();
108
109 if( $this->calendarsPermissions->get($thisCalendar, 'employee_create_own_draft') ){
110 $calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar;
111 }
112 }
113 }
114
115 if( $calendarId != 'x' ){
116 if( isset($calendarsAsEmployee[$calendarId]) ){
117 $return = TRUE;
118 }
119 }
120 else {
121 if( $calendarsAsEmployee ){
122 $return = TRUE;
123 }
124 }
125
126 if( $return ){
127 // check if can create shifts with conflicts
128 // if( ! $this->calendarsPermissions->get($thisCalendar, 'employee_create_own_conflicts') ){
129 // $return = FALSE;
130 // }
131 }
132
133 return $return;
134 }
135
136 public function checkPublish( $calendarId, $typeId, $dateString, $employeeString )
137 {
138 $return = FALSE;
139 $employeesIds = HC3_Functions::unglueArray( $employeeString );
140 $dates = HC3_Functions::unglueArray( $dateString );
141
142 foreach( $dates as $date ){
143 foreach( $employeesIds as $employeeId ){
144 $pos = strpos($employeeId, SH4_NEW_OPEN_SEPARATOR);
145 if( $pos ){
146 $employeeId = substr($employeeId, 0, $pos);
147 }
148
149 $preCheck = $this->self->check( $calendarId, $typeId, $employeeId, $date );
150 if( ! $preCheck ){
151 $return = FALSE;
152 return $return;
153 }
154 }
155 }
156
157 $currentUser = $this->auth->getCurrentUser();
158 $currentUserId = $currentUser->getId();
159 if( ! $currentUserId ){
160 return $return;
161 }
162
163 if( $this->permission->isAdmin($currentUser) ){
164 $return = TRUE;
165 return $return;
166 }
167
168 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
169 if( isset($calendarsAsManager[$calendarId]) ){
170 $return = TRUE;
171 return $return;
172 }
173
174 $calendarsAsEmployee = array();
175 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
176 if( $meEmployee ){
177 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee );
178 foreach( $employeeCalendars as $thisCalendar ){
179 $thisCalendarId = $thisCalendar->getId();
180
181 $checkPerms = array( 'employee_create_own_publish' );
182 foreach( $checkPerms as $perm ){
183 if( $this->calendarsPermissions->get($thisCalendar, $perm) ){
184 $calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar;
185 break;
186 }
187 }
188 }
189 }
190
191 if( $calendarId != 'x' ){
192 if( isset($calendarsAsEmployee[$calendarId]) ){
193 $return = TRUE;
194 }
195 }
196 else {
197 if( $calendarsAsEmployee ){
198 $return = TRUE;
199 }
200 }
201
202 return $return;
203 }
204
205 public function checkNew( $params = array() )
206 {
207 $return = FALSE;
208
209 $currentUser = $this->auth->getCurrentUser();
210 $currentUserId = $currentUser->getId();
211 if( ! $currentUserId ){
212 return $return;
213 }
214
215 if( $this->permission->isAdmin($currentUser) ){
216 $return = TRUE;
217 return $return;
218 }
219
220 if( array_key_exists('date', $params) ){
221 $checkDateString = $params['date'];
222 $checkDates = HC3_Functions::unglueArray( $checkDateString );
223
224 $today = $this->t->setNow()->formatDateDb();
225 list( $minDate, $maxDate ) = $this->self->getMinMaxDate();
226
227 if( null !== $minDate ){
228 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
229
230 foreach( $checkDates as $checkDate ){
231 if( ($checkDate < $minDate) OR ($checkDate > $maxDate) ){
232 if( array_key_exists('calendar', $params) ){
233 $calendarId = $params['calendar'];
234 if( ! isset($calendarsAsManager[$calendarId]) ){
235 return $return;
236 }
237 }
238 else {
239 if( ! $calendarsAsManager ){
240 return $return;
241 }
242 }
243 }
244 }
245 }
246 }
247
248 $useCache = TRUE;
249 static $cache = array();
250 $cacheParams = $params;
251 unset( $cacheParams['date'] );
252 $paramsString = http_build_query($cacheParams, NULL, ',');
253
254 if( $useCache ){
255 if( isset($cache[$paramsString]) ){
256 // echo "USE CACHE '$paramsString'<br>";
257 $return = $cache[$paramsString];
258 return $return;
259 }
260 }
261
262 if( ! $return ){
263 $return = $this->self->checkNewShift( $params );
264 }
265
266 if( ! $return ){
267 $return = $this->self->checkNewTimeoff( $params );
268 }
269
270 if( ! $return ){
271 $return = $this->self->checkNewAvailability( $params );
272 }
273
274 $cache[$paramsString] = $return;
275
276 return $return;
277 }
278
279 public function checkNewTimeoff( $params = array() )
280 {
281 $return = FALSE;
282
283 // echo "CHECKING TIMEOFF";
284 // _print_r( $params );
285
286 $calendars = $this->_findCalendars( $params );
287 if( $calendars === FALSE ){
288 $return = FALSE;
289 return $return;
290 }
291
292 $employeeIds = array('x');
293 if( array_key_exists('employee', $params) ){
294 $employeeIds = HC3_Functions::unglueArray( $params['employee'] );
295 }
296
297 foreach( $calendars as $calendar ){
298 if( ! $calendar->isTimeoff() ){
299 continue;
300 }
301
302 $thisCalendarId = $calendar->getId();
303
304 $thisReturn = TRUE;
305 foreach( $employeeIds as $employeeId ){
306 $pos = strpos($employeeId, SH4_NEW_OPEN_SEPARATOR);
307 if( $pos ){
308 $employeeId = substr($employeeId, 0, $pos);
309 }
310
311 $thisThisReturn = $this->self->check( $thisCalendarId, 'x', $employeeId );
312 if( ! $thisThisReturn ){
313 $thisReturn = FALSE;
314 break;
315 }
316 }
317
318 if( $thisReturn ){
319 $return = TRUE;
320 break;
321 }
322 }
323
324 return $return;
325 }
326
327 public function checkNewAvailability( $params = array() )
328 {
329 if( ! $this->availability->hasAvailability() ){
330 $return = FALSE;
331 return $return;
332 }
333
334 $return = FALSE;
335
336 $calendars = $this->_findCalendars( $params );
337 if( $calendars === FALSE ){
338 $return = FALSE;
339 return $return;
340 }
341
342 $employeeIds = array('x');
343 if( array_key_exists('employee', $params) ){
344 $employeeIds = HC3_Functions::unglueArray( $params['employee'] );
345 }
346
347 foreach( $calendars as $calendar ){
348 if( ! $calendar->isAvailability() ){
349 continue;
350 }
351
352 $thisCalendarId = $calendar->getId();
353
354 $thisReturn = TRUE;
355 foreach( $employeeIds as $employeeId ){
356 $pos = strpos($employeeId, SH4_NEW_OPEN_SEPARATOR);
357 if( $pos ){
358 $employeeId = substr($employeeId, 0, $pos);
359 }
360
361 $thisThisReturn = $this->self->check( $thisCalendarId, 'x', $employeeId );
362 if( ! $thisThisReturn ){
363 $thisReturn = FALSE;
364 break;
365 }
366 }
367
368 if( $thisReturn ){
369 $return = TRUE;
370 break;
371 }
372 }
373
374 return $return;
375 }
376
377 public function getMinMaxDate()
378 {
379 static $isEmployee = null;
380 static $isManager = null;
381
382 if( null === $isEmployee ){
383 $currentUser = $this->auth->getCurrentUser();
384 $currentUserId = $currentUser->getId();
385
386 if( $currentUserId ){
387 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
388 if( $calendarsAsManager ){
389 $isManager = true;
390 }
391 }
392
393 if( ! $isManager ){
394 $employee = $this->appQuery->findEmployeeByUser( $currentUser );
395 if( $employee ){
396 $isEmployee = true;
397 }
398 }
399 }
400
401 if( $isManager ){
402 $minDate = $maxDate = null;
403 $ret = array( $minDate, $maxDate );
404 return $ret;
405 }
406
407 $today = $this->t->setNow()->formatDateDb();
408
409 $minDateSetting = trim( $this->settings->get( 'shifts_employee_create_mindate' ) );
410 $maxDateSetting = trim( $this->settings->get( 'shifts_employee_create_maxdate' ) );
411
412 // minDate
413 $this->t->setDateDb( $today );
414 list( $dateQty, $dateMeasure ) = explode( ' ', $minDateSetting );
415 if( $dateQty ){
416 if( $dateQty > 0 ){
417 $this->t->modify( '+' . $dateQty . ' ' . $dateMeasure );
418 }
419 else {
420 $this->t->modify( $dateQty . ' ' . $dateMeasure );
421 }
422 }
423 if( 'week' == $dateMeasure ){
424 $this->t->setStartWeek();
425 }
426 if( 'month' == $dateMeasure ){
427 $this->t->setStartMonth();
428 }
429 if( 'year' == $dateMeasure ){
430 $this->t->setStartYear();
431 }
432 $minDate = $this->t->formatDateDb();
433
434 // maxDate
435 $this->t->setDateDb( $today );
436 list( $dateQty, $dateMeasure ) = explode( ' ', $maxDateSetting );
437 if( $dateQty ){
438 if( $dateQty > 0 ){
439 $this->t->modify( '+' . $dateQty . ' ' . $dateMeasure );
440 }
441 else {
442 $this->t->modify( $dateQty . ' ' . $dateMeasure );
443 }
444 }
445 if( 'week' == $dateMeasure ){
446 $this->t->setEndWeek();
447 }
448 if( 'month' == $dateMeasure ){
449 $this->t->setEndMonth();
450 }
451 if( 'year' == $dateMeasure ){
452 $this->t->setEndYear();
453 }
454 $maxDate = $this->t->formatDateDb();
455
456 $ret = array( $minDate, $maxDate );
457 return $ret;
458 }
459
460 public function quickCheckNew( $params = array() )
461 {
462 $ret = true;
463
464 static $isEmployee = null;
465 static $isManager = null;
466
467 if( null === $isEmployee ){
468 $isManager = false;
469 $isEmployee = false;
470
471 $currentUser = $this->auth->getCurrentUser();
472 $currentUserId = $currentUser->getId();
473
474 if( $currentUserId ){
475 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
476 if( $calendarsAsManager ){
477 $isManager = true;
478 }
479
480 if( ! $isManager ){
481 $employee = $this->appQuery->findEmployeeByUser( $currentUser );
482 if( $employee ){
483 $isEmployee = true;
484 }
485 }
486 }
487 }
488
489 if( $isManager ){
490 return $ret;
491 }
492
493 if( $isEmployee ){
494 if( ! isset($params['date']) ){
495 return $ret;
496 }
497
498 static $minDate = false;
499 static $maxDate = null;
500 if( false === $minDate ){
501 list( $minDate, $maxDate ) = $this->self->getMinMaxDate();
502 }
503
504 $checkDateString = $params['date'];
505 $checkDates = HC3_Functions::unglueArray( $checkDateString );
506
507 foreach( $checkDates as $checkDate ){
508 // echo "$minDate - $checkDate - $maxDate<br>";
509 if( ($checkDate < $minDate) OR ($checkDate > $maxDate) ){
510 $ret = false;
511 break;
512 }
513 }
514 }
515
516 return $ret;
517 }
518
519 public function checkNewShift( $params = array() )
520 {
521 // static $count = 0;
522 // $count++;
523
524 // echo __METHOD__ . ': ' . $count . '<br>';
525 // _print_r( $params );
526
527 $return = FALSE;
528
529 $calendars = $this->_findCalendars( $params );
530 if( $calendars === FALSE ){
531 $return = FALSE;
532 return $return;
533 }
534
535 $employeeIds = array('x');
536 if( array_key_exists('employee', $params) ){
537 $employeeIds = HC3_Functions::unglueArray( $params['employee'] );
538 }
539
540 foreach( $calendars as $calendar ){
541 if( ! $calendar->isShift() ){
542 continue;
543 }
544
545 $thisCalendarId = $calendar->getId();
546 $thisReturn = TRUE;
547 foreach( $employeeIds as $employeeId ){
548 $pos = strpos($employeeId, SH4_NEW_OPEN_SEPARATOR);
549 if( $pos ){
550 $employeeId = substr($employeeId, 0, $pos);
551 }
552
553 $thisThisReturn = $this->self->check( $thisCalendarId, 'x', $employeeId );
554 if( ! $thisThisReturn ){
555 $thisReturn = FALSE;
556 break;
557 }
558 }
559
560 if( $thisReturn ){
561 $return = TRUE;
562 break;
563 }
564 }
565
566 return $return;
567 }
568
569 protected function _findCalendars( $params = array() )
570 {
571 $return = $this->newQuery->findAllCalendars();
572
573 $employees = array();
574 if( array_key_exists('employee', $params) ){
575 $allEmployees = $this->newQuery->findAllEmployees();
576
577 $employeeId = $params['employee'];
578 $employeeIds = HC3_Functions::unglueArray( $employeeId );
579 foreach( $employeeIds as $employeeId ){
580 $pos = strpos($employeeId, SH4_NEW_OPEN_SEPARATOR);
581 if( $pos ){
582 $employeeId = substr($employeeId, 0, $pos);
583 }
584
585 if( array_key_exists($employeeId, $allEmployees) ){
586 $employees[] = $allEmployees[$employeeId];
587 }
588 else {
589 $return = FALSE;
590 return $return;
591 }
592 }
593 }
594
595 if( $employees ){
596 foreach( $employees as $employee ){
597 $filter = $this->appQuery->findCalendarsForEmployee( $employee );
598
599 $filterIds = array_keys( $filter );
600 $ids = array_keys($return);
601 foreach( $ids as $id ){
602 if( ! in_array($id, $filterIds) ){
603 unset( $return[$id] );
604 }
605 }
606 }
607 }
608
609 if( array_key_exists('calendar', $params) ){
610 $ok = FALSE;
611
612 $suppliedCalendarIds = is_array($params['calendar']) ? $params['calendar'] : array($params['calendar']);
613 foreach( $suppliedCalendarIds as $suppliedCalendarId ){
614 if( isset($return[$suppliedCalendarId]) ){
615 $ok = TRUE;
616 break;
617 }
618 }
619
620 if( ! $ok ){
621 $return = FALSE;
622 return $return;
623 }
624 }
625
626 return $return;
627 }
628
629 public function check( $calendarId, $typeId, $employeeId, $dateString = NULL )
630 {
631 $return = FALSE;
632 $today = $this->t->setNow()->formatDateDb();
633 list( $minDate, $maxDate ) = $this->self->getMinMaxDate();
634
635 $currentUser = $this->auth->getCurrentUser();
636 $currentUserId = $currentUser->getId();
637 if( ! $currentUserId ){
638 return $return;
639 }
640
641 if( $this->permission->isAdmin($currentUser) ){
642 $return = TRUE;
643 return $return;
644 }
645
646 $pos = strpos($employeeId, SH4_NEW_OPEN_SEPARATOR);
647 if( $pos ){
648 $employeeId = substr($employeeId, 0, $pos);
649 }
650
651 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
652
653 $calendarsAsEmployee = array();
654 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
655 if( $meEmployee ){
656 $meEmployeeId = $meEmployee->getId();
657 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee );
658 foreach( $employeeCalendars as $thisCalendar ){
659 $thisCalendarId = $thisCalendar->getId();
660 $checkPerms = array( 'employee_create_own_draft', 'employee_create_own_publish' );
661 foreach( $checkPerms as $perm ){
662 if( $this->calendarsPermissions->get($thisCalendar, $perm) ){
663 $calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar;
664 break;
665 }
666 }
667 }
668 }
669
670 if( ($calendarId == 'x') && ($typeId =='x') && ($employeeId == 'x') ){
671 if( $calendarsAsEmployee OR $calendarsAsManager ){
672 $return = TRUE;
673 }
674 return $return;
675 }
676
677 // check calendar
678 if( $calendarId != 'x' ){
679 if( ! (isset($calendarsAsManager[$calendarId]) OR isset($calendarsAsEmployee[$calendarId])) ){
680 return $return;
681 }
682 }
683
684 // check shift type
685 if( $typeId != 'x' ){
686 if( $calendarId == 'x' ){
687 return $return;
688 }
689
690 $calendar = $this->calendarsQuery->findActiveById( $calendarId );
691 if( ! $calendar ){
692 return $return;
693 }
694
695 $calendarShiftTypes = $this->appQuery->findShiftTypesForCalendar( $calendar );
696
697 // custom time
698 $checkTypeId = $typeId;
699 if( strpos($typeId, '-') ){
700 $checkTypeId = 0;
701 }
702 if( ! isset($calendarShiftTypes[$checkTypeId]) ){
703 return $return;
704 }
705 }
706
707 // check employee
708 if( $employeeId != 'x' ){
709 if( $calendarsAsManager ){
710 foreach( $calendarsAsManager as $calendar ){
711 $calendarEmployees = $this->appQuery->findEmployeesForCalendar( $calendar );
712 if( isset($calendarEmployees[$employeeId]) ){
713 $return = TRUE;
714 return $return;
715 }
716 }
717 }
718
719 // echo "CHECK $calendarId, $typeId, $employeeId, $date<br>";
720 // echo "ME EMPLOYEE $meEmployeeId VS $employeeId<br>";
721
722 if( $meEmployee && ($meEmployeeId == $employeeId) && $calendarsAsEmployee ){
723 if( $dateString ){
724 if( null !== $minDate ){
725 $checkDates = HC3_Functions::unglueArray( $dateString );
726 foreach( $checkDates as $checkDate ){
727 if( ($checkDate < $minDate) OR ($checkDate > $maxDate) ){
728 $return = FALSE;
729 return $return;
730 }
731 }
732 }
733 }
734
735 $return = TRUE;
736 }
737
738 return $return;
739 }
740
741 if( $calendarId != 'x' ){
742 if( isset($calendarsAsManager[$calendarId]) OR isset($calendarsAsEmployee[$calendarId]) ){
743 $return = TRUE;
744 return $return;
745 }
746 }
747
748 // echo "CALENDAR ID = $calendarId, TYPE Id = $typeId, EMPLOYEE ID = $employeeId<br>";
749 return $return;
750 }
751
752 public function findAllCombos()
753 {
754 $ret = array();
755
756 $currentUser = $this->auth->getCurrentUser();
757 $currentUserId = $currentUser->getId();
758 if( ! $currentUserId ){
759 return $ret;
760 }
761
762 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
763 foreach( $calendarsAsManager as $calendar ){
764 $calendarEmployees = $this->appQuery->findEmployeesForCalendar( $calendar );
765 foreach( $calendarEmployees as $employee ){
766 $retId = $calendar->getId() . '-' . $employee->getId();
767 $ret[ $retId ] = $retId;
768 $retId = 0 . '-' . $employee->getId();
769 $ret[ $retId ] = $retId;
770 }
771 }
772
773 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
774
775 if( $meEmployee ){
776 $calendarsAsEmployee = array();
777 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee );
778 foreach( $employeeCalendars as $thisCalendar ){
779 $thisCalendarId = $thisCalendar->getId();
780 if( $this->calendarsPermissions->get($thisCalendar, 'employee_create_own_draft') ){
781 $calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar;
782 }
783 elseif( $this->calendarsPermissions->get($thisCalendar, 'employee_create_own_publish') ){
784 $calendarsAsEmployee[ $thisCalendarId ] = $thisCalendar;
785 }
786 }
787
788 foreach( $calendarsAsEmployee as $calendar ){
789 $retId = $calendar->getId() . '-' . $meEmployee->getId();
790 $ret[ $retId ] = $retId;
791 }
792 }
793
794 return $ret;
795 }
796
797 public function findAllCombosTimeoff()
798 {
799 $ret = array();
800
801 $currentUser = $this->auth->getCurrentUser();
802 $currentUserId = $currentUser->getId();
803 if( ! $currentUserId ){
804 return $ret;
805 }
806
807 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
808 foreach( $calendarsAsManager as $calendar ){
809 if( ! $calendar->isTimeoff() ){
810 continue;
811 }
812 $calendarEmployees = $this->appQuery->findEmployeesForCalendar( $calendar );
813 foreach( $calendarEmployees as $employee ){
814 $retId = $calendar->getId() . '-' . $employee->getId();
815 $ret[ $retId ] = $retId;
816 $retId = 0 . '-' . $employee->getId();
817 $ret[ $retId ] = $retId;
818 }
819 }
820
821 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
822
823 if( $meEmployee ){
824 $calendarsAsEmployee = array();
825 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee );
826 foreach( $employeeCalendars as $calendar ){
827 if( ! $calendar->isTimeoff() ){
828 continue;
829 }
830 $thisCalendarId = $calendar->getId();
831 if( $this->calendarsPermissions->get($calendar, 'employee_create_own_draft') ){
832 $calendarsAsEmployee[ $thisCalendarId ] = $calendar;
833 }
834 elseif( $this->calendarsPermissions->get($calendar, 'employee_create_own_publish') ){
835 $calendarsAsEmployee[ $thisCalendarId ] = $calendar;
836 }
837 }
838
839 foreach( $calendarsAsEmployee as $calendar ){
840 $retId = $calendar->getId() . '-' . $meEmployee->getId();
841 $ret[ $retId ] = $retId;
842 }
843 }
844
845 return $ret;
846 }
847
848 public function findAllCombosShift()
849 {
850 $ret = array();
851
852 $currentUser = $this->auth->getCurrentUser();
853 $currentUserId = $currentUser->getId();
854 if( ! $currentUserId ){
855 return $ret;
856 }
857
858 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
859 foreach( $calendarsAsManager as $calendar ){
860 if( ! $calendar->isShift() ){
861 continue;
862 }
863
864 $calendarEmployees = $this->appQuery->findEmployeesForCalendar( $calendar );
865 foreach( $calendarEmployees as $employee ){
866 $retId = $calendar->getId() . '-' . $employee->getId();
867 $ret[ $retId ] = $retId;
868 $retId = 0 . '-' . $employee->getId();
869 $ret[ $retId ] = $retId;
870 }
871 }
872
873 $meEmployee = $this->appQuery->findEmployeeByUser( $currentUser );
874
875 if( $meEmployee ){
876 $calendarsAsEmployee = array();
877 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $meEmployee );
878 foreach( $employeeCalendars as $calendar ){
879 if( ! $calendar->isShift() ){
880 continue;
881 }
882 $thisCalendarId = $calendar->getId();
883 if( $this->calendarsPermissions->get($calendar, 'employee_create_own_draft') ){
884 $calendarsAsEmployee[ $thisCalendarId ] = $calendar;
885 }
886 elseif( $this->calendarsPermissions->get($calendar, 'employee_create_own_publish') ){
887 $calendarsAsEmployee[ $thisCalendarId ] = $calendar;
888 }
889 }
890
891 foreach( $calendarsAsEmployee as $calendar ){
892 $retId = $calendar->getId() . '-' . $meEmployee->getId();
893 $ret[ $retId ] = $retId;
894 }
895 }
896
897 return $ret;
898 }
899 }