/
Calendar.php
132 lines (110 loc) · 3.98 KB
/
Calendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace gClient\Calendar;
use gClient\Connection;
use gClient\Calendar\Service;
use gClient\Calendar\Meta;
use gClient\Calendar\Builder\SelectEvents;
use gClient\Calendar\Builder\SelectEvents as SelectEventsDefault;
use DateTime;
/**
* A Calendar class represents an individual calendar within Google, containing properties and events
* @property string $unique_id The unique (Google wide) ID of the calendar
* @property Meta\Settings $settings Changeable options pertaining to the calendar
* @property Meta\Properties $properties Read-only attributes associated with the calendar
* @property Meta\Sharing $sharing Manage who has what access to the calendar
* @property Meta\Extensions $extensions User defined properties
*/
class Calendar {
/**
* Service to use to make HTTP calls with
* @var Service
*/
protected $service;
protected $_magic = Array(
'settings' => null
, 'properties' => null
, 'sharing' => null
, 'extensions' => null
, 'unique_id' => null
);
/**
* @internal
* @param Array Data passed by Service
* @param \gClient\ServiceInterface Authenticated account to use or null for an anonymouse (read-only) connection
* @todo Change $catalog_data to mixed - URL to fetch, Array if from Catalog
*/
public function __construct(Array $properties, \gClient\ServiceInterface $service) {
$this->_magic['unique_id'] = substr($properties['id'], strrpos($properties['id'], '/') + 1);
foreach (Array('settings', 'properties') as $attribute) {
$ns = __NAMESPACE__ . '\\Meta\\' . $attribute;
$this->_magic[$attribute] = new $ns($this);
$values = Array();
$required = $this->_magic[$attribute]->getNames();
foreach ($required as $key) {
if (isset($properties[$key])) {
$values[$key] = $properties[$key];
}
}
$this->_magic[$attribute]->softSetValues($values);
}
$this->service = $service;
}
public function __sleep() {
return Array('service', '_magic');
}
/**
* Fetch the scheduled events from this calendar between a specified dates
* @param Builder\SelectEvents|NULL Set the parameters of which events to fetch
* @throws /gClient\HTTP\Exception
* @return \SplFixedArray of Event
*/
public function getEvents(SelectEvents $query = null) {
if ($query === null) {
$query = new SelectEventsDefault();
}
$res = $this->service->prepareCall($this->eventFeedLink)->setMethod('GET')->setParameters($query->params)->request();
$data = json_decode($res->getContent(), true);
if (!isset($data['data']['items'])) {
return new \SplFixedArray(0);
}
$events = new \SplFixedArray(count($data['data']['items']));
foreach ($data['data']['items'] as $i => $edata) {
$events[$i] = new Event($edata, $this);
}
return $events;
}
/**
* @param Builder\NewEvent|Event|string A NewEvent Builder to create a new event,
* an existing Event to duplicate or a string to parse as an event ex. "Squash with Chris tomorrow at noon"
* @return Event
*/
public function createEvent($event) {
}
function quickCreateEvent($string) {
}
function insertEvent(EventBuilder $event) {
}
/**
* @deprecated possibly
*/
public function createAllDayEvent(DateTime $date) {
}
/**
* @param Event|string Event instance or ID of the event to delete from this calendar
* @throws \gClient\HTTP\Exception
*/
public function deleteEvent($event) {
}
public function prepareCall($url) {
return $this->service->prepareCall($url);
}
/**
* @internal
*/
public function &__get($name) {
if (!isset($this->_magic[$name])) {
$this->_magic[$name] = '';
}
return $this->_magic[$name];
}
}