AddressBookRoot.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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\CardDAV;
  23. use OCP\IL10N;
  24. class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
  25. /** @var IL10N */
  26. protected $l10n;
  27. /**
  28. * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
  29. * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
  30. * @param string $principalPrefix
  31. */
  32. public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
  33. parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
  34. $this->l10n = \OC::$server->getL10N('dav');
  35. }
  36. /**
  37. * This method returns a node for a principal.
  38. *
  39. * The passed array contains principal information, and is guaranteed to
  40. * at least contain a uri item. Other properties may or may not be
  41. * supplied by the authentication backend.
  42. *
  43. * @param array $principal
  44. * @return \Sabre\DAV\INode
  45. */
  46. function getChildForPrincipal(array $principal) {
  47. return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
  48. }
  49. function getName() {
  50. if ($this->principalPrefix === 'principals') {
  51. return parent::getName();
  52. }
  53. // Grabbing all the components of the principal path.
  54. $parts = explode('/', $this->principalPrefix);
  55. // We are only interested in the second part.
  56. return $parts[1];
  57. }
  58. }