TextAPI::canDelete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
class TextAPI extends VolunteerAPI
3
{
4
    public function __construct()
5
    {
6
        parent::__construct('longText', 'id');
7
    }
8
9
    protected function canRead($request)
10
    {
11
        return $this->isVolunteerAdmin($request);
12
    }
13
14
    protected function canCreate($request)
15
    {
16
        return $this->isVolunteerAdmin($request);
17
    }
18
19
    protected function canUpdate($request, $entity)
20
    {
21
        return $this->isVolunteerAdmin($request);
22
    }
23
24
    protected function canDelete($request, $entity)
25
    {
26
        return $this->canUpdate($request, $entity);
27
    }
28
29
    protected function processEntry($obj, $request)
30
    {
31
        $args = $request->getAttribute('route')->getArguments();
32
        if(empty($args))
33
        {
34
            return $obj;
35
        }
36
        return $obj['value'];
37
    }
38
39
    public function updateEntry($request, $response, $args)
40
    {
41
        if($this->canRead($request) === false)
42
        {
43
            return $response->withStatus(401);
44
        }
45
        $filter = $this->getFilterForPrimaryKey($args['name']);
46
        $dataTable = $this->getDataTable();
47
        $entry = $dataTable->read($filter);
48
        if(empty($entry))
49
        {
50
            return $response->withStatus(404);
51
        }
52
        if($this->canUpdate($request, $entry) === false)
53
        {
54
            return $response->withStatus(401);
55
        }
56
        $obj = $request->getParsedBody();
57
        if($obj === null)
58
        {
59
            $body = $request->getBody();
60
            $body->rewind();
61
            $obj = array('value'=>$body->getContents());
62
        }
63
        $ret = $dataTable->update($filter, $obj);
64
        return $response->withJson($ret);
65
    }
66
}
67
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
68