PluginProbe
ShiftController Employee Shift Scheduling / 4.9.91
ShiftController Employee Shift Scheduling v4.9.91
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.91, at sh4/app/command.php

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