-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoint.php
More file actions
executable file
·108 lines (91 loc) · 2.63 KB
/
Copy pathendpoint.php
File metadata and controls
executable file
·108 lines (91 loc) · 2.63 KB
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
<?php
require_once('api.php');
use \StopLight\EventList;
use \StopLight\Settings;
use Phpfastcache\Helper\Psr16Adapter;
$defaultDriver = 'Files';
$cache = new Psr16Adapter($defaultDriver);
$lost_connection = false;
$credentialsPath = __DIR__ . DIRECTORY_SEPARATOR . 'credentials' . DIRECTORY_SEPARATOR . 'credentials.json';
$client = getGoogleClient($credentialsPath);
$settings = new Settings(__DIR__ . '/settings.json');
$calendar = null;
$calendarId = null;
try {
$calendar = new Google\Service\Calendar($client);
} catch (Exception $e) {
$lost_connection = true;
}
$calendarList = get_calendar_list($calendar);
if (!empty($settings->get('calendarId'))) {
$calendarId = $settings->get('calendarId');
} else {
$calendarId = $calendarList[0];
}
if (isset($_GET['c'])) {
$calendarId = $_GET['c'];
}
if (!empty($calendar)) {
$eventList = new EventList(
$calendar,
$settings
);
// Default Event Formatting
$current_event = $eventList->formatNextEvent();
// Working From Home override
if ($eventList->getWorkingFrom() === 'Home' && $settings->get('wfh')) {
$current_event->setClassList('dnd');
$current_event->setStatus('Working Remotely');
$current_event->setSubtitle('');
$current_event->setType('');
}
// Pre/Post Work Day override
$workInProgress = $eventList->workInProgress();
if ($workInProgress !== 0) {
if ($workInProgress > 0) {
// After work day
} else {
// Before work day
}
}
$current_event_format = $current_event->getFormat();
} else {
if ($lost_connection) {
$current_event_format = [
'class' => [
'lostconnection',
'text-bg-secondary',
],
'status' => 'Lost Connection',
'subtitle' => 'Please Reload',
'type' => '',
'event' => []
];
}
}
if (!empty($current_event_format)) {
$response = [
"success" => !$lost_connection,
"calendarId" => $calendarId,
"format" => $current_event_format,
"remaining" => $current_event->minutesUntilMeetingBegins()
];
} else {
$response = [
"success" => false,
"calendarId" => $calendarId,
"format" => [
'class' => [
'lostconnection',
'text-bg-secondary',
],
'status' => 'Error',
'subtitle' => 'Please Reload',
'type' => '',
'event' => []
],
"remaining" => 0
];
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);