Completed
Push — master ( 6ca8ce...06e969 )
by Lukas
47:33 queued 38:57
created

RootCollection   B

Complexity

Total Complexity 1

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 16

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 8.4614
c 0
b 0
f 0
wmc 1
lcom 0
cbo 16

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 81 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Joas Schilling <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 * @author Vincent Petry <[email protected]>
9
 *
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
namespace OCA\DAV;
26
27
use OCA\DAV\CalDAV\CalDavBackend;
28
use OCA\DAV\CalDAV\CalendarRoot;
29
use OCA\DAV\CalDAV\PublicCalendarRoot;
30
use OCA\DAV\CardDAV\AddressBookRoot;
31
use OCA\DAV\CardDAV\CardDavBackend;
32
use OCA\DAV\Connector\Sabre\Principal;
33
use OCA\DAV\DAV\GroupPrincipalBackend;
34
use OCA\DAV\DAV\SystemPrincipalBackend;
35
use Sabre\CalDAV\Principal\Collection;
36
use Sabre\DAV\SimpleCollection;
37
38
class RootCollection extends SimpleCollection {
39
40
	public function __construct() {
41
		$config = \OC::$server->getConfig();
42
		$random = \OC::$server->getSecureRandom();
43
		$userManager = \OC::$server->getUserManager();
44
		$db = \OC::$server->getDatabaseConnection();
45
		$dispatcher = \OC::$server->getEventDispatcher();
46
		$userPrincipalBackend = new Principal(
47
			$userManager,
48
			\OC::$server->getGroupManager()
49
		);
50
		$groupPrincipalBackend = new GroupPrincipalBackend(
51
			\OC::$server->getGroupManager()
52
		);
53
		// as soon as debug mode is enabled we allow listing of principals
54
		$disableListing = !$config->getSystemValue('debug', false);
55
56
		// setup the first level of the dav tree
57
		$userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
58
		$userPrincipals->disableListing = $disableListing;
59
		$groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
60
		$groupPrincipals->disableListing = $disableListing;
61
		$systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
62
		$systemPrincipals->disableListing = $disableListing;
63
		$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
64
		$filesCollection->disableListing = $disableListing;
65
		$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $config, $random);
66
		$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
67
		$calendarRoot->disableListing = $disableListing;
68
		$publicCalendarRoot = new PublicCalendarRoot($caldavBackend);
69
		$publicCalendarRoot->disableListing = $disableListing;
70
71
		$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
72
			\OC::$server->getSystemTagManager(),
73
			\OC::$server->getUserSession(),
74
			\OC::$server->getGroupManager()
75
		);
76
		$systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
77
			\OC::$server->getSystemTagManager(),
78
			\OC::$server->getSystemTagObjectMapper(),
79
			\OC::$server->getUserSession(),
80
			\OC::$server->getGroupManager(),
81
			\OC::$server->getEventDispatcher()
82
		);
83
		$commentsCollection = new Comments\RootCollection(
84
			\OC::$server->getCommentsManager(),
85
			\OC::$server->getUserManager(),
86
			\OC::$server->getUserSession(),
87
			\OC::$server->getEventDispatcher(),
88
			\OC::$server->getLogger()
89
		);
90
91
		$usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher);
92
		$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
93
		$usersAddressBookRoot->disableListing = $disableListing;
94
95
		$systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher);
96
		$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
97
		$systemAddressBookRoot->disableListing = $disableListing;
98
99
		$uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
100
		$uploadCollection->disableListing = $disableListing;
101
102
		$children = [
103
				new SimpleCollection('principals', [
104
						$userPrincipals,
105
						$groupPrincipals,
106
						$systemPrincipals]),
107
				$filesCollection,
108
				$calendarRoot,
109
				$publicCalendarRoot,
110
				new SimpleCollection('addressbooks', [
111
						$usersAddressBookRoot,
112
						$systemAddressBookRoot]),
113
				$systemTagCollection,
114
				$systemTagRelationsCollection,
115
				$commentsCollection,
116
				$uploadCollection,
117
		];
118
119
		parent::__construct('root', $children);
120
	}
121
122
}
123