-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendarResource.php
More file actions
126 lines (117 loc) · 4.01 KB
/
Copy pathCalendarResource.php
File metadata and controls
126 lines (117 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace HulkPlayer\V1\Rest\Calendar;
use Thor\V1\Rest\ThorResource;
use ZF\ApiProblem\ApiProblem;
class CalendarResource extends ThorResource
{
/**
* Create a resource
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function create($data)
{
$player_id = $this->getEvent()->getRouteMatch()->getParam('player_id');
$user_id = $this->getUserId();
if ($player_id != $user_id){
return new ApiProblem(403, "Error while creating calendar - player can't do it for another player");
}
$player = $this->getPlayerService()->get($player_id);
if (!$player || !$data->calendar_type || $player_id != $this->getUserId()){
return new ApiProblem(400, "Error while creating calendar - no player with id=[{$player_id}] found or no calendar type provided or player has no rights");
}
if (!$data->calendar_type == 'all' || !$data->calendar_type == 'mine'){
return new ApiProblem(400, "Error while creating calendar - wrong calendar type");
}
if ($calendar_link = $this->getCalendarService()->create($player_id, $data->calendar_type)){
return new ApiProblem(200, "Calendar for player {$player_id} was successfully created", "success", "success", array ("calendar_link" => $calendar_link));
} else {
return new ApiProblem(405, "Calendar for player {$player_id} was not created");
}
}
/**
* Delete a resource
*
* @param mixed $id
* @return ApiProblem|mixed
*/
public function delete($id)
{
return new ApiProblem(405, 'The DELETE method has not been defined for individual resources');
}
/**
* Delete a collection, or members of a collection
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function deleteList($data)
{
$player_id = $this->getEvent()->getRouteMatch()->getParam('player_id');
$user_id = $this->getUserId();
if ($player_id != $user_id){
return new ApiProblem(403, "Error while deleting calendar - player can't do it for another player");
}
$player = $this->getPlayerService()->get($player_id);
if (!$player || $player_id != $this->getUserId()){
return new ApiProblem(400, "Error while deleting calendar - no player with id=[{$player_id}] found or player has no rights");
}
if ($this->getCalendarService()->delete($player_id)){
return new ApiProblem(200, "Calendar for player id=[{$player_id}] was successfully deleted");
}
return new ApiProblem(404, 'Not found');
}
/**
* Fetch a resource
*
* @param mixed $id
* @return ApiProblem|mixed
*/
public function fetch($id)
{
return new ApiProblem(405, 'The GET method has not been defined for individual resources');
}
/**
* Fetch all or a subset of resources
*
* @param array $params
* @return ApiProblem|mixed
*/
public function fetchAll($params = array())
{
return new ApiProblem(405, 'The GET method has not been defined for individual resources');
}
/**
* Patch (partial in-place update) a resource
*
* @param mixed $id
* @param mixed $data
* @return ApiProblem|mixed
*/
public function patch($id, $data)
{
return new ApiProblem(405, 'The PATCH method has not been defined for individual resources');
}
/**
* Replace a collection or members of a collection
*
* @param mixed $data
* @return ApiProblem|mixed
*/
public function replaceList($data)
{
return new ApiProblem(405, 'The PUT method has not been defined for collections');
}
/**
* Update a resource
*
* @param mixed $id
* @param mixed $data
* @return ApiProblem|mixed
*/
public function update($id, $data)
{
return new ApiProblem(405, 'The PUT method has not been defined for individual resources');
}
}