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
← All changes | sh4/api/rest.php +5 -213 trunk4.9.24 View file →
@@ -1,9 +1,7 @@
1 1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 2 class SH4_Api_Rest
3 3 {
4 - public $self, $api;
5 -
6 4 public function __construct(
7 5 HC3_Hooks $hooks,
8 6 SH4_Api_Api $api
9 7 )
@@ -19,16 +17,14 @@
19 17 $myAuthCode = get_option( 'sh4-rest_auth_code', '' );
20 18 $authCode = $request->get_header( 'X-WP-ShiftController-AuthCode' );
21 19
22 20 if( $authCode && ($authCode == $myAuthCode) ){
23 - $ret = true;
21 + $ret = TRUE;
24 22 return $ret;
25 23 }
26 24
27 25 // try body params
28 - $isJson = wp_is_json_request();
29 - $values = $isJson ? $request->get_json_params() : $request->get_body_params();
30 -
26 + $values = $request->get_body_params();
31 27 if( ! $values ){
32 28 $body = $request->get_body();
33 29 parse_str( $body, $values );
34 30 }
@@ -34,20 +30,11 @@
34 30 }
35 31
36 32 if( isset($values['X-WP-ShiftController-AuthCode']) ){
37 33 $authCode = $values['X-WP-ShiftController-AuthCode'];
38 - if( $authCode && ($authCode == $myAuthCode) ){
39 - $ret = true;
40 - return $ret;
41 - }
42 - }
43 34
44 - // try get params
45 - $values = $request->get_query_params();
46 - if( isset($values['X-WP-ShiftController-AuthCode']) ){
47 - $authCode = $values['X-WP-ShiftController-AuthCode'];
48 35 if( $authCode && ($authCode == $myAuthCode) ){
49 - $ret = true;
36 + $ret = TRUE;
50 37 return $ret;
51 38 }
52 39 }
53 40
@@ -67,89 +54,8 @@
67 54 }
68 55
69 56 $startUrl = 'shiftcontroller/v4';
70 57
71 - register_rest_route( $startUrl, '/calendars',
72 - array(
73 - array(
74 - 'methods' => WP_REST_Server::READABLE,
75 - 'callback' => array($this->self, 'calendarsGet'),
76 - // 'permission_callback' => '__return_true',
77 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
78 - ),
79 - )
80 - );
81 -
82 - register_rest_route( $startUrl, '/employees',
83 - array(
84 - array(
85 - 'methods' => WP_REST_Server::READABLE,
86 - 'callback' => array($this->self, 'employeesGet'),
87 - // 'permission_callback' => '__return_true',
88 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
89 - ),
90 - array(
91 - 'methods' => WP_REST_Server::CREATABLE,
92 - 'callback' => array($this->self, 'employeesCreate'),
93 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
94 - ),
95 - )
96 - );
97 -
98 - register_rest_route( $startUrl, '/employees/(?P<id>\d+)',
99 - array(
100 - array(
101 - 'methods' => WP_REST_Server::READABLE,
102 - 'callback' => array( $this->self, 'employeesGetById' ),
103 - // 'permission_callback' => '__return_true',
104 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
105 - ),
106 - )
107 - );
108 -
109 - register_rest_route( $startUrl, '/calendars/(?P<id>\d+)/employees',
110 - array(
111 - array(
112 - 'methods' => WP_REST_Server::READABLE,
113 - 'callback' => array( $this->self, 'employeesGetByCalendarId' ),
114 - // 'permission_callback' => '__return_true',
115 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
116 - ),
117 - )
118 - );
119 -
120 - register_rest_route( $startUrl, '/employees/(?P<id>\d+)/calendars',
121 - array(
122 - array(
123 - 'methods' => WP_REST_Server::READABLE,
124 - 'callback' => array( $this->self, 'calendarsGetByEmployeeId' ),
125 - // 'permission_callback' => '__return_true',
126 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
127 - ),
128 - )
129 - );
130 -
131 - register_rest_route( $startUrl, '/users/(?P<id>\d+)/employee',
132 - array(
133 - array(
134 - 'methods' => WP_REST_Server::READABLE,
135 - 'callback' => array( $this->self, 'employeesGetByUserId' ),
136 - // 'permission_callback' => '__return_true',
137 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
138 - ),
139 - )
140 - );
141 -
142 - register_rest_route( $startUrl, '/available-employees',
143 - array(
144 - array(
145 - 'methods' => WP_REST_Server::READABLE,
146 - 'callback' => array($this->self, 'availableEmployeesGet'),
147 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
148 - ),
149 - )
150 - );
151 -
152 58 register_rest_route( $startUrl, '/shifts',
153 59 array(
154 60 array(
155 61 'methods' => WP_REST_Server::READABLE,
@@ -184,48 +90,10 @@
184 90 'permission_callback' => array( $this->self, 'checkAdmin' ),
185 91 ),
186 92 )
187 93 );
188 -
189 - register_rest_route( $startUrl, '/employees/(?P<eid>\d+)/calendars/(?P<cid>\d+)',
190 - array(
191 - array(
192 - 'methods' => WP_REST_Server::DELETABLE,
193 - 'callback' => array( $this->self, 'employeesRemoveFromCalendar' ),
194 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
195 - ),
196 - array(
197 - 'methods' => WP_REST_Server::CREATABLE,
198 - 'callback' => array( $this->self, 'employeesAddToCalendar' ),
199 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
200 - ),
201 - )
202 - );
203 -
204 - register_rest_route( $startUrl, '/calendars/(?P<eid>\d+)/employees/(?P<cid>\d+)',
205 - array(
206 - array(
207 - 'methods' => WP_REST_Server::DELETABLE,
208 - 'callback' => array( $this->self, 'employeesRemoveFromCalendar' ),
209 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
210 - ),
211 - array(
212 - 'methods' => WP_REST_Server::CREATABLE,
213 - 'callback' => array( $this->self, 'employeesAddToCalendar' ),
214 - 'permission_callback' => array( $this->self, 'checkAdmin' ),
215 - ),
216 - )
217 - );
218 94 }
219 95
220 - public function availableEmployeesGet( $request )
221 - {
222 - $queryParams = $request->get_query_params();
223 - $ret = $this->api->availableEmployeesGet( $queryParams );
224 - $ret = new WP_REST_Response( $ret );
225 - return $ret;
226 - }
227 -
228 96 public function shiftsGet( $request )
229 97 {
230 98 $queryParams = $request->get_query_params();
231 99 $ret = $this->api->shiftsGet( $queryParams );
@@ -240,11 +108,9 @@
240 108 }
241 109
242 110 public function shiftsCreate( $request )
243 111 {
244 - $isJson = wp_is_json_request();
245 - $values = $isJson ? $request->get_json_params() : $request->get_body_params();
246 -
112 + $values = $request->get_body_params();
247 113 if( ! $values ){
248 114 $body = $request->get_body();
249 115 parse_str( $body, $values );
250 116 }
@@ -260,12 +126,9 @@
260 126
261 127 public function shiftsUpdateById( $request )
262 128 {
263 129 $id = $request['id'];
264 -
265 - $isJson = wp_is_json_request();
266 - $values = $isJson ? $request->get_json_params() : $request->get_body_params();
267 -
130 + $values = $request->get_body_params();
268 131 if( ! $values ){
269 132 $body = $request->get_body();
270 133 parse_str( $body, $values );
271 134 }
@@ -270,77 +133,6 @@
270 133 parse_str( $body, $values );
271 134 }
272 135
273 136 return $this->api->shiftsUpdateById( $id, $values );
274 - }
275 -
276 - public function calendarsGet( $request )
277 - {
278 - $queryParams = $request->get_query_params();
279 - $ret = $this->api->calendarsGet( $queryParams );
280 - $ret = new WP_REST_Response( $ret );
281 - return $ret;
282 - }
283 -
284 - public function employeesGet( $request )
285 - {
286 - $queryParams = $request->get_query_params();
287 - $ret = $this->api->employeesGet( $queryParams );
288 - $ret = new WP_REST_Response( $ret );
289 - return $ret;
290 - }
291 -
292 - public function employeesGetById( $request )
293 - {
294 - $id = $request['id'];
295 - return $this->api->employeesGetById( $id );
296 - }
297 -
298 - public function employeesCreate( $request )
299 - {
300 - $isJson = wp_is_json_request();
301 - $values = $isJson ? $request->get_json_params() : $request->get_body_params();
302 -
303 - if( ! $values ){
304 - $body = $request->get_body();
305 - parse_str( $body, $values );
306 - }
307 -
308 - return $this->api->employeesCreate( $request );
309 - }
310 -
311 - public function employeesGetByUserId( $request )
312 - {
313 - $id = $request['id'];
314 - return $this->api->employeesGetByUserId( $id );
315 - }
316 -
317 - public function employeesGetByCalendarId( $request )
318 - {
319 - $id = $request['id'];
320 - $ret = $this->api->employeesGetByCalendarId( $id );
321 - return $ret;
322 - }
323 -
324 - public function calendarsGetByEmployeeId( $request )
325 - {
326 - $id = $request['id'];
327 - $ret = $this->api->calendarsGetByEmployeeId( $id );
328 - return $ret;
329 - }
330 -
331 - public function employeesAddToCalendar( $request )
332 - {
333 - $eid = $request['eid'];
334 - $cid = $request['cid'];
335 - $ret = $this->api->employeesAddToCalendar( $eid, $cid );
336 - return $ret;
337 - }
338 -
339 - public function employeesRemoveFromCalendar( $request )
340 - {
341 - $eid = $request['eid'];
342 - $cid = $request['cid'];
343 - $ret = $this->api->employeesRemoveFromCalendar( $eid, $cid );
344 - return $ret;
345 137 }
346 138 }