ContactsManager.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <georg@owncloud.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  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 OCP\Contacts\IManager;
  26. use OCP\IURLGenerator;
  27. class ContactsManager {
  28. /** @var CardDavBackend */
  29. private $backend;
  30. /**
  31. * ContactsManager constructor.
  32. *
  33. * @param CardDavBackend $backend
  34. */
  35. public function __construct(CardDavBackend $backend) {
  36. $this->backend = $backend;
  37. }
  38. /**
  39. * @param IManager $cm
  40. * @param string $userId
  41. * @param IURLGenerator $urlGenerator
  42. */
  43. public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) {
  44. $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
  45. $this->register($cm, $addressBooks, $urlGenerator);
  46. $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
  47. $this->register($cm, $addressBooks, $urlGenerator);
  48. }
  49. /**
  50. * @param IManager $cm
  51. * @param $addressBooks
  52. * @param IURLGenerator $urlGenerator
  53. */
  54. private function register(IManager $cm, $addressBooks, $urlGenerator) {
  55. foreach ($addressBooks as $addressBookInfo) {
  56. $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo);
  57. $cm->registerAddressBook(
  58. new AddressBookImpl(
  59. $addressBook,
  60. $addressBookInfo,
  61. $this->backend,
  62. $urlGenerator
  63. )
  64. );
  65. }
  66. }
  67. }