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
|
|
|
|