|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LeandroFerreiraMa\GoogleCalendar; |
|
4
|
|
|
|
|
5
|
|
|
use DateInterval; |
|
6
|
|
|
use DateTime; |
|
7
|
|
|
|
|
8
|
|
|
class Schedule extends GoogleCalendar |
|
9
|
|
|
{ |
|
10
|
|
|
public function __construct(string $token) |
|
11
|
|
|
{ |
|
12
|
|
|
parent::__construct($token); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function read(?array $headers, ?string $syncToken, ?DateTime $startDate = null): Schedule |
|
16
|
|
|
{ |
|
17
|
|
|
$url_parameters = array(); |
|
18
|
|
|
|
|
19
|
|
|
if(!empty($syncToken)){ |
|
20
|
|
|
$url_parameters['syncToken'] = strip_tags($syncToken); |
|
21
|
|
|
} else { |
|
22
|
|
|
if(is_null($startDate)){ |
|
|
|
|
|
|
23
|
|
|
$startDate = new DateTime('now'); |
|
24
|
|
|
$interval = new DateInterval("P1D"); |
|
25
|
|
|
$startDate->sub($interval); |
|
26
|
|
|
} |
|
27
|
|
|
$url_parameters['timeMin'] = $startDate->format(DATE_W3C); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$this->request( |
|
31
|
|
|
"GET", |
|
32
|
|
|
"v3/calendars/primary/events?". http_build_query($url_parameters), |
|
|
|
|
|
|
33
|
|
|
null, |
|
34
|
|
|
$headers |
|
35
|
|
|
); |
|
36
|
|
|
return $this; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function create(string $summary, DateTime $start, DateTime $end,?string $description = null, ?string $location = null, ?string $calendaId = 'primary', ?array $attendees = []): Schedule |
|
40
|
|
|
{ |
|
41
|
|
|
$schedule = [ |
|
42
|
|
|
"summary" => $summary, |
|
43
|
|
|
"description" => $description, |
|
44
|
|
|
"location" => $location, |
|
45
|
|
|
"start" => array('dateTime' => $start->format(DATE_RFC3339)), |
|
46
|
|
|
"end" => array('dateTime' => $end->format(DATE_RFC3339)), |
|
47
|
|
|
"attendees" => $attendees |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
$this->request( |
|
51
|
|
|
"POST", |
|
52
|
|
|
"v3/calendars/{$calendaId}/events", |
|
53
|
|
|
$schedule, |
|
54
|
|
|
["Content-Type" => "application/json"] |
|
55
|
|
|
); |
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function update(string $eventId, string $summary, DateTime $start, DateTime $end,?string $description = null, ?string $location = null, ?string $calendaId = 'primary', string $status = 'confirmed', ?array $attendees = []): Schedule |
|
60
|
|
|
{ |
|
61
|
|
|
$schedule = [ |
|
62
|
|
|
"summary" => $summary, |
|
63
|
|
|
"description" => $description, |
|
64
|
|
|
"location" => $location, |
|
65
|
|
|
"status" => $status, |
|
66
|
|
|
"start" => array('dateTime' => $start->format(DATE_RFC3339)), |
|
67
|
|
|
"end" => array('dateTime' => $end->format(DATE_RFC3339)), |
|
68
|
|
|
"attendees" => $attendees |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
$this->request( |
|
72
|
|
|
"PUT", |
|
73
|
|
|
"v3/calendars/{$calendaId}/events/{$eventId}", |
|
74
|
|
|
$schedule, |
|
75
|
|
|
["Content-Type" => "application/json"] |
|
76
|
|
|
); |
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function delete(string $eventId, ?string $calendaId = 'primary'): Schedule |
|
81
|
|
|
{ |
|
82
|
|
|
$this->request( |
|
83
|
|
|
"DELETE", |
|
84
|
|
|
"v3/calendars/{$calendaId}/events/{$eventId}", |
|
85
|
|
|
null, |
|
86
|
|
|
["Content-Type" => "application/json"] |
|
87
|
|
|
); |
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|