2016-01-11 16:34:17 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
2016-01-11 16:34:17 +03: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-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
|
|
|
|
|
|
|
/**
|
|
|
|
* ContactsManager constructor.
|
|
|
|
*
|
|
|
|
* @param CardDavBackend $backend
|
|
|
|
*/
|
|
|
|
public function __construct(CardDavBackend $backend) {
|
|
|
|
$this->backend = $backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
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-01-11 16:34:17 +03:00
|
|
|
$addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo);
|
|
|
|
$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
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|