1 | <?php |
||
60 | class Attendee extends DataObject |
||
61 | { |
||
62 | /** |
||
63 | * Set this to true when you want to have a QR code that opens the check in page and validates the code. |
||
64 | * The validation is only done with proper authorisation so guest cannot check themselves in by mistake. |
||
65 | * By default only the ticket number is translated to an QR code. (for use with USB QR scanners) |
||
66 | * |
||
67 | * @var bool |
||
68 | */ |
||
69 | private static $qr_as_link = false; |
||
1 ignored issue
–
show
|
|||
70 | |||
71 | private static $default_fields = array( |
||
1 ignored issue
–
show
|
|||
72 | 'FirstName' => array( |
||
73 | 'Title' => 'First name', |
||
74 | 'FieldType' => 'UserTextField', |
||
75 | 'Required' => true, |
||
76 | 'Editable' => false |
||
77 | ), |
||
78 | 'Surname' => array( |
||
79 | 'Title' => 'Surname', |
||
80 | 'FieldType' => 'UserTextField', |
||
81 | 'Required' => true, |
||
82 | 'Editable' => false |
||
83 | ), |
||
84 | 'Email' => array( |
||
85 | 'Title' => 'Email', |
||
86 | 'FieldType' => 'UserEmailField', |
||
87 | 'Required' => true, |
||
88 | 'Editable' => false |
||
89 | ) |
||
90 | ); |
||
91 | |||
92 | private static $table_fields = array( |
||
1 ignored issue
–
show
|
|||
93 | 'Title', |
||
94 | 'Email' |
||
95 | ); |
||
96 | |||
97 | private static $db = array( |
||
2 ignored issues
–
show
|
|||
98 | 'Title' => 'Varchar(255)', |
||
99 | 'TicketReceiver' => 'Boolean', |
||
100 | 'TicketCode' => 'Varchar(255)', |
||
101 | 'CheckedIn' => 'Boolean' |
||
102 | ); |
||
103 | |||
104 | private static $indexes = array( |
||
105 | 'TicketCode' => 'unique("TicketCode")' |
||
106 | ); |
||
107 | |||
108 | private static $has_one = array( |
||
2 ignored issues
–
show
|
|||
109 | 'Reservation' => 'Broarm\EventTickets\Reservation', |
||
110 | 'Ticket' => 'Broarm\EventTickets\Ticket', |
||
111 | 'Event' => 'CalendarEvent', |
||
112 | 'Member' => 'Member', |
||
113 | 'TicketQRCode' => 'Image', |
||
114 | 'TicketFile' => 'File' |
||
115 | ); |
||
116 | |||
117 | private static $many_many = array( |
||
2 ignored issues
–
show
|
|||
118 | 'Fields' => 'Broarm\EventTickets\UserField' |
||
119 | ); |
||
120 | |||
121 | private static $many_many_extraFields = array( |
||
2 ignored issues
–
show
|
|||
122 | 'Fields' => array( |
||
123 | 'Value' => 'Varchar(255)' |
||
124 | ) |
||
125 | ); |
||
126 | |||
127 | private static $summary_fields = array( |
||
2 ignored issues
–
show
|
|||
128 | 'Title' => 'Name', |
||
129 | 'Ticket.Title' => 'Ticket', |
||
130 | 'TicketCode' => 'Ticket #', |
||
131 | 'CheckedIn.Nice' => 'Checked in', |
||
132 | ); |
||
133 | |||
134 | public function getCMSFields() |
||
135 | { |
||
136 | $fields = new FieldList(new TabSet('Root', $mainTab = new Tab('Main'))); |
||
137 | |||
138 | $fields->addFieldsToTab('Root.Main', array( |
||
139 | ReadonlyField::create('TicketCode', _t('Attendee.Ticket', 'Ticket')), |
||
140 | ReadonlyField::create('MyCheckedIn', _t('Attendee.CheckedIn', 'Checked in'), $this->dbObject('CheckedIn')->Nice()) |
||
141 | )); |
||
142 | |||
143 | foreach ($this->Fields() as $field) { |
||
144 | $fields->addFieldToTab( |
||
145 | 'Root.Main', |
||
146 | ReadonlyField::create("{$field->Name}_Preview", $field->Title, $field->getValue()) |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | if ($this->TicketFile()->exists()) { |
||
151 | $fields->addFieldToTab('Root.Main', $reservationFileField = ReadonlyField::create( |
||
152 | 'ReservationFile', |
||
153 | _t('Attendee.Reservation', 'Reservation'), |
||
154 | "<a class='readonly' href='{$this->TicketFile()->Link()}' target='_blank'>Download reservation PDF</a>" |
||
155 | )); |
||
156 | $reservationFileField->dontEscape = true; |
||
157 | } |
||
158 | |||
159 | $this->extend('updateCMSFields', $fields); |
||
160 | return $fields; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Utility method for fetching the default field, FirstName, value |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getFirstName() |
||
169 | { |
||
170 | if ($firstName = $this->Fields()->find('Name', 'FirstName')) { |
||
171 | return (string)$firstName->getField('Value'); |
||
172 | } |
||
173 | |||
174 | return null; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Utility method for fetching the default field, Surname, value |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getSurname() |
||
183 | { |
||
184 | if ($surname = $this->Fields()->find('Name', 'Surname')) { |
||
185 | return (string)$surname->getField('Value'); |
||
186 | } |
||
187 | |||
188 | return null; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Get the combined first and last nave for display on the ticket and attendee list |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getName() |
||
197 | { |
||
198 | $mainContact = $this->Reservation()->MainContact(); |
||
199 | if (!empty($this->getSurname())) { |
||
200 | return trim("{$this->getFirstName()} {$this->getSurname()}"); |
||
201 | } elseif ($mainContact->exists() && !empty($mainContact->getSurname())) { |
||
202 | return _t('Attendee.GUEST_OF', 'Guest of {name}', null, array('name' => $mainContact->getName())); |
||
203 | } else { |
||
204 | return null; |
||
205 | } |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Utility method for fetching the default field, Email, value |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getEmail() |
||
214 | { |
||
215 | if ($email = $this->Fields()->find('Name', 'Email')) { |
||
216 | return (string)$email->getField('Value'); |
||
217 | } |
||
218 | |||
219 | return null; |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * Set the title and ticket code before writing |
||
224 | */ |
||
225 | public function onBeforeWrite() |
||
226 | { |
||
227 | // Set the title of the attendee |
||
228 | $this->Title = $this->getName(); |
||
229 | |||
230 | // Generate the ticket code |
||
231 | if ($this->exists() && empty($this->TicketCode)) { |
||
232 | $this->TicketCode = $this->generateTicketCode(); |
||
233 | } |
||
234 | |||
235 | parent::onBeforeWrite(); |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Delete any stray files before deleting the object |
||
240 | */ |
||
241 | public function onBeforeDelete() |
||
242 | { |
||
243 | // If an attendee is deleted from the guest list remove it's qr code |
||
244 | // after deleting the code it's not validatable anymore, simply here for cleanup |
||
245 | if ($this->TicketQRCode()->exists()) { |
||
246 | $this->TicketQRCode()->delete(); |
||
247 | } |
||
248 | |||
249 | // cleanup the ticket file |
||
250 | if ($this->TicketFile()->exists()) { |
||
251 | $this->TicketFile()->delete(); |
||
252 | } |
||
253 | |||
254 | parent::onBeforeDelete(); |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * Get the table fields for this attendee |
||
259 | * |
||
260 | * @return ArrayList |
||
261 | */ |
||
262 | public function getTableFields() |
||
263 | { |
||
264 | $fields = new ArrayList(); |
||
265 | foreach (self::config()->get('table_fields') as $field) { |
||
266 | $data = new ViewableData(); |
||
267 | $data->Header = _t("Attendee.$field", $field); |
||
268 | $data->Value = $this->$field; |
||
269 | $fields->add($data); |
||
270 | } |
||
271 | return $fields; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Get the unnamespaced singular name for display in the CMS |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | public function singular_name() |
||
280 | { |
||
281 | $name = explode('\\', parent::singular_name()); |
||
282 | return trim(end($name)); |
||
283 | } |
||
284 | |||
285 | /** |
||
286 | * Generate a unique ticket id |
||
287 | * Serves as the base for the QR code and ticket file |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | public function generateTicketCode() |
||
295 | |||
296 | /** |
||
297 | * Create a QRCode for the attendee based on the Ticket code |
||
298 | * |
||
299 | * @param Folder $folder |
||
300 | * |
||
301 | * @return Image |
||
302 | */ |
||
303 | public function createQRCode(Folder $folder) |
||
335 | |||
336 | /** |
||
337 | * Creates a printable ticket for the attendee |
||
338 | * |
||
339 | * @param Folder $folder |
||
340 | * |
||
341 | * @return File |
||
342 | */ |
||
343 | public function createTicketFile(Folder $folder) |
||
378 | |||
379 | /** |
||
380 | * Get the checkin link |
||
381 | * |
||
382 | * @return string |
||
383 | */ |
||
384 | public function getCheckInLink() |
||
385 | { |
||
386 | return $this->Event()->Link("checkin/{$this->TicketCode}"); |
||
387 | } |
||
388 | |||
389 | /** |
||
390 | * Check the attendee out |
||
391 | */ |
||
392 | public function checkIn() { |
||
396 | |||
397 | /** |
||
398 | * Check the attendee in |
||
399 | */ |
||
400 | public function checkOut() { |
||
404 | |||
405 | public function canView($member = null) |
||
409 | |||
410 | public function canEdit($member = null) |
||
414 | |||
415 | public function canDelete($member = null) |
||
419 | |||
420 | public function canCreate($member = null) |
||
424 | } |
||
425 |
This check marks private properties in classes that are never used. Those properties can be removed.