|
1
|
|
|
<?php namespace CalDAVClient\Facade\Requests; |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2017 OpenStack Foundation |
|
4
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5
|
|
|
* you may not use this file except in compliance with the License. |
|
6
|
|
|
* You may obtain a copy of the License at |
|
7
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
8
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
9
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
10
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
11
|
|
|
* See the License for the specific language governing permissions and |
|
12
|
|
|
* limitations under the License. |
|
13
|
|
|
**/ |
|
14
|
|
|
use Sabre\Xml\Service; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class CalendarQueryRequest |
|
18
|
|
|
* @package CalDAVClient\Facade\Requests |
|
19
|
|
|
*/ |
|
20
|
|
|
class CalendarQueryRequest implements IAbstractWebDAVRequest |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* CalendarQueryRequest constructor. |
|
25
|
|
|
* @param CalendarQueryFilter $filter |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(CalendarQueryFilter $filter) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->filter = $filter; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var CalendarQueryFilter |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $filter; |
|
36
|
|
|
|
|
37
|
|
|
protected function formatTimestamp($datetime) { |
|
38
|
|
|
// Make a copy of the date, and convert it to GMT to accommodate |
|
39
|
|
|
// CalDAV's date & time formatting requirements |
|
40
|
|
|
$clone = clone $datetime; |
|
41
|
|
|
$clone->setTimezone(new \DateTimeZone("GMT")); |
|
42
|
|
|
|
|
43
|
|
|
return $clone->format('Ymd\THis\Z'); // 'Z' means: GMT time |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getContent() |
|
50
|
|
|
{ |
|
51
|
|
|
$service = new Service(); |
|
52
|
|
|
|
|
53
|
|
|
$service->namespaceMap = [ |
|
54
|
|
|
'DAV:' => 'D', |
|
55
|
|
|
'urn:ietf:params:xml:ns:caldav' => 'C', |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
$filter = []; |
|
59
|
|
|
$props = []; |
|
60
|
|
|
|
|
61
|
|
|
if($this->filter->useGetETags()){ |
|
62
|
|
|
$props['{DAV:}getetag'] = ''; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if($this->filter->useGetCalendarData()){ |
|
66
|
|
|
$props['{urn:ietf:params:xml:ns:caldav}calendar-data'] = ''; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($this->filter->getFrom() || $this->filter->getTo()) { |
|
70
|
|
|
$date_range = []; |
|
71
|
|
|
if ($this->filter->getFrom()) { |
|
72
|
|
|
$date_range['start'] = $this->formatTimestamp($this->filter->getFrom()); |
|
73
|
|
|
} |
|
74
|
|
|
if ($this->filter->getTo()) { |
|
75
|
|
|
$date_range['end'] = $this->formatTimestamp($this->filter->getTo()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$filter[] = [ |
|
79
|
|
|
'name' => '{urn:ietf:params:xml:ns:caldav}comp-filter', |
|
80
|
|
|
'attributes' => ['name' => 'VCALENDAR'], |
|
81
|
|
|
'value' => [ |
|
82
|
|
|
'name' => '{urn:ietf:params:xml:ns:caldav}comp-filter', |
|
83
|
|
|
'attributes' => ['name' => 'VEVENT'], |
|
84
|
|
|
'value' => [ |
|
85
|
|
|
'name' => '{urn:ietf:params:xml:ns:caldav}time-range', |
|
86
|
|
|
'attributes' => $date_range |
|
87
|
|
|
] |
|
88
|
|
|
] |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$nodes = [ |
|
93
|
|
|
'{DAV:}prop' => [ |
|
94
|
|
|
$props |
|
95
|
|
|
], |
|
96
|
|
|
'{urn:ietf:params:xml:ns:caldav}filter' => $filter |
|
97
|
|
|
]; |
|
98
|
|
|
return $service->write('{urn:ietf:params:xml:ns:caldav}calendar-query', $nodes); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|