| 1 | <?php |
||
| 54 | class Reservation extends DataObject |
||
| 55 | { |
||
| 56 | /** |
||
| 57 | * Time to wait before deleting the discarded cart |
||
| 58 | * Give a string that is parsable by strtotime |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | private static $delete_after = '+1 week'; |
||
|
1 ignored issue
–
show
|
|||
| 63 | |||
| 64 | private static $db = array( |
||
|
2 ignored issues
–
show
|
|||
| 65 | 'Status' => 'Enum("CART,PENDING,PAID,CANCELED","CART")', |
||
| 66 | 'Title' => 'Varchar(255)', |
||
| 67 | 'Subtotal' => 'Currency', |
||
| 68 | 'Total' => 'Currency', |
||
| 69 | 'Email' => 'Varchar(255)', |
||
| 70 | 'Gateway' => 'Varchar(255)', |
||
| 71 | 'Comments' => 'Text', |
||
| 72 | 'ReservationCode' => 'Varchar(255)' |
||
| 73 | ); |
||
| 74 | |||
| 75 | private static $has_one = array( |
||
| 76 | 'Event' => 'CalendarEvent', |
||
| 77 | //'TicketFile' => 'File', |
||
| 78 | 'MainContact' => 'Broarm\EventTickets\Attendee' |
||
| 79 | ); |
||
| 80 | |||
| 81 | private static $has_many = array( |
||
|
1 ignored issue
–
show
|
|||
| 82 | 'Payments' => 'Payment', |
||
| 83 | 'Attendees' => 'Broarm\EventTickets\Attendee.Reservation' |
||
| 84 | ); |
||
| 85 | |||
| 86 | private static $belongs_many_many = array( |
||
| 87 | 'PriceModifiers' => 'Broarm\EventTickets\PriceModifier' |
||
| 88 | ); |
||
| 89 | |||
| 90 | private static $indexes = array( |
||
|
2 ignored issues
–
show
|
|||
| 91 | 'ReservationCode' => 'unique("ReservationCode")' |
||
| 92 | ); |
||
| 93 | |||
| 94 | private static $summary_fields = array( |
||
|
1 ignored issue
–
show
|
|||
| 95 | 'Title' => 'Customer', |
||
| 96 | 'Total.Nice' => 'Total', |
||
| 97 | 'State' => 'Status' |
||
| 98 | ); |
||
| 99 | |||
| 100 | public function getCMSFields() |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @deprecated |
||
| 126 | * @return mixed |
||
| 127 | */ |
||
| 128 | public function TicketFile() |
||
| 132 | |||
| 133 | public function onBeforeWrite() |
||
| 145 | |||
| 146 | public function onBeforeDelete() |
||
| 168 | |||
| 169 | public function singular_name() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Check if the cart is still in cart state and the delete_after time period has been exceeded |
||
| 177 | * |
||
| 178 | * @return bool |
||
| 179 | */ |
||
| 180 | public function isDiscarded() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Get the full name |
||
| 188 | * |
||
| 189 | * @return string |
||
| 190 | */ |
||
| 191 | public function getName() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Return the translated state |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | public function getState() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Get the total by querying the sum of attendee ticket prices |
||
| 212 | * |
||
| 213 | * @return float |
||
| 214 | */ |
||
| 215 | public function calculateTotal() |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Safely change to a state |
||
| 234 | * |
||
| 235 | * @param $state |
||
| 236 | */ |
||
| 237 | public function changeState($state) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Set the main contact id |
||
| 249 | * |
||
| 250 | * @param $id |
||
| 251 | */ |
||
| 252 | public function setMainContact($id) { |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Create a reservation code |
||
| 259 | * |
||
| 260 | * @return string |
||
| 261 | */ |
||
| 262 | public function createReservationCode() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Create the folder for the qr code and ticket file |
||
| 269 | * |
||
| 270 | * @return Folder|DataObject|null |
||
| 271 | */ |
||
| 272 | public function fileFolder() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Generate the qr codes and downloadable pdf |
||
| 279 | */ |
||
| 280 | public function createFiles() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Create a Printable ticket file |
||
| 292 | * |
||
| 293 | * @param Folder $folder |
||
| 294 | * |
||
| 295 | * @return File |
||
| 296 | * / |
||
| 297 | private function createTicketFile(Folder $folder) |
||
| 298 | { |
||
| 299 | // Find or make a folder |
||
| 300 | $relativeFilePath = "/{$folder->Filename}{$this->ReservationCode}.pdf"; |
||
| 301 | $absoluteFilePath = Director::baseFolder() . $relativeFilePath; |
||
| 302 | |||
| 303 | if (!$file = File::get()->find('Filename', $relativeFilePath)) { |
||
| 304 | $file = File::create(); |
||
| 305 | $file->ParentID = $folder->ID; |
||
| 306 | $file->OwnerID = (Member::currentUser()) ? Member::currentUser()->ID : 0; |
||
| 307 | $file->Title = $this->ReservationCode; |
||
| 308 | $file->setFilename($relativeFilePath); |
||
| 309 | $file->write(); |
||
| 310 | } |
||
| 311 | |||
| 312 | // Set the template and parse the data |
||
| 313 | $template = new SSViewer('PrintableTicket'); |
||
| 314 | $html = $template->process($this->getViewableData()); |
||
| 315 | |||
| 316 | // Create a DomPDF instance |
||
| 317 | $domPDF = new Dompdf(); |
||
| 318 | $domPDF->loadHtml($html); |
||
| 319 | $domPDF->setPaper('A4'); |
||
| 320 | $domPDF->getOptions()->setDpi(250); |
||
| 321 | $domPDF->render(); |
||
| 322 | |||
| 323 | // Save the pdf stream as a file |
||
| 324 | file_put_contents($absoluteFilePath, $domPDF->output()); |
||
| 325 | |||
| 326 | // Attach the ticket file to the Attendee |
||
| 327 | $this->TicketFileID = $file->ID; |
||
| 328 | $this->write(); |
||
| 329 | |||
| 330 | return $file; |
||
| 331 | }*/ |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Get a viewable data object for this reservation |
||
| 335 | * For use in the Email and print template |
||
| 336 | * @deprecated |
||
| 337 | * @return ViewableData |
||
| 338 | * / |
||
| 339 | public function getViewableData() |
||
| 340 | { |
||
| 341 | $config = SiteConfig::current_site_config(); |
||
| 342 | $data = $this->Me(); |
||
| 343 | $data->CurrentDate = $this->Event()->getController()->CurrentDate(); |
||
| 344 | $data->Logo = $config->TicketLogo(); |
||
| 345 | $this->extend('updateViewableData', $data); |
||
| 346 | return $data; |
||
| 347 | }*/ |
||
| 348 | |||
| 349 | public function canView($member = null) |
||
| 353 | |||
| 354 | public function canEdit($member = null) |
||
| 358 | |||
| 359 | public function canDelete($member = null) |
||
| 363 | |||
| 364 | public function canCreate($member = null) |
||
| 368 | } |
||
| 369 |
This check marks private properties in classes that are never used. Those properties can be removed.