|
1
|
|
|
<?php |
|
2
|
|
|
trait Processor |
|
3
|
|
|
{ |
|
4
|
|
|
protected function certCheck($requirements, $certs, $certType) |
|
5
|
|
|
{ |
|
6
|
|
|
if(isset($requirements[$certType]) && $requirements[$certType]) |
|
7
|
|
|
{ |
|
8
|
|
|
return (!isset($certs[$certType]) || !$certs[$certType]); |
|
9
|
|
|
} |
|
10
|
|
|
return false; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
public function canUserDoRole($user, $role) |
|
14
|
|
|
{ |
|
15
|
|
|
if($role['publicly_visible'] === true) |
|
16
|
|
|
{ |
|
17
|
|
|
return true; |
|
18
|
|
|
} |
|
19
|
|
|
$requirements = array(); |
|
20
|
|
|
if(isset($role['requirements'])) |
|
21
|
|
|
{ |
|
22
|
|
|
$requirements = $role['requirements']; |
|
23
|
|
|
} |
|
24
|
|
|
$certs = $user->certs; |
|
25
|
|
|
if(count($requirements) === 0) |
|
26
|
|
|
{ |
|
27
|
|
|
//Bugged role... |
|
28
|
|
|
return true; |
|
29
|
|
|
} |
|
30
|
|
|
if(isset($requirements['email_list'])) |
|
31
|
|
|
{ |
|
32
|
|
|
$emails = explode(',', $requirements['email_list']); |
|
33
|
|
|
if(!$user->userInEmailList($emails)) |
|
34
|
|
|
{ |
|
35
|
|
|
return array('whyClass' => 'INVITE', 'whyMsg' => 'Shift is invite only.'); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
if($this->certCheck($requirements, $certs, 'ics100')) |
|
39
|
|
|
{ |
|
40
|
|
|
return array('whyClass' => 'CERT', 'whyMsg' => 'Shift requires ICS 100 and you do not have that certification'); |
|
41
|
|
|
} |
|
42
|
|
|
if($this->certCheck($requirements, $certs, 'ics200')) |
|
43
|
|
|
{ |
|
44
|
|
|
return array('whyClass' => 'CERT', 'whyMsg' => 'Shift requires ICS 200 and you do not have that certification'); |
|
45
|
|
|
} |
|
46
|
|
|
if($this->certCheck($requirements, $certs, 'bls')) |
|
47
|
|
|
{ |
|
48
|
|
|
return array('whyClass' => 'CERT', 'whyMsg' => 'Shift requires Basic Life Support certification and you do not have that certification'); |
|
49
|
|
|
} |
|
50
|
|
|
return true; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function getParticipantDiplayName($uid) |
|
54
|
|
|
{ |
|
55
|
|
|
static $uids = array(); |
|
56
|
|
|
if(!isset($uids[$uid])) |
|
57
|
|
|
{ |
|
58
|
|
|
$profile = new \VolunteerProfile($uid); |
|
59
|
|
|
$uids[$uid] = $profile->getDisplayName(); |
|
60
|
|
|
} |
|
61
|
|
|
return $uids[$uid]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function isUserDepartmentLead($departmentID, $user) |
|
65
|
|
|
{ |
|
66
|
|
|
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'departments'); |
|
67
|
|
|
$filter = new \Data\Filter('departmentID eq '.$departmentID); |
|
68
|
|
|
$depts = $dataTable->read($filter); |
|
69
|
|
|
if(empty($depts)) |
|
70
|
|
|
{ |
|
71
|
|
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
return $this->isUserDepartmentLead2($depts[0], $user); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
protected function isUserDepartmentLead2($dept, $user) |
|
77
|
|
|
{ |
|
78
|
|
|
if($user->isInGroupNamed('Leads')) |
|
79
|
|
|
{ |
|
80
|
|
|
if(in_array($dept['lead'], $user->title)) |
|
81
|
|
|
{ |
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
if(!isset($dept['others'])) |
|
86
|
|
|
{ |
|
87
|
|
|
return false; |
|
88
|
|
|
} |
|
89
|
|
|
$email = $user->mail; |
|
90
|
|
|
$otherAdmins = explode(',', $dept['others']); |
|
91
|
|
|
return in_array($email, $otherAdmins); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function isAdminForShift($shift, $user) |
|
95
|
|
|
{ |
|
96
|
|
|
if($this->isAdmin) |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
return true; |
|
99
|
|
|
} |
|
100
|
|
|
if($this->isUserDepartmentLead($shift['departmentID'], $user)) |
|
101
|
|
|
{ |
|
102
|
|
|
return true; |
|
103
|
|
|
} |
|
104
|
|
|
return false; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function isAdminForRole($role, $user) |
|
108
|
|
|
{ |
|
109
|
|
|
//Shift and Role use the same key for department ID... |
|
110
|
|
|
return $this->isAdminForShift($role, $user); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
protected function shouldShowDepartment($deptId, $isAdmin) |
|
114
|
|
|
{ |
|
115
|
|
|
static $privateDepts = null; |
|
116
|
|
|
if($privateDepts === null) |
|
117
|
|
|
{ |
|
118
|
|
|
$privateDepts = VolunteerDepartment::getPrivateDepartments(); |
|
119
|
|
|
} |
|
120
|
|
|
if($isAdmin) |
|
121
|
|
|
{ |
|
122
|
|
|
return true; |
|
123
|
|
|
} |
|
124
|
|
|
return !in_array($deptId, $privateDepts); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
protected function doShiftTimeChecks($shift, $entry) |
|
128
|
|
|
{ |
|
129
|
|
|
$now = new DateTime(); |
|
130
|
|
|
if($shift->startTime < $now) |
|
131
|
|
|
{ |
|
132
|
|
|
$entry['available'] = false; |
|
133
|
|
|
$entry['why'] = 'Shift already started'; |
|
134
|
|
|
} |
|
135
|
|
|
if($shift->endTime < $now) |
|
136
|
|
|
{ |
|
137
|
|
|
$entry['available'] = false; |
|
138
|
|
|
$entry['why'] = 'Shift already ended'; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
protected function processShift($entry) |
|
143
|
|
|
{ |
|
144
|
|
|
static $profile = null; |
|
145
|
|
|
static $eeAvailable = false; |
|
146
|
|
|
static $canDoRole = array(); |
|
147
|
|
|
static $roles = array(); |
|
148
|
|
|
if($profile === null) |
|
149
|
|
|
{ |
|
150
|
|
|
$profile = new \VolunteerProfile($this->user->uid); |
|
|
|
|
|
|
151
|
|
|
$eeAvailable = $profile->isEEAvailable(); |
|
152
|
|
|
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'roles'); |
|
153
|
|
|
$tmp = $dataTable->read(); |
|
154
|
|
|
foreach($tmp as $role) |
|
|
|
|
|
|
155
|
|
|
{ |
|
156
|
|
|
$roles[$role['short_name']] = $role; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
$shift = new \VolunteerShift(false, $entry); |
|
160
|
|
|
$entry['isAdmin'] = $this->isAdminForShift($entry, $this->user); |
|
161
|
|
|
$entry['overlap'] = $shift->findOverlaps($this->user->uid, true); |
|
162
|
|
|
if(!$this->shouldShowDepartment($entry['departmentID'], $entry['isAdmin'])) |
|
163
|
|
|
{ |
|
164
|
|
|
return null; |
|
165
|
|
|
} |
|
166
|
|
|
$entry['available'] = true; |
|
167
|
|
|
$this->doShiftTimeChecks($shift, $entry); |
|
168
|
|
|
if($entry['earlyLate'] != -1 && !$eeAvailable) |
|
169
|
|
|
{ |
|
170
|
|
|
$entry['available'] = false; |
|
171
|
|
|
$entry['why'] = 'Shift requires early entry or late stay and you have not provided your legal name'; |
|
172
|
|
|
} |
|
173
|
|
|
if(!isset($canDoRole[$entry['roleID']])) |
|
174
|
|
|
{ |
|
175
|
|
|
$canDoRole[$entry['roleID']] = $this->canUserDoRole($profile, $roles[$entry['roleID']]); |
|
176
|
|
|
} |
|
177
|
|
|
if($canDoRole[$entry['roleID']] !== true) |
|
178
|
|
|
{ |
|
179
|
|
|
$entry['available'] = false; |
|
180
|
|
|
$entry['why'] = $canDoRole[$entry['roleID']]['whyMsg']; |
|
181
|
|
|
$entry['whyClass'] = $canDoRole[$entry['roleID']]['whyClass']; |
|
182
|
|
|
} |
|
183
|
|
|
if($shift->isFilled()) |
|
184
|
|
|
{ |
|
185
|
|
|
$entry['volunteer'] = $this->getParticipantDiplayName($entry['participant']); |
|
186
|
|
|
if($entry['participant'] === $profile->uid) |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
$entry['available'] = false; |
|
189
|
|
|
$entry['why'] = 'Shift is already taken, by you'; |
|
190
|
|
|
$entry['whyClass'] = 'MINE'; |
|
191
|
|
|
} |
|
192
|
|
|
else |
|
193
|
|
|
{ |
|
194
|
|
|
$entry['available'] = false; |
|
195
|
|
|
$entry['why'] = 'Shift is already taken'; |
|
196
|
|
|
$entry['whyClass'] = 'TAKEN'; |
|
197
|
|
|
} |
|
198
|
|
|
if(!$entry['isAdmin']) |
|
199
|
|
|
{ |
|
200
|
|
|
unset($entry['participant']); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
return $entry; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
protected function processRole($entry, $request) |
|
|
|
|
|
|
207
|
|
|
{ |
|
208
|
|
|
$entry['isAdmin'] = $this->isAdminForRole($entry, $this->user); |
|
209
|
|
|
return $entry; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
|
213
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: