2016-01-11 13:34:17 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-07-21 16:13:36 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-11 13:34:17 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @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,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\CardDAV;
|
|
|
|
|
|
|
|
use OCP\Contacts\IManager;
|
2016-09-20 12:15:23 +00:00
|
|
|
use OCP\IL10N;
|
2016-06-21 13:25:44 +00:00
|
|
|
use OCP\IURLGenerator;
|
2016-01-11 13:34:17 +00:00
|
|
|
|
|
|
|
class ContactsManager {
|
2016-07-05 20:45:05 +00:00
|
|
|
/** @var CardDavBackend */
|
|
|
|
private $backend;
|
2016-01-11 13:34:17 +00:00
|
|
|
|
2016-09-20 12:15:23 +00:00
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
|
|
|
|
2016-01-11 13:34:17 +00:00
|
|
|
/**
|
|
|
|
* ContactsManager constructor.
|
|
|
|
*
|
|
|
|
* @param CardDavBackend $backend
|
2016-09-20 12:15:23 +00:00
|
|
|
* @param IL10N $l10n
|
2016-01-11 13:34:17 +00:00
|
|
|
*/
|
2016-09-20 12:15:23 +00:00
|
|
|
public function __construct(CardDavBackend $backend, IL10N $l10n) {
|
2016-01-11 13:34:17 +00:00
|
|
|
$this->backend = $backend;
|
2016-09-20 12:15:23 +00:00
|
|
|
$this->l10n = $l10n;
|
2016-01-11 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IManager $cm
|
|
|
|
* @param string $userId
|
2016-06-21 13:25:44 +00:00
|
|
|
* @param IURLGenerator $urlGenerator
|
2016-01-11 13:34:17 +00:00
|
|
|
*/
|
2016-06-21 13:25:44 +00:00
|
|
|
public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) {
|
2016-01-28 14:02:01 +00:00
|
|
|
$addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
|
2016-06-21 13:25:44 +00:00
|
|
|
$this->register($cm, $addressBooks, $urlGenerator);
|
2016-01-28 14:02:01 +00:00
|
|
|
$addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
|
2016-06-21 13:25:44 +00:00
|
|
|
$this->register($cm, $addressBooks, $urlGenerator);
|
2016-01-28 14:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IManager $cm
|
|
|
|
* @param $addressBooks
|
2016-06-21 13:25:44 +00:00
|
|
|
* @param IURLGenerator $urlGenerator
|
2016-01-28 14:02:01 +00:00
|
|
|
*/
|
2016-06-21 13:25:44 +00:00
|
|
|
private function register(IManager $cm, $addressBooks, $urlGenerator) {
|
2016-01-28 14:02:01 +00:00
|
|
|
foreach ($addressBooks as $addressBookInfo) {
|
2016-09-20 12:15:23 +00:00
|
|
|
$addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n);
|
2016-01-11 13:34:17 +00:00
|
|
|
$cm->registerAddressBook(
|
|
|
|
new AddressBookImpl(
|
|
|
|
$addressBook,
|
|
|
|
$addressBookInfo,
|
2016-06-21 13:25:44 +00:00
|
|
|
$this->backend,
|
|
|
|
$urlGenerator
|
2016-01-11 13:34:17 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|