Skip to content

Commit 3dbeb32

Browse files
authored
Create Calendars.php
1 parent 0a6a42c commit 3dbeb32

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

src/AdminResources/Calendars.php

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

0 commit comments

Comments
 (0)