Retrieve ICS Content for a event

Add getIcsForEvent() method, this returns an ICS formatted text ready
for download or attaching to emails.
This commit is contained in:
James Mowatt 2016-09-11 16:49:27 +01:00
parent 9d5755beec
commit 9579dfb10c
1 changed files with 28 additions and 0 deletions

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;
}
}