2016-01-11 16:34:17 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 22:15:27 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-11 16:34:17 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Tobia De Koninck <tobia@ledfan.be>
|
2016-01-11 16:34:17 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-01-11 16:34:17 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\CardDAV;
|
|
|
|
|
|
|
|
use OCP\Contacts\IManager;
|
2016-09-20 15:15:23 +03:00
|
|
|
use OCP\IL10N;
|
2016-06-21 16:25:44 +03:00
|
|
|
use OCP\IURLGenerator;
|
2016-01-11 16:34:17 +03:00
|
|
|
|
|
|
|
class ContactsManager {
|
2016-07-05 23:45:05 +03:00
|
|
|
/** @var CardDavBackend */
|
|
|
|
private $backend;
|
2016-01-11 16:34:17 +03:00
|
|
|
|
2016-09-20 15:15:23 +03:00
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
|
|
|
|
2016-01-11 16:34:17 +03:00
|
|
|
/**
|
|
|
|
* ContactsManager constructor.
|
|
|
|
*
|
|
|
|
* @param CardDavBackend $backend
|
2016-09-20 15:15:23 +03:00
|
|
|
* @param IL10N $l10n
|
2016-01-11 16:34:17 +03:00
|
|
|
*/
|
2016-09-20 15:15:23 +03:00
|
|
|
public function __construct(CardDavBackend $backend, IL10N $l10n) {
|
2016-01-11 16:34:17 +03:00
|
|
|
$this->backend = $backend;
|
2016-09-20 15:15:23 +03:00
|
|
|
$this->l10n = $l10n;
|
2016-01-11 16:34:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IManager $cm
|
|
|
|
* @param string $userId
|
2016-06-21 16:25:44 +03:00
|
|
|
* @param IURLGenerator $urlGenerator
|
2016-01-11 16:34:17 +03:00
|
|
|
*/
|
2016-06-21 16:25:44 +03:00
|
|
|
public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) {
|
2016-01-28 17:02:01 +03:00
|
|
|
$addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
|
2016-06-21 16:25:44 +03:00
|
|
|
$this->register($cm, $addressBooks, $urlGenerator);
|
2017-09-16 14:42:46 +03:00
|
|
|
$this->setupSystemContactsProvider($cm, $urlGenerator);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IManager $cm
|
|
|
|
* @param IURLGenerator $urlGenerator
|
|
|
|
*/
|
|
|
|
public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) {
|
2016-01-28 17:02:01 +03:00
|
|
|
$addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
|
2016-06-21 16:25:44 +03:00
|
|
|
$this->register($cm, $addressBooks, $urlGenerator);
|
2016-01-28 17:02:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IManager $cm
|
|
|
|
* @param $addressBooks
|
2016-06-21 16:25:44 +03:00
|
|
|
* @param IURLGenerator $urlGenerator
|
2016-01-28 17:02:01 +03:00
|
|
|
*/
|
2016-06-21 16:25:44 +03:00
|
|
|
private function register(IManager $cm, $addressBooks, $urlGenerator) {
|
2016-01-28 17:02:01 +03:00
|
|
|
foreach ($addressBooks as $addressBookInfo) {
|
2016-09-20 15:15:23 +03:00
|
|
|
$addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n);
|
2016-01-11 16:34:17 +03:00
|
|
|
$cm->registerAddressBook(
|
|
|
|
new AddressBookImpl(
|
|
|
|
$addressBook,
|
|
|
|
$addressBookInfo,
|
2016-06-21 16:25:44 +03:00
|
|
|
$this->backend,
|
|
|
|
$urlGenerator
|
2016-01-11 16:34:17 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|