Skip to content

Commit f0986dd

Browse files
authored
Create Events.php
1 parent 3dbeb32 commit f0986dd

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

src/AdminResources/Events.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace Dcblogdev\MsGraph\AdminResources;
4+
5+
use Dcblogdev\MsGraph\Facades\MsGraphAdmin;
6+
7+
class Events 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($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/events?$params");
52+
53+
$data = MsGraphAdmin::getPagination($events, $top, $skip);
54+
55+
return [
56+
'events' => $events,
57+
'total' => $data['total'],
58+
'top' => $data['top'],
59+
'skip' => $data['skip'],
60+
];
61+
}
62+
63+
public function find($id)
64+
{
65+
if ($this->userId == null) {
66+
throw new Exception("userId is required.");
67+
}
68+
69+
return MsGraphAdmin::get("users/$this->userId/events/$id");
70+
}
71+
72+
public function store(array $data)
73+
{
74+
if ($this->userId == null) {
75+
throw new Exception("userId is required.");
76+
}
77+
78+
return MsGraphAdmin::post("users/$this->userId/events", $data);
79+
}
80+
81+
public function update($id, array $data)
82+
{
83+
if ($this->userId == null) {
84+
throw new Exception("userId is required.");
85+
}
86+
87+
return MsGraphAdmin::patch("users/$this->userId/events/$id", $data);
88+
}
89+
90+
public function delete($id)
91+
{
92+
if ($this->userId == null) {
93+
throw new Exception("userId is required.");
94+
}
95+
96+
return MsGraphAdmin::delete("users/$this->userId/events/$id");
97+
}
98+
}

0 commit comments

Comments
 (0)