|
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 CalDAVClient\Facade\Utils\ICalTimeZoneBuilder; |
|
15
|
|
|
use Sabre\Xml\Element\Cdata; |
|
16
|
|
|
use Sabre\Xml\Service; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class CalendarCreateRequest |
|
20
|
|
|
* @package CalDAVClient\Facade\Requests |
|
21
|
|
|
*/ |
|
22
|
|
|
final class CalendarCreateRequest implements IAbstractWebDAVRequest |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var MakeCalendarRequestVO |
|
26
|
|
|
*/ |
|
27
|
|
|
private $vo; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* CalendarCreateRequest constructor. |
|
31
|
|
|
* @param MakeCalendarRequestVO $vo |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(MakeCalendarRequestVO $vo) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->vo = $vo; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getContent() |
|
42
|
|
|
{ |
|
43
|
|
|
$service = new Service(); |
|
44
|
|
|
$service->namespaceMap = [ |
|
45
|
|
|
'DAV:' => 'D', |
|
46
|
|
|
'urn:ietf:params:xml:ns:caldav' => 'C', |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
$props = [ |
|
50
|
|
|
[ |
|
51
|
|
|
'name' =>'{DAV:}displayname', |
|
52
|
|
|
'attributes' => ['xml:lang' => 'eng'], |
|
53
|
|
|
'value' => $this->vo->getDisplayName(), |
|
54
|
|
|
], |
|
55
|
|
|
|
|
56
|
|
|
'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => [ |
|
57
|
|
|
[ |
|
58
|
|
|
'name' => '{urn:ietf:params:xml:ns:caldav}comp', |
|
59
|
|
|
'attributes' => ['name' => 'VEVENT'] |
|
60
|
|
|
] |
|
61
|
|
|
], |
|
62
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => new Cdata |
|
63
|
|
|
( |
|
64
|
|
|
ICalTimeZoneBuilder::build |
|
65
|
|
|
( |
|
66
|
|
|
$this->vo->getTimezone(), |
|
67
|
|
|
$this->vo->getDisplayName() |
|
68
|
|
|
)->render() |
|
69
|
|
|
) |
|
70
|
|
|
]; |
|
71
|
|
|
|
|
72
|
|
|
if(!empty($this->vo->getDescription())) |
|
73
|
|
|
$props['{urn:ietf:params:xml:ns:caldav}calendar-description'] = $this->vo->getDescription(); |
|
74
|
|
|
|
|
75
|
|
|
return $service->write('{urn:ietf:params:xml:ns:caldav}mkcalendar', |
|
76
|
|
|
[ |
|
77
|
|
|
'{DAV:}set' => [ |
|
78
|
|
|
'{DAV:}prop' => [ |
|
79
|
|
|
$props |
|
80
|
|
|
] |
|
81
|
|
|
] |
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
} |