PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / query.php

query.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/new/query.php

108 lines 2.7 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_IQuery
3 {
4 public function findAllCalendars();
5 public function findAllEmployees();
6 }
7
8 class SH4_New_Query implements SH4_New_IQuery
9 {
10 public function __construct(
11 HC3_Hooks $hooks,
12 HC3_Auth $auth,
13
14 SH4_App_Query $appQuery,
15
16 SH4_Calendars_Permissions $calendarsPermissions,
17 SH4_Calendars_Query $calendarsQuery,
18 SH4_Employees_Query $employeesQuery
19 )
20 {
21 $this->auth = $auth;
22
23 $this->appQuery = $hooks->wrap( $appQuery );
24
25 $this->calendarsPermissions = $hooks->wrap( $calendarsPermissions );
26 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
27 $this->employeesQuery = $hooks->wrap( $employeesQuery );
28 }
29
30 public function findAllEmployees()
31 {
32 $return = array();
33
34 $currentUser = $this->auth->getCurrentUser();
35 $currentUserId = $currentUser->getId();
36 if( ! $currentUserId ){
37 return $return;
38 }
39
40 $allowed = array();
41
42 // as employee
43 $employee = $this->appQuery->findEmployeeByUser( $currentUser );
44 if( $employee ){
45 $employeeId = $employee->getId();
46 $allowed[ $employeeId ] = $employee;
47 }
48
49 // as manager
50 $managedCalendars = $this->appQuery->findCalendarsManagedByUser( $currentUser );
51 foreach( $managedCalendars as $calendar ){
52 $thisEmployees = $this->appQuery->findEmployeesForCalendar( $calendar );
53 $allowed = $allowed + $thisEmployees;
54 }
55
56 $allowedIds = array_keys( $allowed );
57
58 if( $allowedIds ){
59 $return = $this->employeesQuery->findManyActiveById( $allowedIds );
60 }
61
62 return $return;
63 }
64
65 public function findAllCalendars()
66 {
67 $return = array();
68
69 $currentUser = $this->auth->getCurrentUser();
70 $currentUserId = $currentUser->getId();
71 if( ! $currentUserId ){
72 return $return;
73 }
74
75 $allowed = array();
76
77 // as employee
78 $employee = $this->appQuery->findEmployeeByUser( $currentUser );
79 if( $employee ){
80 $employeeCalendars = $this->appQuery->findCalendarsForEmployee( $employee );
81 foreach( $employeeCalendars as $thisCalendar ){
82 $calendarId = $thisCalendar->getId();
83
84 $checkPerms = array( 'employee_create_own_draft', 'employee_create_own_publish' );
85 foreach( $checkPerms as $perm ){
86 if( $this->calendarsPermissions->get($thisCalendar, $perm) ){
87 $allowed[ $calendarId ] = $thisCalendar;
88 break;
89 }
90 }
91 }
92 }
93
94 // as manager
95 $managedCalendars = $this->appQuery->findCalendarsManagedByUser( $currentUser );
96 if( $managedCalendars ){
97 $allowed = $allowed + $managedCalendars;
98 }
99
100 $allowedIds = array_keys( $allowed );
101
102 if( $allowedIds ){
103 $return = $this->calendarsQuery->findManyActiveById( $allowedIds );
104 }
105
106 return $return;
107 }
108 }