ContactsManager.php 1.9 KB

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