1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* A class to abstract access to a Volunter System Shift. |
4
|
|
|
* |
5
|
|
|
* This class is the primary method to access shift information. |
6
|
|
|
* |
7
|
|
|
* @property string $_id The shift's ID |
8
|
|
|
* @property string $departmentID The shift's department |
9
|
|
|
* @property string $eventID The shift's event |
10
|
|
|
* @property string $roleID The shift's role |
11
|
|
|
* @property DateTime $startTime The shifts's starting time |
12
|
|
|
* @property DateTime $endTime The shifts's ending time |
13
|
|
|
* @property boolean $enabled Is the shift available for signup |
14
|
|
|
* @property string $earlyLate The shift's Early Entry/Late Stay status |
15
|
|
|
*/ |
16
|
|
|
class VolunteerShift extends VolunteerObject |
17
|
|
|
{ |
18
|
|
|
protected static $deptCache = array(); |
19
|
|
|
protected static $roleCache = array(); |
20
|
|
|
protected static $eventCache = array(); |
21
|
|
|
protected $mod = null; |
22
|
|
|
protected $myStart = null; |
23
|
|
|
protected $myEnd = null; |
24
|
|
|
protected $modStart = null; |
25
|
|
|
protected $modEnd = null; |
26
|
|
|
protected $participantObj = null; |
27
|
|
|
protected $webParticipantName = null; |
28
|
|
|
|
29
|
|
|
public function __construct($shiftID, $dbData = null) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($shiftID, $dbData, 'shifts', '_id'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function __get($propName) |
35
|
|
|
{ |
36
|
|
|
switch($propName) |
37
|
|
|
{ |
38
|
|
|
case 'modTime': |
39
|
|
|
if($this->mod === null) |
40
|
|
|
{ |
41
|
|
|
$this->mod = new \DateInterval('PT'.strval($this->role->down_time).'H'); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
return $this->mod; |
44
|
|
|
case 'startTime': |
45
|
|
|
if($this->myStart === null) |
46
|
|
|
{ |
47
|
|
|
$this->myStart = new \DateTime($this->dbData['startTime']); |
48
|
|
|
} |
49
|
|
|
return $this->myStart; |
50
|
|
|
case 'startTimeWithMod': |
51
|
|
|
if($this->modStart === null) |
52
|
|
|
{ |
53
|
|
|
$this->modStart = clone $this->startTime; |
54
|
|
|
$this->modStart->sub($this->modTime); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
return $this->modStart; |
57
|
|
|
case 'endTime': |
58
|
|
|
if($this->myEnd === null) |
59
|
|
|
{ |
60
|
|
|
$this->myEnd = new \DateTime($this->dbData['endTime']); |
61
|
|
|
} |
62
|
|
|
return $this->myEnd; |
63
|
|
|
case 'endTimeWithMod': |
64
|
|
|
if($this->modEnd === null) |
65
|
|
|
{ |
66
|
|
|
$this->modEnd = clone $this->endTime; |
67
|
|
|
$this->modEnd->add($this->modTime); |
68
|
|
|
} |
69
|
|
|
return $this->modEnd; |
70
|
|
|
case 'department': |
71
|
|
|
if(!isset(self::$deptCache[$this->dbData['departmentID']])) |
72
|
|
|
{ |
73
|
|
|
self::$deptCache[$this->dbData['departmentID']] = new \VolunteerDepartment($this->dbData['departmentID']); |
74
|
|
|
} |
75
|
|
|
return self::$deptCache[$this->dbData['departmentID']]; |
76
|
|
|
case 'role': |
77
|
|
|
if(!isset(self::$roleCache[$this->dbData['roleID']])) |
78
|
|
|
{ |
79
|
|
|
self::$roleCache[$this->dbData['roleID']] = new \VolunteerRole($this->dbData['roleID']); |
80
|
|
|
} |
81
|
|
|
return self::$roleCache[$this->dbData['roleID']]; |
82
|
|
|
case 'event': |
83
|
|
|
if(!isset(self::$eventCache[$this->dbData['eventID']])) |
84
|
|
|
{ |
85
|
|
|
self::$eventCache[$this->dbData['eventID']] = new \VolunteerEvent($this->dbData['eventID']); |
86
|
|
|
} |
87
|
|
|
return self::$eventCache[$this->dbData['eventID']]; |
88
|
|
|
case 'participantObj': |
89
|
|
|
if($this->participantObj === null) |
90
|
|
|
{ |
91
|
|
|
if(isset($this->dbData['participant']) && $this->dbData['participant'] !== '' && $this->dbData['participant'] !== '/dev/null') |
92
|
|
|
{ |
93
|
|
|
$this->participantObj = new \VolunteerProfile($this->dbData['participant']); |
94
|
|
|
} |
95
|
|
|
else |
96
|
|
|
{ |
97
|
|
|
$this->participantObj = false; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
return $this->participantObj; |
101
|
|
|
case 'webParticipantName': |
102
|
|
|
if($this->webParticipantName === null) |
103
|
|
|
{ |
104
|
|
|
if(isset($this->dbData['participant'])) |
105
|
|
|
{ |
106
|
|
|
$tmp = new \VolunteerProfile($this->dbData['participant']); |
107
|
|
|
$this->webParticipantName = $tmp->getDisplayName(); |
108
|
|
|
} |
109
|
|
|
else |
110
|
|
|
{ |
111
|
|
|
$this->webParticipantName = ""; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
return $this->webParticipantName; |
115
|
|
|
case 'scheduleParticipantName': |
116
|
|
|
if($this->scheduleParticipantName === null) |
117
|
|
|
{ |
118
|
|
|
if(isset($this->dbData['participant'])) |
119
|
|
|
{ |
120
|
|
|
$tmp = new \VolunteerProfile($this->dbData['participant']); |
121
|
|
|
$this->scheduleParticipantName = $tmp->getDisplayName('paperName'); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
else |
124
|
|
|
{ |
125
|
|
|
$this->scheduleParticipantName = ""; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
return $this->scheduleParticipantName; |
129
|
|
|
default: |
130
|
|
|
return $this->dbData[$propName]; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function isSame($shift) |
135
|
|
|
{ |
136
|
|
|
return $this->dbData['_id'] === $shift->dbData['_id']; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function overlaps($shift) |
140
|
|
|
{ |
141
|
|
|
if($this->isSame($shift)) |
142
|
|
|
{ |
143
|
|
|
return false; |
144
|
|
|
} |
145
|
|
|
if($this->startTimeWithMod > $shift->startTimeWithMod && $this->startTimeWithMod < $shift->endTimeWithMod) |
|
|
|
|
146
|
|
|
{ |
147
|
|
|
return true; |
148
|
|
|
} |
149
|
|
|
if($this->endTimeWithMod < $shift->endTimeWithMod && $this->endTimeWithMod > $shift->startTimeWithMod) |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
return true; |
152
|
|
|
} |
153
|
|
|
return false; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function isFilled() |
157
|
|
|
{ |
158
|
|
|
return isset($this->dbData['status']) && ($this->dbData['status'] === 'pending' || $this->dbData['status'] === 'filled' || $this->dbData['status'] === 'groupPending'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function findOverlaps($uid, $shortCircuit = false) |
162
|
|
|
{ |
163
|
|
|
static $userShifts = null; |
164
|
|
|
static $count = 0; |
165
|
|
|
if($userShifts === null) |
166
|
|
|
{ |
167
|
|
|
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts'); |
168
|
|
|
$filter = new \Data\Filter("participant eq '$uid'"); |
169
|
|
|
$userShifts = $dataTable->read($filter); |
170
|
|
|
$count = count($userShifts); |
|
|
|
|
171
|
|
|
for($i = 0; $i < $count; $i++) |
172
|
|
|
{ |
173
|
|
|
$userShifts[$i] = new VolunteerShift(false, $userShifts[$i]); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
$res = array(); |
177
|
|
|
for($i = 0; $i < $count; $i++) |
178
|
|
|
{ |
179
|
|
|
if($this->overlaps($userShifts[$i])) |
180
|
|
|
{ |
181
|
|
|
if($shortCircuit === true) |
182
|
|
|
{ |
183
|
|
|
return true; |
184
|
|
|
} |
185
|
|
|
array_push($res, $userShifts[$i]); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
if($shortCircuit === true) |
189
|
|
|
{ |
190
|
|
|
return false; |
191
|
|
|
} |
192
|
|
|
return $res; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function makeCopy($dataTable) |
196
|
|
|
{ |
197
|
|
|
$tmp = $this->dbData; |
198
|
|
|
unset($tmp['_id']); |
199
|
|
|
$dataTable->create($tmp); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
203
|
|
|
|