You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ContactsManager.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. * @author Tobia De Koninck <tobia@ledfan.be>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\DAV\CardDAV;
  27. use OCP\Contacts\IManager;
  28. use OCP\IL10N;
  29. use OCP\IURLGenerator;
  30. class ContactsManager {
  31. /** @var CardDavBackend */
  32. private $backend;
  33. /** @var IL10N */
  34. private $l10n;
  35. /**
  36. * ContactsManager constructor.
  37. *
  38. * @param CardDavBackend $backend
  39. * @param IL10N $l10n
  40. */
  41. public function __construct(CardDavBackend $backend, IL10N $l10n) {
  42. $this->backend = $backend;
  43. $this->l10n = $l10n;
  44. }
  45. /**
  46. * @param IManager $cm
  47. * @param string $userId
  48. * @param IURLGenerator $urlGenerator
  49. */
  50. public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) {
  51. $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
  52. $this->register($cm, $addressBooks, $urlGenerator);
  53. $this->setupSystemContactsProvider($cm, $urlGenerator);
  54. }
  55. /**
  56. * @param IManager $cm
  57. * @param IURLGenerator $urlGenerator
  58. */
  59. public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) {
  60. $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
  61. $this->register($cm, $addressBooks, $urlGenerator);
  62. }
  63. /**
  64. * @param IManager $cm
  65. * @param $addressBooks
  66. * @param IURLGenerator $urlGenerator
  67. */
  68. private function register(IManager $cm, $addressBooks, $urlGenerator) {
  69. foreach ($addressBooks as $addressBookInfo) {
  70. $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n);
  71. $cm->registerAddressBook(
  72. new AddressBookImpl(
  73. $addressBook,
  74. $addressBookInfo,
  75. $this->backend,
  76. $urlGenerator
  77. )
  78. );
  79. }
  80. }
  81. }