/** * Generates and returns an iCal file for a ticket. * @param String $code Code of a ticket in the system. * @return .ics file iCal file representing that ticket. */ public function iCal($code) { $vCalendar = new Calendar($_SERVER["HTTP_HOST"]); try { $ticket = Ticket::hasCode($code)->firstOrFail(); } catch (ModelNotFoundException $e) { return view("tickets.unverifiable", ['error' => $this->errorMessages['ticket_invalid']]); } $event = $ticket->event; // Have to call Event this way to avoid clash with App\Event $vEvent = new iCal\Component\Event(); $breakAddress = explode(",", $event->location->name, 2); $firstName = $breakAddress[0]; $vEvent->setDtStart(new DateTime($event->start_datetime))->setDtEnd(new DateTime($event->end_datetime))->setLocation($event->location->name, $firstName, "{$event->location->latitude}, {$event->location->longitude}")->setSummary($event->title); $vCalendar->addComponent($vEvent); header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); echo $vCalendar->render(); }