1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright 2020, Georg Ehrke <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Georg Ehrke <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
namespace OCA\Deck\DAV; |
24
|
|
|
|
25
|
|
|
use OCA\Deck\Db\Card; |
26
|
|
|
use OCA\Deck\Service\CardService; |
27
|
|
|
use Sabre\VObject\Component\VCalendar; |
28
|
|
|
|
29
|
|
|
class CalendarObject implements \Sabre\CalDAV\ICalendarObject, \Sabre\DAVACL\IACL { |
30
|
|
|
|
31
|
|
|
/** @var Calendar */ |
32
|
|
|
private $calendar; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $name; |
36
|
|
|
/** |
37
|
|
|
* @var Card |
38
|
|
|
*/ |
39
|
|
|
private $card; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* CalendarObject constructor. |
43
|
|
|
* |
44
|
|
|
* @param Calendar $calendar |
45
|
|
|
* @param string $name |
46
|
|
|
*/ |
47
|
|
|
public function __construct(Calendar $calendar, string $name, Card $card = null) { |
48
|
|
|
$this->calendar = $calendar; |
49
|
|
|
$this->name = $name; |
50
|
|
|
$this->card = $card; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritDoc |
55
|
|
|
*/ |
56
|
|
|
function getOwner() { |
|
|
|
|
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritDoc |
62
|
|
|
*/ |
63
|
|
|
function getGroup() { |
|
|
|
|
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritDoc |
69
|
|
|
*/ |
70
|
|
|
function getACL() { |
|
|
|
|
71
|
|
|
return $this->calendar->getACL(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @inheritDoc |
76
|
|
|
*/ |
77
|
|
|
function setACL(array $acl) { |
|
|
|
|
78
|
|
|
throw new \Sabre\DAV\Exception\Forbidden('Setting ACL is not supported on this node'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritDoc |
83
|
|
|
*/ |
84
|
|
|
function getSupportedPrivilegeSet() { |
|
|
|
|
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @inheritDoc |
90
|
|
|
*/ |
91
|
|
|
function put($data) { |
|
|
|
|
92
|
|
|
throw new \Sabre\DAV\Exception\Forbidden('This calendar-object is read-only'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @inheritDoc |
97
|
|
|
*/ |
98
|
|
|
function get() { |
|
|
|
|
99
|
|
|
if ($this->card) { |
100
|
|
|
return $this->card->getCalendarObject()->serialize(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @inheritDoc |
106
|
|
|
*/ |
107
|
|
|
function getContentType() { |
|
|
|
|
108
|
|
|
return 'text/calendar; charset=utf-8'; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @inheritDoc |
113
|
|
|
*/ |
114
|
|
|
function getETag() { |
|
|
|
|
115
|
|
|
return '"' . md5($this->get()) . '"'; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @inheritDoc |
120
|
|
|
*/ |
121
|
|
|
function getSize() { |
|
|
|
|
122
|
|
|
return strlen($this->get()); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @inheritDoc |
127
|
|
|
*/ |
128
|
|
|
function delete() { |
|
|
|
|
129
|
|
|
throw new \Sabre\DAV\Exception\Forbidden('This calendar-object is read-only'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @inheritDoc |
134
|
|
|
*/ |
135
|
|
|
function getName() { |
|
|
|
|
136
|
|
|
return $this->name; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @inheritDoc |
141
|
|
|
*/ |
142
|
|
|
function setName($name) { |
|
|
|
|
143
|
|
|
throw new \Sabre\DAV\Exception\Forbidden('This calendar-object is read-only'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @inheritDoc |
148
|
|
|
*/ |
149
|
|
|
function getLastModified() { |
|
|
|
|
150
|
|
|
return $this->card->getLastModified(); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.