-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpatieCalendarLinksAdapter.php
30 lines (26 loc) · 1.11 KB
/
SpatieCalendarLinksAdapter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
// Requires Spatie/CalendarLinks 'https://github.com/spatie/calendar-links'
use Spatie\CalendarLinks\Link;
use DateTime;
use DateTimeZone;
class SpatieCalendarLinksAdapter
{
/**
* Generate calendar links based on given data
*
* @param object
* { from : ..., to : ..., title: ..., description: ..., timezone : ..., address: ..., }
* @return object
* { 'google':..., 'yahoo':..., 'webOutlook':..., 'ics':..., }
*/
public static function create(object $obj) : object
{
$from = DateTime::createFromFormat('Y-m-d H:i', $obj->from ?? '', isset($obj->timezone) ? new DateTimeZone($obj->timezone) : null);
$to = DateTime::createFromFormat('Y-m-d H:i', $obj->to ?? '', isset($obj->timezone) ? new DateTimeZone($obj->timezone) : null);
$link = Link::create($obj->title ?? '', $from, $to)
->description($obj->description ?? '')
->address($obj->address ?? '');
// Generate a link for each calendar platform available
return (object)['google' => $link->google(), 'yahoo' => $link->yahoo(), 'webOutlook' => $link->webOutlook(), 'ics' => $link->ics()];
}
}