PluginProbe
ShiftController Employee Shift Scheduling / 4.9.68
ShiftController Employee Shift Scheduling v4.9.68
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 / app / command.php

command.php in ShiftController Employee Shift Scheduling 4.9.68, at sh4/app/command.php

223 lines 7.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_App_ICommand
3 {
4 public function linkEmployeeToUser( SH4_Employees_Model $employee, HC3_Users_Model $user );
5 public function unlinkEmployeeFromUser( SH4_Employees_Model $employee );
6
7 public function addManagerToCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar );
8 public function removeManagerFromCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar );
9
10 public function addViewerToCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar );
11 public function removeViewerFromCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar );
12
13 public function addEmployeeToCalendar( SH4_Employees_Model $employee, SH4_Calendars_Model $calendar );
14 public function removeEmployeeFromCalendar( SH4_Employees_Model $employee, SH4_Calendars_Model $calendar );
15
16 public function addShiftTypeToCalendar( SH4_ShiftTypes_Model $shiftType, SH4_Calendars_Model $calendar );
17 public function removeShiftTypeFromCalendar( SH4_ShiftTypes_Model $shiftType, SH4_Calendars_Model $calendar );
18
19 public function uninstall();
20 }
21
22 class SH4_App_Command implements SH4_App_ICommand
23 {
24 public $crudFactory, $settings, $shiftTypesCommand, $calendarsCommand, $employeesCommand, $shiftsCommand;
25
26 public function __construct(
27 HC3_CrudFactory $crudFactory,
28 HC3_Settings $settings,
29 HC3_Hooks $hooks,
30
31 SH4_ShiftTypes_Command $shiftTypesCommand,
32 SH4_Calendars_Command $calendarsCommand,
33 SH4_Employees_Command $employeesCommand,
34 SH4_Shifts_Command $shiftsCommand
35 )
36 {
37 $this->crudFactory = $hooks->wrap( $crudFactory );
38 $this->settings = $hooks->wrap( $settings );
39 $this->shiftTypesCommand = $hooks->wrap( $shiftTypesCommand );
40 $this->calendarsCommand = $hooks->wrap( $calendarsCommand );
41 $this->employeesCommand = $hooks->wrap( $employeesCommand );
42 $this->shiftsCommand = $hooks->wrap( $shiftsCommand );
43 }
44
45 public function uninstall()
46 {
47 // $this->shiftTypesCommand->deleteAll();
48 // $this->calendarsCommand->deleteAll();
49 // $this->employeesCommand->deleteAll();
50 // $this->shiftsCommand->deleteAll();
51 $this->settings->resetAll();
52 }
53
54 public function addManagerToCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar )
55 {
56 $userId = $user->getId();
57 $calendarId = $calendar->getId();
58 $settingName = 'calendar_' . $calendarId . '_manager';
59
60 $managersIds = $this->settings->get( $settingName, TRUE );
61
62 $iis = array_keys( $managersIds );
63 foreach( $iis as $ii ){
64 if( ! is_numeric($managersIds[$ii]) ){
65 unset( $managersIds[$ii] );
66 }
67 }
68
69 if( ! in_array($userId, $managersIds) ){
70 $managersIds[] = $userId;
71 }
72
73 $this->settings->set( $settingName, $managersIds );
74 }
75
76 public function removeManagerFromCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar )
77 {
78 $userId = $user->getId();
79 $calendarId = $calendar->getId();
80 $settingName = 'calendar_' . $calendarId . '_manager';
81
82 $managersIds = $this->settings->get( $settingName, TRUE );
83 $managersIds = HC3_Functions::removeFromArray( $managersIds, $userId );
84
85 $this->settings->set( $settingName, $managersIds );
86 }
87
88 public function addViewerToCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar )
89 {
90 $userId = $user->getId();
91 $calendarId = $calendar->getId();
92 $settingName = 'calendar_' . $calendarId . '_viewer';
93
94 $managersIds = $this->settings->get( $settingName, TRUE );
95
96 $iis = array_keys( $managersIds );
97 foreach( $iis as $ii ){
98 if( ! is_numeric($managersIds[$ii]) ){
99 unset( $managersIds[$ii] );
100 }
101 }
102
103 if( ! in_array($userId, $managersIds) ){
104 $managersIds[] = $userId;
105 }
106
107 $this->settings->set( $settingName, $managersIds );
108 }
109
110 public function removeViewerFromCalendar( HC3_Users_Model $user, SH4_Calendars_Model $calendar )
111 {
112 $userId = $user->getId();
113 $calendarId = $calendar->getId();
114 $settingName = 'calendar_' . $calendarId . '_viewer';
115
116 $managersIds = $this->settings->get( $settingName, TRUE );
117 $managersIds = HC3_Functions::removeFromArray( $managersIds, $userId );
118
119 $this->settings->set( $settingName, $managersIds );
120 }
121
122 public function addEmployeeToCalendar( SH4_Employees_Model $employee, SH4_Calendars_Model $calendar )
123 {
124 $employeeId = $employee->getId();
125 $calendarId = $calendar->getId();
126 $settingName = 'calendar_' . $calendarId . '_employee';
127
128 $employeesIds = $this->settings->get( $settingName, TRUE );
129
130 $iis = array_keys( $employeesIds );
131 foreach( $iis as $ii ){
132 if( ! is_numeric($employeesIds[$ii]) ){
133 unset( $employeesIds[$ii] );
134 }
135 }
136
137 if( ! in_array($employeeId, $employeesIds) ){
138 $employeesIds[] = $employeeId;
139 }
140
141 $this->settings->set( $settingName, $employeesIds );
142 }
143
144 public function addShiftTypeToCalendar( SH4_ShiftTypes_Model $shiftType, SH4_Calendars_Model $calendar )
145 {
146 $shiftTypeId = $shiftType->getId();
147 $calendarId = $calendar->getId();
148 $settingName = 'calendar_' . $calendarId . '_shifttype';
149
150 $shiftTypesIds = $this->settings->get( $settingName, TRUE );
151
152 $iis = array_keys( $shiftTypesIds );
153 foreach( $iis as $ii ){
154 if( ! is_numeric($shiftTypesIds[$ii]) ){
155 unset( $shiftTypesIds[$ii] );
156 }
157 }
158
159 if( ! in_array($shiftTypeId, $shiftTypesIds) ){
160 $shiftTypesIds[] = $shiftTypeId;
161 }
162
163 $this->settings->set( $settingName, $shiftTypesIds );
164 }
165
166 public function removeShiftTypeFromCalendar( SH4_ShiftTypes_Model $shiftType, SH4_Calendars_Model $calendar )
167 {
168 $shiftTypeId = $shiftType->getId();
169 $calendarId = $calendar->getId();
170 $settingName = 'calendar_' . $calendarId . '_shifttype';
171
172 $shiftTypesIds = $this->settings->get( $settingName, TRUE );
173 $shiftTypesIds = HC3_Functions::removeFromArray( $shiftTypesIds, $shiftTypeId );
174
175 $this->settings->set( $settingName, $shiftTypesIds );
176 }
177
178 public function removeEmployeeFromCalendar( SH4_Employees_Model $employee, SH4_Calendars_Model $calendar )
179 {
180 $employeeId = $employee->getId();
181 $calendarId = $calendar->getId();
182 $settingName = 'calendar_' . $calendarId . '_employee';
183
184 $employeesIds = $this->settings->get( $settingName, TRUE );
185 $employeesIds = HC3_Functions::removeFromArray( $employeesIds, $employeeId );
186
187 $this->settings->set( $settingName, $employeesIds );
188 }
189
190 public function linkEmployeeToUserById( $employeeId, $userId )
191 {
192 if( ! $employeeId ){
193 return;
194 }
195
196 if( ! $userId ){
197 return;
198 }
199
200 $crud = $this->crudFactory->make('employee');
201
202 $values = array( 'user_id' => $userId );
203 $results = $crud->update( $employeeId, $values );
204 }
205
206 public function linkEmployeeToUser( SH4_Employees_Model $employee, HC3_Users_Model $user )
207 {
208 return $this->self->linkEmployeeToUserById( $employee->getId(), $user->getId() );
209 }
210
211 public function unlinkEmployeeFromUser( SH4_Employees_Model $employee )
212 {
213 $employeeId = $employee->getId();
214 if( ! $employeeId ){
215 return;
216 }
217
218 $crud = $this->crudFactory->make('employee');
219
220 $values = array( 'user_id' => NULL );
221 $results = $crud->update( $employeeId, $values );
222 }
223 }