Skip to content

Commit 88294f3

Browse files
authored
Merge pull request #18 from thursdaydan/master
Added support for calendar and event based API interactions.
2 parents d3a63c8 + f0986dd commit 88294f3

File tree

4 files changed

+291
-0
lines changed

4 files changed

+291
-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+
}

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+
}

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+
}

src/MsGraphAdmin.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616

1717
class MsGraphAdmin
1818
{
19+
public function calendarEvents()
20+
{
21+
return new CalendarEvents();
22+
}
23+
24+
public function calendars()
25+
{
26+
return new Calendars();
27+
}
28+
1929
public function contacts()
2030
{
2131
return new Contacts();
@@ -26,6 +36,16 @@ public function emails()
2636
return new Emails();
2737
}
2838

39+
public function events()
40+
{
41+
return new Events();
42+
}
43+
44+
public function files()
45+
{
46+
return new Files();
47+
}
48+
2949
/**
3050
* Set the base url that all API requests use
3151
* @var string

0 commit comments

Comments
 (0)