1
|
|
|
<?php |
2
|
|
|
class EventAPI extends VolunteerAPI |
3
|
|
|
{ |
4
|
|
|
use Processor; |
|
|
|
|
5
|
|
|
|
6
|
|
|
public function __construct() |
7
|
|
|
{ |
8
|
|
|
parent::__construct('events'); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
public function setup($app) |
12
|
|
|
{ |
13
|
|
|
parent::setup($app); |
14
|
|
|
$app->get('/{event}/shifts[/]', array($this, 'getShiftsForEvent')); |
15
|
|
|
$app->post('/{event}/shifts[/]', array($this, 'createShiftForEvent')); |
16
|
|
|
$app->get('/{event}/Actions/GetEEShiftReport', array($this, 'getEEShiftReportForEvent')); |
17
|
|
|
$app->post('/{event}/Actions/GetEEShiftReport', array($this, 'getEEShiftReportForEvent')); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
protected function getFilterForPrimaryKey($value) |
21
|
|
|
{ |
22
|
|
|
return new \Data\Filter($this->primaryKeyName." eq '$value' or alias eq '$value'"); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function canUpdate($request, $entity) |
26
|
|
|
{ |
27
|
|
|
if($this->isVolunteerAdmin($request)) |
28
|
|
|
{ |
29
|
|
|
return true; |
30
|
|
|
} |
31
|
|
|
return false; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function canDelete($request, $entity) |
35
|
|
|
{ |
36
|
|
|
if($this->isVolunteerAdmin($request)) |
37
|
|
|
{ |
38
|
|
|
return true; |
39
|
|
|
} |
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function processEntry($entry, $request) |
44
|
|
|
{ |
45
|
|
|
$entry['available'] = true; |
46
|
|
|
$endTime = new DateTime($entry['endTime']); |
47
|
|
|
$now = new DateTime(); |
48
|
|
|
if($endTime < $now) |
49
|
|
|
{ |
50
|
|
|
$entry['available'] = false; |
51
|
|
|
$entry['why'] = 'Event is in the past'; |
52
|
|
|
} |
53
|
|
|
if(isset($entry['volList']) && !is_array($entry['volList'])) |
54
|
|
|
{ |
55
|
|
|
$entry['volList'] = explode(',', $entry['volList']); |
56
|
|
|
$count = count($entry['volList']); |
57
|
|
|
for($i = 0; $i < $count; $i++) |
58
|
|
|
{ |
59
|
|
|
$entry['volList'][$i] = trim($entry['volList'][$i]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
if($entry['private'] && !in_array($this->user->mail, $entry['volList'])) |
63
|
|
|
{ |
64
|
|
|
$entry['available'] = false; |
65
|
|
|
$entry['why'] = 'Event is private and you are not invited'; |
66
|
|
|
} |
67
|
|
|
if(!$entry['available'] && !$this->isVolunteerAdmin($request) && !$this->userIsLeadCached($this->user)) |
68
|
|
|
{ |
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
if(!$this->isVolunteerAdmin($request) && !$this->userIsLeadCached($this->user) && isset($entry['eeLists'])) |
72
|
|
|
{ |
73
|
|
|
unset($entry['eeLists']); |
74
|
|
|
} |
75
|
|
|
return $entry; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getShiftsForEvent($request, $response, $args) |
79
|
|
|
{ |
80
|
|
|
$this->validateLoggedIn($request); |
81
|
|
|
$eventId = $args['event']; |
82
|
|
|
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts'); |
83
|
|
|
$odata = $request->getAttribute('odata', new \ODataParams(array())); |
84
|
|
|
$filter = $this->addRequiredFilter('eventID', $eventId, $odata); |
85
|
|
|
if($filter === false) |
86
|
|
|
{ |
87
|
|
|
return $response->withStatus(409); |
88
|
|
|
} |
89
|
|
|
$shifts = $dataTable->read($filter, $odata->select, $odata->top, |
90
|
|
|
$odata->skip, $odata->orderby); |
91
|
|
|
if($shifts === false) |
92
|
|
|
{ |
93
|
|
|
$shifts = array(); |
94
|
|
|
} |
95
|
|
|
$count = count($shifts); |
|
|
|
|
96
|
|
|
for($i = 0; $i < $count; $i++) |
97
|
|
|
{ |
98
|
|
|
$shifts[$i] = $this->processShift($shifts[$i], $request); |
99
|
|
|
} |
100
|
|
|
$shifts = array_values(array_filter($shifts)); |
|
|
|
|
101
|
|
|
return $response->withJson($shifts); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function createShiftForEvent($request, $response, $args) |
105
|
|
|
{ |
106
|
|
|
$eventId = $args['event']; |
107
|
|
|
if($this->canUpdate($request, null) === false) |
108
|
|
|
{ |
109
|
|
|
return $response->withStatus(401); |
110
|
|
|
} |
111
|
|
|
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts'); |
112
|
|
|
$obj = $request->getParsedBody(); |
113
|
|
|
if($obj == NULL) |
114
|
|
|
{ |
115
|
|
|
$obj = json_decode($request->getBody()->getContents(), true); |
116
|
|
|
} |
117
|
|
|
$obj['eventID'] = $eventId; |
118
|
|
|
$ret = $dataTable->create($obj); |
119
|
|
|
return $response->withJson($ret); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getEEShiftReportForEvent($request, $response, $args) |
123
|
|
|
{ |
124
|
|
|
$eventId = $args['event']; |
125
|
|
|
if($this->canUpdate($request, null) === false) |
126
|
|
|
{ |
127
|
|
|
return $response->withStatus(401); |
128
|
|
|
} |
129
|
|
|
$shiftDataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts'); |
130
|
|
|
$obj = $request->getParsedBody(); |
131
|
|
|
if($obj == NULL) |
132
|
|
|
{ |
133
|
|
|
$obj = json_decode($request->getBody()->getContents(), true); |
134
|
|
|
} |
135
|
|
|
$filterStr = 'eventID eq '.$eventId.' and status eq filled'; |
136
|
|
|
if(isset($obj['earlyLate'])) |
137
|
|
|
{ |
138
|
|
|
$filterStr .= ' and earlyLate eq \''.$obj['earlyLate'].'\''; |
139
|
|
|
} |
140
|
|
|
else |
141
|
|
|
{ |
142
|
|
|
$filterStr .= " and earlyLate ne '-1'"; |
143
|
|
|
} |
144
|
|
|
$filter = new \Data\Filter($filterStr); |
145
|
|
|
$shifts = $shiftDataTable->read($filter); |
146
|
|
|
$ret = array(); |
147
|
|
|
$count = count($shifts); |
|
|
|
|
148
|
|
|
for($i = 0; $i < $count; $i++) |
149
|
|
|
{ |
150
|
|
|
$shift = new \VolunteerShift(false, $shifts[$i]); |
151
|
|
|
$vol = $shift->participantObj; |
|
|
|
|
152
|
|
|
$role = $shift->role; |
|
|
|
|
153
|
|
|
$entry = array('name' => $vol->getDisplayName('paperName'), 'email'=> $vol->email, 'dept'=> $shift->departmentID, 'role' => $role->display_name, 'earlyLate'=>$shift->earlyLate); |
154
|
|
|
array_push($ret, $entry); |
155
|
|
|
} |
156
|
|
|
return $response->withJson($ret); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
160
|
|
|
|