Completed
Push — master ( 9e1d87...340598 )
by Patrick
01:35
created

ShiftAPI   F

Complexity

Total Complexity 97

Size/Duplication

Total Lines 536
Duplicated Lines 9.51 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
dl 51
loc 536
rs 2
c 0
b 0
f 0
wmc 97
lcom 1
cbo 12

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setup() 0 15 1
A canCreate() 0 5 1
A canUpdate() 0 8 2
A canDelete() 0 4 1
A validateCreate() 0 12 3
A processEntry() 0 4 1
A postUpdateAction() 0 14 5
A postDeleteAction() 9 18 4
A genUUID() 0 22 1
B createGroup() 0 46 8
A newGroup() 0 32 5
A deleteGroup() 0 21 4
C signup() 16 68 15
A abandon() 0 20 4
A approvePending() 0 18 3
A disapprovePending() 0 26 4
B startGroupSignup() 8 46 9
C generateGroupLink() 9 77 17
A emptyShift() 9 31 5
A forceEmpty() 0 20 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ShiftAPI often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ShiftAPI, and based on these observations, apply Extract Interface, too.

1
<?php
2
class ShiftAPI extends VolunteerAPI
3
{
4
    use Processor;
5
6
    public function __construct()
7
    {
8
        parent::__construct('shifts');
9
    }
10
11
    public function setup($app)
12
    {
13
        parent::setup($app);
14
        $app->post('/Actions/CreateGroup', array($this, 'createGroup'));
15
        $app->post('/Actions/NewGroup', array($this, 'newGroup'));
16
        $app->post('/Actions/DeleteGroup', array($this, 'deleteGroup'));
17
        $app->post('/{shift}/Actions/Signup[/]', array($this, 'signup'));
18
        $app->post('/{shift}/Actions/Abandon[/]', array($this, 'abandon'));
19
        $app->post('/{shift}/Actions/Approve[/]', array($this, 'approvePending'));
20
        $app->post('/{shift}/Actions/Disapprove[/]', array($this, 'disapprovePending')); 
21
        $app->post('/{shift}/Actions/StartGroupSignup', array($this, 'startGroupSignup'));
22
        $app->post('/{shift}/Actions/GenerateGroupLink', array($this, 'generateGroupLink'));
23
        $app->post('/{shift}/Actions/EmptyShift[/]', array($this, 'emptyShift'));
24
        $app->post('/{shift}/Actions/ForceShiftEmpty[/]', array($this, 'forceEmpty'));
25
    }
26
27
    protected function canCreate($request)
28
    {
29
        //Check is handled by validateCreate...
30
        return true;
31
    }
32
33
    protected function canUpdate($request, $entity)
34
    {
35
 	if($this->isVolunteerAdmin($request))
36
        {
37
            return true;
38
        }
39
        return $this->isUserDepartmentLead($entity['departmentID'], $this->user);
40
    }
41
42
    protected function canDelete($request, $entity)
43
    {
44
        return $this->canUpdate($request, $entity);
45
    }
46
47
    protected function validateCreate(&$obj, $request)
48
    {
49
        if($this->isVolunteerAdmin($request))
50
        {
51
            return true;
52
        }
53
        if(!isset($obj['departmentID']))
54
        {
55
             return false;
56
        }
57
        return $this->isUserDepartmentLead($obj['departmentID'], $this->user);
58
    }
59
60
    protected function processEntry($entry, $request)
61
    {
62
        return $this->processShift($entry, $request);
63
    }
64
65
    protected function postUpdateAction($newObj, $request, $oldObj)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
        $oldShift = new \VolunteerShift(false, $oldObj);
68
        if($oldShift->isFilled() && ($oldObj['startTime'] != $newObj['startTime'] || $oldObj['endTime'] != $newObj['endTime']))
69
        {
70
            $email = new \Emails\ShiftEmail($oldShift, 'shiftChangedSource');
71
            $emailProvider = \EmailProvider::getInstance();
72
            if($emailProvider->sendEmail($email) === false)
73
            {
74
                throw new \Exception('Unable to send email!');
75
            }
76
        }
77
        return true;
78
    }
79
80
    protected function postDeleteAction($entry)
81
    {
82
        if(empty($entry))
83
        {
84
            return true;
85
        }
86
        $shift = new \VolunteerShift(false, $entry[0]);
87 View Code Duplication
        if($shift->isFilled())
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
        {
89
            $email = new \Emails\ShiftEmail($shift, 'shiftCanceledSource');
90
            $emailProvider = \EmailProvider::getInstance();
91
            if($emailProvider->sendEmail($email) === false)
92
            {
93
                throw new \Exception('Unable to send email!');
94
            } 
95
        }
96
        return true;
97
    }
98
99
    protected function genUUID()
100
    {
101
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
102
            // 32 bits for "time_low"
103
            mt_rand(0, 0xffff), mt_rand(0, 0xffff),
104
105
            // 16 bits for "time_mid"
106
            mt_rand(0, 0xffff),
107
108
            // 16 bits for "time_hi_and_version",
109
            // four most significant bits holds version number 4
110
            mt_rand(0, 0x0fff) | 0x4000,
111
112
            // 16 bits, 8 bits for "clk_seq_hi_res",
113
            // 8 bits for "clk_seq_low",
114
            // two most significant bits holds zero and one for variant DCE1.1
115
            mt_rand(0, 0x3fff) | 0x8000,
116
117
            // 48 bits for "node"
118
            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
119
        );
120
    }
121
122
    public function createGroup($request, $response)
123
    {
124
        $array = $request->getParsedBody();
125
        $count = count($array);
126
        $entArray = array();
127
        $uuid = $this->genUUID();
128
        $dataTable = $this->getDataTable();
129
        //User must be able to edit all shifts
130
        for($i = 0; $i < $count; $i++)
131
        {
132
            $filter = $this->getFilterForPrimaryKey($array[$i]);
133
            $entity = $dataTable->read($filter);
134
            if($entity === false || !isset($entity[0]))
135
            {
136
                return $response->withStatus(404);
137
            }
138
            $entity = $entity[0];
139
            if(!$this->canUpdate($request, $entity))
140
            {
141
                return $response->withStatus(401);
142
            }
143
            $entity['groupID'] = $uuid;
144
            array_push($entArray, $entity);
145
        }
146
        //If we got here we can update them all
147
        $myRet = true;
148
        $errors = array();
149
        for($i = 0; $i < $count; $i++)
150
        {
151
            $filter = $this->getFilterForPrimaryKey($array[$i]);
152
            $ret = $dataTable->update($filter, $entArray[$i]);
153
            if($ret === false)
154
            {
155
               $myRet = false;
156
               array_push($errors, $array[$i]);
157
            }
158
        }
159
        if($myRet)
160
        {
161
            return $response->withJson($myRet);
162
        }
163
        else
164
        {
165
            return $response->withJson(array('res'=>$myRet, 'errors'=>$errors));
166
        }
167
    }
168
169
    public function newGroup($request, $response)
170
    {
171
        if(!$this->canCreate($request))
172
        {
173
            return $response->withStatus(401);
174
        }
175
        $data = $request->getParsedBody();
176
        $shift = array();
177
        $shift['groupID'] = $this->genUUID();
178
        $shift['departmentID'] = $data['groupDepartmentID'];
179
        $shift['earlyLate'] = $data['groupEarlyLate'];
180
        $shift['enabled'] = $data['groupEnabled'];
181
        $shift['endTime'] = $data['groupEndTime'];
182
        $shift['eventID'] = $data['groupEvent'];
183
        $shift['name'] = $data['groupName'];
184
        $shift['startTime'] = $data['groupStartTime'];
185
        $dataTable = $this->getDataTable();
186
        $ret = true;
187
        foreach($data['roles'] as $role=>$count)
188
        {
189
            $count = intval($count);
190
            for($i = 0; $i < $count; $i++)
191
            {
192
                $shift['roleID'] = $role;
193
                if($dataTable->create($shift) === false)
194
                {
195
                    $ret = false;
196
                }
197
            }
198
        }
199
        return $response->withJSON($ret);
200
    }
201
202
    public function deleteGroup($request, $response)
203
    {
204
        $data = $request->getParsedBody();
205
        $dataTable = $this->getDataTable();
206
        $filter = new \Data\Filter('groupID eq '.$data['groupID']);
207
        $entities = $dataTable->read($filter);
208
        if(empty($entities))
209
        {
210
            return $response->withStatus(404);
211
        }
212
        if(!$this->canUpdate($request, $entities[0]))
213
        {
214
            return $response->withStatus(401);
215
        }
216
        $res = $dataTable->delete($filter);
217
        if($res)
218
        {
219
            return $response->withJSON($res);
220
        }
221
        return $response->withJSON($res, 500);
222
    }
223
224
    public function signup($request, $response, $args)
225
    {
226
        $this->validateLoggedIn($request);
227
        $shiftId = $args['shift'];
228
        $dataTable = $this->getDataTable();
229
        $filter = $this->getFilterForPrimaryKey($shiftId);
230
        $entity = $dataTable->read($filter);
231
        if(empty($entity))
232
        {
233
            return $response->withStatus(404);
234
        }
235
        $entity = $entity[0];
236 View Code Duplication
        if(isset($entity['participant']) && strlen($entity['participant']) > 0)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
        {
238
            return $response->withStatus(401);
239
        }
240
        $shift = new \VolunteerShift($shiftId, $entity);
241
        $entity = $this->processShift($entity, $request);
242
        if(isset($entity['minShifts']) && $entity['minShifts'] > 0)
243
        {
244
          $shift->makeCopy($dataTable);
245
        }
246
        if(isset($entity['overlap']) && $entity['overlap'])
247
        {
248
            $overlaps = $shift->findOverlaps($this->user->uid);
249
            $count = count($overlaps);
250
            $leads = array();
251
            for($i = 0; $i < $count; $i++)
252
            {
253
                $dept = new \VolunteerDepartment($overlaps[$i]->departmentID);
254
                $leads = array_merge($leads, $dept->getLeadEmails());
255
                $overlaps[$i]->status = 'pending';
256
                $tmp = new \Data\Filter('_id eq '.$overlaps[$i]->{'_id'});
257
                $res = $dataTable->update($tmp, $overlaps[$i]);
258
                if($res === false)
259
                {
260
                    return $response->withJSON(array('err'=>'Unable to update overlap with id '.$overlaps[$i]->{'_id'}));
261
                }
262
            }
263
            $dept = new \VolunteerDepartment($entity['departmentID']);
264
            $leads = array_merge($leads, $dept->getLeadEmails());
265
            $leads = array_unique($leads);
266
            $entity['participant'] = $this->user->uid;
267
            $entity['status'] = 'pending';
268
            $profile = new \VolunteerProfile($this->user->uid);
269
            $email = new \Emails\TwoShiftsAtOnceEmail($profile);
270
            $email->addLeads($leads);
271
            $emailProvider = \EmailProvider::getInstance();
272
            if($emailProvider->sendEmail($email) === false)
273
            {
274
                throw new \Exception('Unable to send duplicate email!');
275
            }
276
            return $response->withJSON($dataTable->update($filter, $entity));
277
        }
278 View Code Duplication
        if(isset($entity['available']) && $entity['available'])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
279
        {
280
            $entity['participant'] = $this->user->uid;
281
            $entity['status'] = 'filled';
282
            return $response->withJSON($dataTable->update($filter, $entity));
283
        }
284 View Code Duplication
        if(isset($entity['status']) && $entity['status'] === 'groupPending')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
285
        {
286
            $entity['participant'] = $this->user->uid;
287
            $entity['status'] = 'filled';
288
            return $response->withJSON($dataTable->update($filter, $entity));
289
        }
290
        print_r($entity); die();
291
    }
292
293
    public function abandon($request, $response, $args)
294
    {
295
        $this->validateLoggedIn($request);
296
        $shiftId = $args['shift'];
297
        $dataTable = $this->getDataTable();
298
        $filter = $this->getFilterForPrimaryKey($shiftId);
299
        $entity = $dataTable->read($filter);
300
        if(empty($entity))
301
        {
302
            return $response->withStatus(404);
303
        }
304
        $entity = $entity[0];
305
        if(!isset($entity['participant']) || $entity['participant'] !== $this->user->uid)
306
        {
307
            return $response->withStatus(401);
308
        }
309
        $entity['participant'] = '';
310
        $entity['status'] = 'unfilled';
311
        return $response->withJSON($dataTable->update($filter, $entity));
312
    }
313
314
    public function approvePending($request, $response, $args)
315
    {
316
        if(!$this->canCreate($request))
317
        {
318
            return $response->withStatus(401);
319
        }
320
        $shiftId = $args['shift'];
321
        $dataTable = $this->getDataTable();
322
        $filter = $this->getFilterForPrimaryKey($shiftId);
323
        $entity = $dataTable->read($filter);
324
        if(empty($entity))
325
        {
326
            return $response->withStatus(404);
327
        }
328
        $entity = $entity[0];
329
        $entity['status'] = 'filled';
330
        return $response->withJSON($dataTable->update($filter, $entity));
331
    }
332
333
    public function disapprovePending($request, $response, $args)
334
    {
335
        if(!$this->canCreate($request))
336
        {
337
            return $response->withStatus(401);
338
        }
339
        $shiftId = $args['shift'];
340
        $dataTable = $this->getDataTable();
341
        $filter = $this->getFilterForPrimaryKey($shiftId);
342
        $entity = $dataTable->read($filter);
343
        if(empty($entity))
344
        {
345
            return $response->withStatus(404);
346
        }
347
        $entity['participant'] = '';
348
        $entity['status'] = 'unfilled';
349
        $profile = new \VolunteerProfile($this->user->uid);
350
        $email = new \Emails\PendingRejectedEmail($profile);
351
        $email->setShift($entity);
352
        $emailProvider = \EmailProvider::getInstance();
353
        if($emailProvider->sendEmail($email) === false)
354
        {
355
            throw new \Exception('Unable to send duplicate email!');
356
        }
357
        return $response->withJSON($dataTable->update($filter, $entity));
358
    }
359
360
    public function startGroupSignup($request, $response, $args)
361
    {
362
        $this->validateLoggedIn($request);
363
        $shiftId = $args['shift'];
364
        $dataTable = $this->getDataTable();
365
        $filter = $this->getFilterForPrimaryKey($shiftId);
366
        $entity = $dataTable->read($filter);
367
        if(empty($entity))
368
        {
369
            return $response->withStatus(404);
370
        }
371
        $entity = $entity[0];
372 View Code Duplication
        if(isset($entity['participant']) && strlen($entity['participant']) > 0)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
373
        {
374
            return $response->withStatus(401);
375
        }
376
        $filter = new \Data\Filter('groupID eq '.$entity['groupID'].' and enabled eq true');
377
        $entities = $dataTable->read($filter);
378
        $count = count($entities);
379
        $dept = new \VolunteerDepartment($entity['departmentID']);
380
        $res = array();
381
        $res['department'] = $dept->departmentName;
0 ignored issues
show
Bug introduced by
The property departmentName does not seem to exist in VolunteerDepartment.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
382
        $res['earlyLate'] = $entity['earlyLate'];
383
        $res['endTime'] = $entity['endTime'];
384
        $res['eventID'] = $entity['eventID'];
385
        $res['name'] = $entity['name'];
386
        $res['startTime'] = $entity['startTime'];
387
        $res['groupID'] = $entity['groupID'];
388
        $res['shifts'] = array();
389
        $roles = array();
390
        for($i = 0; $i < $count; $i++)
391
        {
392 View Code Duplication
            if(isset($entities[$i]['status']) && ($entities[$i]['status'] === 'filled' || $entities[$i]['status'] === 'pending'))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
393
            {
394
                continue;
395
            }
396
            if(!isset($roles[$entities[$i]['roleID']]))
397
            {
398
                $roles[$entities[$i]['roleID']] = new \VolunteerRole($entities[$i]['roleID']);
399
            }
400
            $role = $roles[$entities[$i]['roleID']];
401
            $entities[$i]['role'] = $role->display_name;
402
            array_push($res['shifts'], $entities[$i]);
403
        }
404
        return $response->withJSON($res);
405
    }
406
407
    public function generateGroupLink($request, $response, $args)
408
    {
409
        $this->validateLoggedIn($request);
410
        $shiftId = $args['shift'];
411
        $dataTable = $this->getDataTable();
412
        $filter = $this->getFilterForPrimaryKey($shiftId);
413
        $entity = $dataTable->read($filter);
414
        if(empty($entity))
415
        {
416
            return $response->withStatus(404);
417
        }
418
        $entity = $entity[0];
419 View Code Duplication
        if(isset($entity['participant']) && strlen($entity['participant']) > 0)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
420
        {
421
            return $response->withStatus(401);
422
        }
423
        $data = $request->getParsedBody();
424
        $myShift = $data['myshift'];
425
        $roles = array();
426
        foreach($data as $key => $value)
427
        {
428
            if(substr($key, 0, 6) === "roles.")
429
            {
430
                $roles[substr($key, 6)] = $value;
431
            }
432
        }
433
        $filter = new \Data\Filter('groupID eq '.$entity['groupID'].' and enabled eq true');
434
        $entities = $dataTable->read($filter);
435
        $count = count($entities);
436
        $uuid = $this->genUUID();
437
        for($i = 0; $i < $count; $i++)
438
        {
439 View Code Duplication
            if(isset($entities[$i]['status']) && ($entities[$i]['status'] === 'filled' || $entities[$i]['status'] === 'pending'))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
440
            {
441
                $entities[$i] = false;
442
                continue;
443
            }
444
            if((string)$entities[$i]['_id'] === (string)new \MongoDB\BSON\ObjectId($myShift))
445
            {
446
                $entities[$i]['participant'] = $this->user->uid;
447
                $entities[$i]['status'] = 'filled';
448
                $entities[$i]['signupLink'] = $uuid;
449
            }
450
            else if(isset($roles[$entities[$i]['roleID']]))
451
            {
452
                $entities[$i]['status'] = 'groupPending';
453
                $entities[$i]['signupLink'] = $uuid;
454
                $roles[$entities[$i]['roleID']]--;
455
                if($roles[$entities[$i]['roleID']] === 0)
456
                {
457
                    unset($roles[$entities[$i]['roleID']]);
458
                }
459
            }
460
            else
461
            {
462
                $entities[$i] = false;
463
            }
464
        }
465
        if(count($roles) !== 0)
466
        {
467
            throw new \Exception('Not enough shifts to fullfill requests');
468
        }
469
        for($i = 0; $i < $count; $i++)
470
        {
471
            if($entities[$i] === false)
472
            {
473
                continue;
474
            }
475
            $filter = new \Data\Filter('_id eq '.$entities[$i]['_id']);
476
            $res = $dataTable->update($filter, $entities[$i]);
477
            if($res === false)
478
            {
479
                throw new \Exception('Not able to save shift '.$entities[$i]['_id']);
480
            }
481
        }
482
        return $response->withJSON(array('uuid' => $uuid));
483
    }
484
485
    function emptyShift($request, $response, $args)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
486
    {
487
        $this->validateLoggedIn($request);
488
        $shiftId = $args['shift'];
489
        $dataTable = $this->getDataTable();
490
        $filter = $this->getFilterForPrimaryKey($shiftId);
491
        $entity = $dataTable->read($filter);
492
        if(empty($entity))
493
        {
494
            return $response->withStatus(404);
495
        }
496
        $entity = $entity[0];
497
        if(!$this->canUpdate($request, $entity))
498
        {
499
            return $response->withStatus(401);
500
        }
501
        $shift = new \VolunteerShift(false, $entity);
502
        $entity['participant'] = '';
503
        $entity['status'] = 'unfilled';
504
        $ret = $dataTable->update($filter, $entity);
505 View Code Duplication
        if($ret)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
506
        {
507
            $email = new \Emails\ShiftEmail($shift, 'shiftEmptiedSource');
508
            $emailProvider = \EmailProvider::getInstance();
509
            if($emailProvider->sendEmail($email) === false)
510
            {
511
                throw new \Exception('Unable to send email!');
512
            }
513
        }
514
        return $response->withJSON($ret);
515
    }
516
517
    function forceEmpty($request, $response, $args)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
518
    {
519
        $this->validateLoggedIn($request);
520
        $shiftId = $args['shift'];
521
        $dataTable = $this->getDataTable();
522
        $filter = $this->getFilterForPrimaryKey($shiftId);
523
        $entity = $dataTable->read($filter);
524
        if(empty($entity))
525
        {
526
            return $response->withStatus(404);
527
        }
528
        $entity = $entity[0];
529
        if(!$this->canUpdate($request, $entity))
530
        {
531
            return $response->withStatus(401);
532
        }
533
        $entity['participant'] = '';
534
        $entity['status'] = 'unfilled';
535
        return $response->withJSON($dataTable->update($filter, $entity));
536
    }
537
}
538