Merge pull request #199 from jmowatt/feature/ics-on-confirmation

Add user importable calendar to email
This commit is contained in:
Dave Earley 2016-09-15 17:13:35 +01:00 committed by GitHub
commit 52b29fe071
4 changed files with 46 additions and 1 deletions

View File

@ -124,4 +124,16 @@ class EventViewController extends Controller
'message' => 'Message Successfully Sent',
]);
}
public function showCalendarIcs(Request $request, $event_id)
{
$event = Event::findOrFail($event_id);
$icsContent = $event->getIcsForEvent();
return response()->make($icsContent, 200, [
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="event.ics'
]);
}
}

View File

@ -116,6 +116,11 @@ Route::group(['prefix' => 'e'], function () {
'uses' => 'EventViewEmbeddedController@showEmbeddedEvent',
]);
Route::get('/{event_id}/calendar.ics', [
'as' => 'downloadCalendarIcs',
'uses' => 'EventViewController@showCalendarIcs',
]);
Route::get('/{event_id}/{event_slug?}', [
'as' => 'showEventPage',
'uses' => 'EventViewController@showEventHome',

View File

@ -331,4 +331,32 @@ class Event extends MyBaseModel
{
return ['created_at', 'updated_at', 'start_date', 'end_date'];
}
public function getIcsForEvent()
{
$siteUrl = URL::to('/');
$eventUrl = $this->getEventUrlAttribute();
$start_date = new Carbon($this->start_date);
$end_date = new Carbon($this->end_date);
$timestamp = new Carbon();
$icsTemplate = <<<ICSTemplate
BEGIN:VCALENDAR
VERSION:2.0
PRODID:{$siteUrl}
BEGIN:VEVENT
UID:{$eventUrl}
DTSTAMP:{$timestamp->format('Ymd\THis\Z')}
DTSTART:{$start_date->format('Ymd\THis\Z')}
DTEND:{$end_date->format('Ymd\THis\Z')}
SUMMARY:$this->title
LOCATION:{$this->venue_name}
DESCRIPTION:{$this->description}
END:VEVENT
END:VCALENDAR
ICSTemplate;
return $icsTemplate;
}
}

View File

@ -17,7 +17,7 @@ Order Reference: <b>{{$order->order_reference}}</b><br>
Order Name: <b>{{$order->full_name}}</b><br>
Order Date: <b>{{$order->created_at->toDayDateTimeString()}}</b><br>
Order Email: <b>{{$order->email}}</b><br>
<a href="{!! route('downloadCalendarIcs', ['event_id' => $order->event->id]) !!}">Add To Calendar</a>
<h3>Order Items</h3>
<div style="padding:10px; background: #F9F9F9; border: 1px solid #f1f1f1;">
<table style="width:100%; margin:10px;">