Skip to content

Commit 0a6a42c

Browse files
authored
Create CalendarEvents.php
1 parent 82e74bf commit 0a6a42c

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

src/AdminResources/CalendarEvents.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Dcblogdev\MsGraph\AdminResources;
4+
5+
use Dcblogdev\MsGraph\Facades\MsGraphAdmin;
6+
7+
class CalendarEvents extends MsGraphAdmin
8+
{
9+
private $userId;
10+
private $top;
11+
private $skip;
12+
13+
public function userid($userId)
14+
{
15+
$this->userId = $userId;
16+
return $this;
17+
}
18+
19+
public function top($top)
20+
{
21+
$this->top = $top;
22+
return $this;
23+
}
24+
25+
public function skip($skip)
26+
{
27+
$this->skip = $skip;
28+
return $this;
29+
}
30+
31+
public function get($calendarId, $params = [])
32+
{
33+
if ($this->userId == null) {
34+
throw new Exception("userId is required.");
35+
}
36+
37+
$top = request('top', $this->top);
38+
$skip = request('skip', $this->skip);
39+
40+
if ($params == []) {
41+
$params = http_build_query([
42+
"\$orderby" => "subject",
43+
"\$top" => $top,
44+
"\$skip" => $skip,
45+
"\$count" => "true",
46+
]);
47+
} else {
48+
$params = http_build_query($params);
49+
}
50+
51+
$events = MsGraphAdmin::get("users/$this->userId/calendars/$calendarId/events?$params");
52+
$data = MsGraphAdmin::getPagination($events, $top, $skip);
53+
54+
return [
55+
'events' => $events,
56+
'total' => $data['total'],
57+
'top' => $data['top'],
58+
'skip' => $data['skip'],
59+
];
60+
}
61+
62+
public function find($calendarId, $eventId)
63+
{
64+
if ($this->userId == null) {
65+
throw new Exception("userId is required.");
66+
}
67+
68+
return MsGraphAdmin::get("users/$this->userId/calendars/$calendarId/events/$eventId");
69+
}
70+
71+
public function store($calendarId, $data)
72+
{
73+
if ($this->userId == null) {
74+
throw new Exception("userId is required.");
75+
}
76+
77+
return MsGraphAdmin::post("users/$this->userId/calendars/$calendarId/events", $data);
78+
}
79+
}

0 commit comments

Comments
 (0)