1
0

ContactsManager.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\IL10N;
  27. use OCP\IURLGenerator;
  28. class ContactsManager {
  29. /** @var CardDavBackend */
  30. private $backend;
  31. /** @var IL10N */
  32. private $l10n;
  33. /**
  34. * ContactsManager constructor.
  35. *
  36. * @param CardDavBackend $backend
  37. * @param IL10N $l10n
  38. */
  39. public function __construct(CardDavBackend $backend, IL10N $l10n) {
  40. $this->backend = $backend;
  41. $this->l10n = $l10n;
  42. }
  43. /**
  44. * @param IManager $cm
  45. * @param string $userId
  46. * @param IURLGenerator $urlGenerator
  47. */
  48. public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) {
  49. $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
  50. $this->register($cm, $addressBooks, $urlGenerator);
  51. $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
  52. $this->register($cm, $addressBooks, $urlGenerator);
  53. }
  54. /**
  55. * @param IManager $cm
  56. * @param $addressBooks
  57. * @param IURLGenerator $urlGenerator
  58. */
  59. private function register(IManager $cm, $addressBooks, $urlGenerator) {
  60. foreach ($addressBooks as $addressBookInfo) {
  61. $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n);
  62. $cm->registerAddressBook(
  63. new AddressBookImpl(
  64. $addressBook,
  65. $addressBookInfo,
  66. $this->backend,
  67. $urlGenerator
  68. )
  69. );
  70. }
  71. }
  72. }