AddressBookRoot.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\CardDAV;
  25. use OCA\DAV\AppInfo\PluginManager;
  26. class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
  27. /** @var PluginManager */
  28. private $pluginManager;
  29. /**
  30. * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
  31. * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
  32. * @param string $principalPrefix
  33. */
  34. public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend,
  35. \Sabre\CardDAV\Backend\BackendInterface $carddavBackend,
  36. PluginManager $pluginManager,
  37. $principalPrefix = 'principals') {
  38. parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
  39. $this->pluginManager = $pluginManager;
  40. }
  41. /**
  42. * This method returns a node for a principal.
  43. *
  44. * The passed array contains principal information, and is guaranteed to
  45. * at least contain a uri item. Other properties may or may not be
  46. * supplied by the authentication backend.
  47. *
  48. * @param array $principal
  49. *
  50. * @return \Sabre\DAV\INode
  51. */
  52. public function getChildForPrincipal(array $principal) {
  53. return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager);
  54. }
  55. public function getName() {
  56. if ($this->principalPrefix === 'principals') {
  57. return parent::getName();
  58. }
  59. // Grabbing all the components of the principal path.
  60. $parts = explode('/', $this->principalPrefix);
  61. // We are only interested in the second part.
  62. return $parts[1];
  63. }
  64. }