2015-11-05 18:46:37 +03:00
|
|
|
<?php
|
2016-01-12 17:02:16 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-01-12 17:02:16 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2015-11-05 18:46:37 +03:00
|
|
|
namespace OCA\DAV\CardDAV;
|
|
|
|
|
2020-02-27 18:54:07 +03:00
|
|
|
use OCA\DAV\AppInfo\PluginManager;
|
2016-09-20 15:15:23 +03:00
|
|
|
|
2015-11-05 18:46:37 +03:00
|
|
|
class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
|
|
|
|
|
2020-02-27 18:54:07 +03:00
|
|
|
/** @var PluginManager */
|
|
|
|
private $pluginManager;
|
2016-09-20 15:15:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
|
|
|
|
* @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
|
|
|
|
* @param string $principalPrefix
|
|
|
|
*/
|
2020-02-27 18:54:07 +03:00
|
|
|
public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend,
|
|
|
|
\Sabre\CardDAV\Backend\BackendInterface $carddavBackend,
|
|
|
|
PluginManager $pluginManager,
|
|
|
|
$principalPrefix = 'principals') {
|
2016-09-20 15:15:23 +03:00
|
|
|
parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
|
2020-02-27 18:54:07 +03:00
|
|
|
$this->pluginManager = $pluginManager;
|
2016-09-20 15:15:23 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 18:46:37 +03:00
|
|
|
/**
|
|
|
|
* This method returns a node for a principal.
|
|
|
|
*
|
|
|
|
* The passed array contains principal information, and is guaranteed to
|
|
|
|
* at least contain a uri item. Other properties may or may not be
|
|
|
|
* supplied by the authentication backend.
|
|
|
|
*
|
|
|
|
* @param array $principal
|
2020-02-27 18:54:07 +03:00
|
|
|
*
|
2015-11-05 18:46:37 +03:00
|
|
|
* @return \Sabre\DAV\INode
|
|
|
|
*/
|
|
|
|
function getChildForPrincipal(array $principal) {
|
2020-02-27 18:54:07 +03:00
|
|
|
return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager);
|
2015-11-05 18:46:37 +03:00
|
|
|
}
|
|
|
|
|
2015-11-27 15:14:55 +03:00
|
|
|
function getName() {
|
|
|
|
|
2016-01-20 23:08:23 +03:00
|
|
|
if ($this->principalPrefix === 'principals') {
|
|
|
|
return parent::getName();
|
|
|
|
}
|
2015-11-27 15:14:55 +03:00
|
|
|
// Grabbing all the components of the principal path.
|
|
|
|
$parts = explode('/', $this->principalPrefix);
|
|
|
|
|
|
|
|
// We are only interested in the second part.
|
|
|
|
return $parts[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|