Completed
Push — master ( 63632c...9f438b )
by Patrick
01:51
created

ShiftAPI::generateGroupLink()   C

Complexity

Conditions 17
Paths 92

Size

Total Lines 77

Duplication

Lines 9
Ratio 11.69 %

Importance

Changes 0
Metric Value
cc 17
nc 92
nop 3
dl 9
loc 77
rs 5.2166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 View Code Duplication
        if(isset($obj['unbounded']) && $obj['unbounded'])
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...
58
        {
59
            if(!isset($obj['minShifts']) || $obj['minShifts'] === 0 || $obj['minShifts'] === '')
60
            {
61
                 $obj['minShifts'] = '1';
62
            }
63
        }
64
        return $this->isUserDepartmentLead($obj['departmentID'], $this->user);
65
    }
66
67
    protected function processEntry($entry, $request)
68
    {
69
        return $this->processShift($entry, $request);
70
    }
71
72
    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...
73
    {
74
        $oldShift = new \VolunteerShift(false, $oldObj);
75
        if($oldShift->isFilled() && ($oldObj['startTime'] != $newObj['startTime'] || $oldObj['endTime'] != $newObj['endTime']))
76
        {
77
            $email = new \Emails\ShiftEmail($oldShift, 'shiftChangedSource');
78
            $emailProvider = \EmailProvider::getInstance();
79
            if($emailProvider->sendEmail($email) === false)
80
            {
81
                throw new \Exception('Unable to send email!');
82
            }
83
        }
84
        return true;
85
    }
86
87
    protected function postDeleteAction($entry)
88
    {
89
        if(empty($entry))
90
        {
91
            return true;
92
        }
93
        $shift = new \VolunteerShift(false, $entry[0]);
94 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...
95
        {
96
            $email = new \Emails\ShiftEmail($shift, 'shiftCanceledSource');
97
            $emailProvider = \EmailProvider::getInstance();
98
            if($emailProvider->sendEmail($email) === false)
99
            {
100
                throw new \Exception('Unable to send email!');
101
            } 
102
        }
103
        return true;
104
    }
105
106
    protected function genUUID()
107
    {
108
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
109
            // 32 bits for "time_low"
110
            mt_rand(0, 0xffff), mt_rand(0, 0xffff),
111
112
            // 16 bits for "time_mid"
113
            mt_rand(0, 0xffff),
114
115
            // 16 bits for "time_hi_and_version",
116
            // four most significant bits holds version number 4
117
            mt_rand(0, 0x0fff) | 0x4000,
118
119
            // 16 bits, 8 bits for "clk_seq_hi_res",
120
            // 8 bits for "clk_seq_low",
121
            // two most significant bits holds zero and one for variant DCE1.1
122
            mt_rand(0, 0x3fff) | 0x8000,
123
124
            // 48 bits for "node"
125
            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
126
        );
127
    }
128
129
    public function createGroup($request, $response)
130
    {
131
        $array = $request->getParsedBody();
132
        $count = count($array);
133
        $entArray = array();
134
        $uuid = $this->genUUID();
135
        $dataTable = $this->getDataTable();
136
        //User must be able to edit all shifts
137
        for($i = 0; $i < $count; $i++)
138
        {
139
            $filter = $this->getFilterForPrimaryKey($array[$i]);
140
            $entity = $dataTable->read($filter);
141
            if($entity === false || !isset($entity[0]))
142
            {
143
                return $response->withStatus(404);
144
            }
145
            $entity = $entity[0];
146
            if(!$this->canUpdate($request, $entity))
147
            {
148
                return $response->withStatus(401);
149
            }
150
            $entity['groupID'] = $uuid;
151
            array_push($entArray, $entity);
152
        }
153
        //If we got here we can update them all
154
        $myRet = true;
155
        $errors = array();
156
        for($i = 0; $i < $count; $i++)
157
        {
158
            $filter = $this->getFilterForPrimaryKey($array[$i]);
159
            $ret = $dataTable->update($filter, $entArray[$i]);
160
            if($ret === false)
161
            {
162
               $myRet = false;
163
               array_push($errors, $array[$i]);
164
            }
165
        }
166
        if($myRet)
167
        {
168
            return $response->withJson($myRet);
169
        }
170
        else
171
        {
172
            return $response->withJson(array('res'=>$myRet, 'errors'=>$errors));
173
        }
174
    }
175
176
    public function newGroup($request, $response)
177
    {
178
        if(!$this->canCreate($request))
179
        {
180
            return $response->withStatus(401);
181
        }
182
        $data = $request->getParsedBody();
183
        $shift = array();
184
        $shift['groupID'] = $this->genUUID();
185
        $shift['departmentID'] = $data['groupDepartmentID'];
186
        $shift['earlyLate'] = $data['groupEarlyLate'];
187
        $shift['enabled'] = $data['groupEnabled'];
188
        $shift['endTime'] = $data['groupEndTime'];
189
        $shift['eventID'] = $data['groupEvent'];
190
        $shift['name'] = $data['groupName'];
191
        $shift['startTime'] = $data['groupStartTime'];
192
        $dataTable = $this->getDataTable();
193
        $ret = true;
194
        foreach($data['roles'] as $role=>$count)
195
        {
196
            $count = intval($count);
197
            for($i = 0; $i < $count; $i++)
198
            {
199
                $shift['roleID'] = $role;
200
                if($dataTable->create($shift) === false)
201
                {
202
                    $ret = false;
203
                }
204
            }
205
        }
206
        return $response->withJSON($ret);
207
    }
208
209
    public function deleteGroup($request, $response)
210
    {
211
        $data = $request->getParsedBody();
212
        $dataTable = $this->getDataTable();
213
        $filter = new \Data\Filter('groupID eq '.$data['groupID']);
214
        $entities = $dataTable->read($filter);
215
        if(empty($entities))
216
        {
217
            return $response->withStatus(404);
218
        }
219
        if(!$this->canUpdate($request, $entities[0]))
220
        {
221
            return $response->withStatus(401);
222
        }
223
        $res = $dataTable->delete($filter);
224
        if($res)
225
        {
226
            return $response->withJSON($res);
227
        }
228
        return $response->withJSON($res, 500);
229
    }
230
231
    protected function doSignup($uid, $status, $entity, $filter, $dataTable)
232
    {
233
        if(isset($entity['earlyLate']) && $entity['earlyLate'] !== '-1')
234
        {
235
            $event = new \VolunteerEvent($entity['eventID']);
236
            if(!$event->hasVolOnEEList($uid, intval($entity['earlyLate'])))
237
            {
238
                $status = 'pending';
239
                $entity['needEEApproval'] = true;
240
                $event->addToEEList($uid, intval($entity['earlyLate']));
241
            }
242
        }
243
        $entity['participant'] = $uid;
244
        $entity['status'] = $status;
245
        return $dataTable->update($filter, $entity);
246
    }
247
248
    public function signup($request, $response, $args)
249
    {
250
        $this->validateLoggedIn($request);
251
        $shiftId = $args['shift'];
252
        $dataTable = $this->getDataTable();
253
        $filter = $this->getFilterForPrimaryKey($shiftId);
254
        $entity = $dataTable->read($filter);
255
        if(empty($entity))
256
        {
257
            return $response->withStatus(404);
258
        }
259
        $entity = $entity[0];
260 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...
261
        {
262
            return $response->withStatus(401);
263
        }
264
        $shift = new \VolunteerShift($shiftId, $entity);
265
        $entity = $this->processShift($entity, $request);
266
        if(isset($entity['minShifts']) && $entity['minShifts'] > 0)
267
        {
268
          $shift->makeCopy($dataTable);
269
        }
270
        if(isset($entity['overlap']) && $entity['overlap'])
271
        {
272
            $overlaps = $shift->findOverlaps($this->user->uid);
273
            $count = count($overlaps);
274
            $leads = array();
275
            for($i = 0; $i < $count; $i++)
276
            {
277
                $dept = new \VolunteerDepartment($overlaps[$i]->departmentID);
278
                $leads = array_merge($leads, $dept->getLeadEmails());
279
                $overlaps[$i]->status = 'pending';
280
                $tmp = new \Data\Filter('_id eq '.$overlaps[$i]->{'_id'});
281
                $res = $dataTable->update($tmp, $overlaps[$i]);
282
                if($res === false)
283
                {
284
                    return $response->withJSON(array('err'=>'Unable to update overlap with id '.$overlaps[$i]->{'_id'}));
285
                }
286
            }
287
            $dept = new \VolunteerDepartment($entity['departmentID']);
288
            $leads = array_merge($leads, $dept->getLeadEmails());
289
            $leads = array_unique($leads);
290
            $ret = $this->doSignup($this->user->uid, 'pending', $entity, $filter, $dataTable);
291
            $profile = new \VolunteerProfile($this->user->uid);
292
            $email = new \Emails\TwoShiftsAtOnceEmail($profile);
293
            $email->addLeads($leads);
294
            $emailProvider = \EmailProvider::getInstance();
295
            if($emailProvider->sendEmail($email) === false)
296
            {
297
                throw new \Exception('Unable to send duplicate email!');
298
            }
299
            return $response->withJSON($ret);
300
        }
301 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...
302
        {
303
            $ret = $this->doSignup($this->user->uid, 'filled', $entity, $filter, $dataTable);
304
            return $response->withJSON($ret);
305
        }
306 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...
307
        {
308
            $ret = $this->doSignup($this->user->uid, 'filled', $entity, $filter, $dataTable);
309
            return $response->withJSON($ret);
310
        }
311
        print_r($entity); die();
312
    }
313
314
    public function abandon($request, $response, $args)
315
    {
316
        $this->validateLoggedIn($request);
317
        $shiftId = $args['shift'];
318
        $dataTable = $this->getDataTable();
319
        $filter = $this->getFilterForPrimaryKey($shiftId);
320
        $entity = $dataTable->read($filter);
321
        if(empty($entity))
322
        {
323
            return $response->withStatus(404);
324
        }
325
        $entity = $entity[0];
326
        if(!isset($entity['participant']) || $entity['participant'] !== $this->user->uid)
327
        {
328
            return $response->withStatus(401);
329
        }
330
        $entity['participant'] = '';
331
        $entity['status'] = 'unfilled';
332
        return $response->withJSON($dataTable->update($filter, $entity));
333
    }
334
335
    public function approvePending($request, $response, $args)
336
    {
337
        if(!$this->canCreate($request))
338
        {
339
            return $response->withStatus(401);
340
        }
341
        $shiftId = $args['shift'];
342
        $dataTable = $this->getDataTable();
343
        $filter = $this->getFilterForPrimaryKey($shiftId);
344
        $entity = $dataTable->read($filter);
345
        if(empty($entity))
346
        {
347
            return $response->withStatus(404);
348
        }
349
        $entity = $entity[0];
350
        $entity['status'] = 'filled';
351
        return $response->withJSON($dataTable->update($filter, $entity));
352
    }
353
354
    public function disapprovePending($request, $response, $args)
355
    {
356
        if(!$this->canCreate($request))
357
        {
358
            return $response->withStatus(401);
359
        }
360
        $shiftId = $args['shift'];
361
        $dataTable = $this->getDataTable();
362
        $filter = $this->getFilterForPrimaryKey($shiftId);
363
        $entity = $dataTable->read($filter);
364
        if(empty($entity))
365
        {
366
            return $response->withStatus(404);
367
        }
368
        $entity['participant'] = '';
369
        $entity['status'] = 'unfilled';
370
        $profile = new \VolunteerProfile($this->user->uid);
371
        $email = new \Emails\PendingRejectedEmail($profile);
372
        $email->setShift($entity);
373
        $emailProvider = \EmailProvider::getInstance();
374
        if($emailProvider->sendEmail($email) === false)
375
        {
376
            throw new \Exception('Unable to send duplicate email!');
377
        }
378
        return $response->withJSON($dataTable->update($filter, $entity));
379
    }
380
381
    public function startGroupSignup($request, $response, $args)
382
    {
383
        $this->validateLoggedIn($request);
384
        $shiftId = $args['shift'];
385
        $dataTable = $this->getDataTable();
386
        $filter = $this->getFilterForPrimaryKey($shiftId);
387
        $entity = $dataTable->read($filter);
388
        if(empty($entity))
389
        {
390
            return $response->withStatus(404);
391
        }
392
        $entity = $entity[0];
393 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...
394
        {
395
            return $response->withStatus(401);
396
        }
397
        $filter = new \Data\Filter('groupID eq '.$entity['groupID'].' and enabled eq true');
398
        $entities = $dataTable->read($filter);
399
        $count = count($entities);
400
        $dept = new \VolunteerDepartment($entity['departmentID']);
401
        $res = array();
402
        $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...
403
        $res['earlyLate'] = $entity['earlyLate'];
404
        $res['endTime'] = $entity['endTime'];
405
        $res['eventID'] = $entity['eventID'];
406
        $res['name'] = $entity['name'];
407
        $res['startTime'] = $entity['startTime'];
408
        $res['groupID'] = $entity['groupID'];
409
        $res['shifts'] = array();
410
        $roles = array();
411
        for($i = 0; $i < $count; $i++)
412
        {
413 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...
414
            {
415
                continue;
416
            }
417
            if(!isset($roles[$entities[$i]['roleID']]))
418
            {
419
                $roles[$entities[$i]['roleID']] = new \VolunteerRole($entities[$i]['roleID']);
420
            }
421
            $role = $roles[$entities[$i]['roleID']];
422
            $entities[$i]['role'] = $role->display_name;
423
            array_push($res['shifts'], $entities[$i]);
424
        }
425
        return $response->withJSON($res);
426
    }
427
428
    public function generateGroupLink($request, $response, $args)
429
    {
430
        $this->validateLoggedIn($request);
431
        $shiftId = $args['shift'];
432
        $dataTable = $this->getDataTable();
433
        $filter = $this->getFilterForPrimaryKey($shiftId);
434
        $entity = $dataTable->read($filter);
435
        if(empty($entity))
436
        {
437
            return $response->withStatus(404);
438
        }
439
        $entity = $entity[0];
440 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...
441
        {
442
            return $response->withStatus(401);
443
        }
444
        $data = $request->getParsedBody();
445
        $myShift = $data['myshift'];
446
        $roles = array();
447
        foreach($data as $key => $value)
448
        {
449
            if(substr($key, 0, 6) === "roles.")
450
            {
451
                $roles[substr($key, 6)] = $value;
452
            }
453
        }
454
        $filter = new \Data\Filter('groupID eq '.$entity['groupID'].' and enabled eq true');
455
        $entities = $dataTable->read($filter);
456
        $count = count($entities);
457
        $uuid = $this->genUUID();
458
        for($i = 0; $i < $count; $i++)
459
        {
460 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...
461
            {
462
                $entities[$i] = false;
463
                continue;
464
            }
465
            if((string)$entities[$i]['_id'] === (string)new \MongoDB\BSON\ObjectId($myShift))
466
            {
467
                $entities[$i]['participant'] = $this->user->uid;
468
                $entities[$i]['status'] = 'filled';
469
                $entities[$i]['signupLink'] = $uuid;
470
            }
471
            else if(isset($roles[$entities[$i]['roleID']]))
472
            {
473
                $entities[$i]['status'] = 'groupPending';
474
                $entities[$i]['signupLink'] = $uuid;
475
                $roles[$entities[$i]['roleID']]--;
476
                if($roles[$entities[$i]['roleID']] === 0)
477
                {
478
                    unset($roles[$entities[$i]['roleID']]);
479
                }
480
            }
481
            else
482
            {
483
                $entities[$i] = false;
484
            }
485
        }
486
        if(count($roles) !== 0)
487
        {
488
            throw new \Exception('Not enough shifts to fullfill requests');
489
        }
490
        for($i = 0; $i < $count; $i++)
491
        {
492
            if($entities[$i] === false)
493
            {
494
                continue;
495
            }
496
            $filter = new \Data\Filter('_id eq '.$entities[$i]['_id']);
497
            $res = $dataTable->update($filter, $entities[$i]);
498
            if($res === false)
499
            {
500
                throw new \Exception('Not able to save shift '.$entities[$i]['_id']);
501
            }
502
        }
503
        return $response->withJSON(array('uuid' => $uuid));
504
    }
505
506
    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...
507
    {
508
        $this->validateLoggedIn($request);
509
        $shiftId = $args['shift'];
510
        $dataTable = $this->getDataTable();
511
        $filter = $this->getFilterForPrimaryKey($shiftId);
512
        $entity = $dataTable->read($filter);
513
        if(empty($entity))
514
        {
515
            return $response->withStatus(404);
516
        }
517
        $entity = $entity[0];
518
        if(!$this->canUpdate($request, $entity))
519
        {
520
            return $response->withStatus(401);
521
        }
522
        $shift = new \VolunteerShift(false, $entity);
523
        $entity['participant'] = '';
524
        $entity['status'] = 'unfilled';
525
        $ret = $dataTable->update($filter, $entity);
526 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...
527
        {
528
            $email = new \Emails\ShiftEmail($shift, 'shiftEmptiedSource');
529
            $emailProvider = \EmailProvider::getInstance();
530
            if($emailProvider->sendEmail($email) === false)
531
            {
532
                throw new \Exception('Unable to send email!');
533
            }
534
        }
535
        return $response->withJSON($ret);
536
    }
537
538
    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...
539
    {
540
        $this->validateLoggedIn($request);
541
        $shiftId = $args['shift'];
542
        $dataTable = $this->getDataTable();
543
        $filter = $this->getFilterForPrimaryKey($shiftId);
544
        $entity = $dataTable->read($filter);
545
        if(empty($entity))
546
        {
547
            return $response->withStatus(404);
548
        }
549
        $entity = $entity[0];
550
        if(!$this->canUpdate($request, $entity))
551
        {
552
            return $response->withStatus(401);
553
        }
554
        $entity['participant'] = '';
555
        $entity['status'] = 'unfilled';
556
        return $response->withJSON($dataTable->update($filter, $entity));
557
    }
558
}
559