-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathCalendarEvents.php
99 lines (77 loc) · 2.32 KB
/
CalendarEvents.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
<?php
namespace Dcblogdev\MsGraph\AdminResources;
use Dcblogdev\MsGraph\Facades\MsGraphAdmin;
use Exception;
class CalendarEvents extends MsGraphAdmin
{
private string $userId = '';
private string $top = '100';
private string $skip = '0';
public function userid(string $userId): static
{
$this->userId = $userId;
return $this;
}
public function top(string $top): static
{
$this->top = $top;
return $this;
}
public function skip(string $skip): static
{
$this->skip = $skip;
return $this;
}
/**
* @throws Exception
*/
public function get(string $calendarId, array $params = []): array
{
if ($this->userId === '') {
throw new Exception('userId is required.');
}
$top = request('top', $this->top);
$skip = request('skip', $this->skip);
if ($params == []) {
$params = http_build_query([
'$orderby' => 'subject',
'$top' => $top,
'$skip' => $skip,
'$count' => 'true',
]);
} else {
$params = http_build_query($params);
}
$events = MsGraphAdmin::get("users/$this->userId/calendars/$calendarId/events?$params");
if (isset($events->error)) {
throw new Exception("Graph API Error, code: {$events->error->code}, Message: {$events->error->message}");
}
$data = MsGraphAdmin::getPagination($events, $top, $skip);
return [
'events' => $events,
'total' => $data['total'],
'top' => $data['top'],
'skip' => $data['skip'],
];
}
/**
* @throws Exception
*/
public function find(string $calendarId, string $eventId): MsGraphAdmin
{
if ($this->userId === '') {
throw new Exception('userId is required.');
}
return MsGraphAdmin::get("users/$this->userId/calendars/$calendarId/events/$eventId");
}
/**
* @throws Exception
*/
public function store(string $calendarId, array $data): MsGraphAdmin
{
if ($this->userId === '') {
throw new Exception('userId is required.');
}
return MsGraphAdmin::post("users/$this->userId/calendars/$calendarId/events", $data);
}
}