|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017, Georg Ehrke |
|
4
|
|
|
* |
|
5
|
|
|
* @author Georg Ehrke <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license AGPL-3.0 |
|
8
|
|
|
* |
|
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
11
|
|
|
* as published by the Free Software Foundation. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
namespace OCA\DAV\CalDAV; |
|
23
|
|
|
|
|
24
|
|
|
use Sabre\DAV\Exception\NotFound; |
|
25
|
|
|
|
|
26
|
|
|
class PublicCalendar extends Calendar { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $name |
|
30
|
|
|
* @throws NotFound |
|
31
|
|
|
* @return PublicCalendarObject |
|
32
|
|
|
*/ |
|
33
|
|
View Code Duplication |
public function getChild($name) { |
|
|
|
|
|
|
34
|
|
|
$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
35
|
|
|
|
|
36
|
|
|
if (!$obj) { |
|
37
|
|
|
throw new NotFound('Calendar object not found'); |
|
38
|
|
|
} |
|
39
|
|
|
if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
40
|
|
|
throw new NotFound('Calendar object not found'); |
|
41
|
|
|
} |
|
42
|
|
|
$obj['acl'] = $this->getChildACL(); |
|
43
|
|
|
|
|
44
|
|
|
return new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return PublicCalendarObject[] |
|
49
|
|
|
*/ |
|
50
|
|
View Code Duplication |
public function getChildren() { |
|
|
|
|
|
|
51
|
|
|
$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
52
|
|
|
$children = []; |
|
53
|
|
|
foreach ($objs as $obj) { |
|
54
|
|
|
if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
55
|
|
|
continue; |
|
56
|
|
|
} |
|
57
|
|
|
$obj['acl'] = $this->getChildACL(); |
|
58
|
|
|
$children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
59
|
|
|
} |
|
60
|
|
|
return $children; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string[] $paths |
|
65
|
|
|
* @return PublicCalendarObject[] |
|
66
|
|
|
*/ |
|
67
|
|
View Code Duplication |
public function getMultipleChildren(array $paths) { |
|
|
|
|
|
|
68
|
|
|
$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
69
|
|
|
$children = []; |
|
70
|
|
|
foreach ($objs as $obj) { |
|
71
|
|
|
if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
72
|
|
|
continue; |
|
73
|
|
|
} |
|
74
|
|
|
$obj['acl'] = $this->getChildACL(); |
|
75
|
|
|
$children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
76
|
|
|
} |
|
77
|
|
|
return $children; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* public calendars are always shared |
|
82
|
|
|
* @return bool |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function isShared() { |
|
85
|
|
|
return true; |
|
86
|
|
|
} |
|
87
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.