forked from legion151/occupySpaceCal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathical.php
45 lines (34 loc) · 1 KB
/
ical.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
$calData = "BEGIN:VCALENDAR\n";
$calData .="VERSION:2.0\n";
foreach(getOccupations() as $event){
$calData.=getICALEntry($event['start'], $event['end'], 'space occupied', '');
}
$calData .="END:VCALENDAR";
print($calData);
function getOccupations(){
$json = file_get_contents("occ.json");
$dec = json_decode($json, true);
$occupations = array();
foreach($dec as $occ){
$st = DateTime::createFromFormat("Y-m-d H:i:s.u", $occ['start']['date']);
$end = DateTime::createFromFormat("Y-m-d H:i:s.u", $occ['end']['date']);
$occupations[] = array(
'start' => $st->format("Ymd\TH0000"),
'end' => $end->format("Ymd\TH0000")
);
}
return $occupations;
}
function getICALEntry($start, $end, $name, $desc)
{
$entry ="BEGIN:VEVENT\n";
$entry .="SUMMARY:".$name."\n";
$entry .="DTSTART;TZID=Europe/Berlin:".$start."\n";
$entry .="DTEND;TZID=Europe/Berlin:".$end."\n";
$entry .="LOCATION:\n";
$entry .="DESCRIPTION:".$desc."\n";
$entry .="END:VEVENT\n";
return $entry;
}
?>