This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.php
158 lines (128 loc) · 4.62 KB
/
example.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* FreeBusyCal example script. This file connects to an iCal server, retrieves data and calculates availbility,
* generates and outputs HTML.
*
* @author Martin Porcheron <martin-fbc@porcheron.uk>
* @copyright (c) Martin Porcheron 2017.
* @license MIT Licence
*/
include 'vendor/autoload.php';
use MPorcheron\FreeBusyCal as Fbc;
// Configuration of calendars //////////////////////////////////////////////////////////////////////////////////////////
$exchange = (new Fbc\Calendar())
->setUrl('https://outlook.office365.com/owa/calendar/dadad@example.com/23432rcsdf34fsc/calendar.ics');
$iCloud = (new MPorcheron\FreeBusyCal\CalDAVCalendar())
->setUsername('my.apple.id@me.com')
->setPassword('application-specific-password')
->setPrincipalUrl('https://caldav.icloud.com/123456789876543/principal/');
// Fetch the calendars /////////////////////////////////////////////////////////////////////////////////////////////////
$fbc = (new Fbc\Generator($exchange, $iCloud))
->setDateRange(new \DateTime('Monday this week'), 14, false)
->setTimeRange(9, 17, 60)
->fetchAndParse();
// Output the calendar /////////////////////////////////////////////////////////////////////////////////////////////////
echo <<<HEADER
<html>
<head>
<title>Free/Busy Calendar</title>
<style type="text/css">
table.cal {
border-spacing: .1em;
cursor: default;
width: 100%;
}
.cal th {
background: transparent;
margin-bottom: 1em;
}
.cal td, .cal th {
text-align: center;
width: 9%;
}
.cal td {
padding: .5em 0;
}
.cal div.time {
text-align: right;
padding-right: 15px;
height: 30px;
}
.cal div.date {
height: 30px;
vertical-align: bottom;
}
.cal div.avail {
cursor: default;
display: block;
margin-bottom: 1px;
height: 30px;
padding-top: 3px;
text-align: center;
}
.cal td.avail span {
color: #FFFFFF;
opacity: 0;
-webkit-transition: opacity .2s ease-in-out;
-moz-transition: opacity .2s ease-in-out;
-o-transition: opacity .2s ease-in-out;
-ms-transition: opacity. 2s ease-in-out;
transition: opacity .2s ease-in-out;
}
.cal td.avail:hover span {
opacity: 1;
}
.cal .avail.busy {
background: #AA6786;
}
.cal .avail.free {
background: #71B075;
}
</style>
<!-- Free/Busy Calendar by Martin Porcheron <martin-fbc@porcheron.uk> -->
</head>
<body>
HEADER;
echo $fbc->generate(function (Fbc\FreeBusyCalendar &$cal) {
// Show time range, or just start time
$showRange = true;
$output = '<table class="cal">';
// Output table headers with days
$output .= '<tr><th></th>';
$days = [ 'S', 'M', 'T', 'W', 'T', 'F', 'S' ];
foreach ($cal->getCalendarDates(Fbc\FreeBusyCalendar::DATE_FORMAT) as $label => &$dt) {
$output .= '<th class="day">'. $days[$dt->format('N')] .'</th>';
}
$output .= '</tr>';
// Output table headers with dates
$output .= '<tr><th></th>';
foreach ($cal->getCalendarDates(Fbc\FreeBusyCalendar::DATE_FORMAT) as $label => &$dt) {
$output .= '<th class="date">'. $label .'</th>';
}
$output .= '</tr>';
// Iterate through each time and $output .= the availability
$times = $cal->getCalendarTimes(Fbc\FreeBusyCalendar::TIME_FORMAT);
foreach ($times as $hour => $temp) {
foreach ($temp as $minute => $labels) {
$output .= '<tr><td class="time">'. $labels[0];
if ($showRange) {
$output .= ' – ' . $labels[1];
}
$output .= '</td>';
foreach ($cal->getCalendarDates(Fbc\FreeBusyCalendar::DATE_FORMAT) as $dt) {
if ($cal->isFree($dt->format('Y-m-d'), $hour, $minute)) {
$output .= '<td class="avail free">Free</td>';
} else {
$output .= '<td class="avail busy">Busy</td>';
}
}
}
$output .= '</td>';
}
$output .= '</table>';
return $output;
});
echo <<<FOOTER
</body>
</html>
FOOTER;