Blame view
sources/apps/contacts/lib/backend/shared.php
3.39 KB
|
d1bafeea1
|
1 2 3 4 5 |
<?php /** * ownCloud - Backend for Shared contacts * * @author Thomas Tanghus |
|
6d9380f96
|
6 |
* @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net) |
|
d1bafeea1
|
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>. * */ namespace OCA\Contacts\Backend; use OCA\Contacts; /** |
|
6d9380f96
|
28 |
* Backend class for shared address books. |
|
d1bafeea1
|
29 |
*/ |
|
d1bafeea1
|
30 |
class Shared extends Database {
|
|
6d9380f96
|
31 32 33 34 35 |
/** * The name of the backend. * * @var string */ |
|
d1bafeea1
|
36 |
public $name = 'shared'; |
|
d1bafeea1
|
37 38 |
/** |
|
6d9380f96
|
39 |
* The cached address books. |
|
d1bafeea1
|
40 |
* |
|
6d9380f96
|
41 |
* @var array[] |
|
d1bafeea1
|
42 |
*/ |
|
6d9380f96
|
43 44 45 46 47 |
public $addressBooks = array();
/**
* {@inheritdoc}
*/
|
|
d1bafeea1
|
48 49 50 51 52 53 54 |
public function getAddressBooksForUser(array $options = array()) {
// workaround for https://github.com/owncloud/core/issues/2814
$maybeSharedAddressBook = \OCP\Share::getItemsSharedWith(
'addressbook',
Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS
);
|
|
d1bafeea1
|
55 56 57 58 59 60 |
foreach ($maybeSharedAddressBook as $sharedAddressbook) {
if (isset($sharedAddressbook['id'])) {
$this->addressBooks[$sharedAddressbook['id']] = $sharedAddressbook;
$this->addressBooks[$sharedAddressbook['id']]['backend'] = $this->name;
}
|
|
6d9380f96
|
61 |
|
|
d1bafeea1
|
62 63 64 65 66 67 |
} return $this->addressBooks; } /** |
|
6d9380f96
|
68 69 70 71 72 73 74 75 76 77 78 |
* {@inheritdoc}
*/
public function getAddressBook($addressBookId, array $options = array()) {
foreach ($this->addressBooks as $addressBook) {
if ($addressBook['id'] === $addressBookId) {
return $addressBook;
}
}
|
|
d1bafeea1
|
79 80 |
$addressBook = \OCP\Share::getItemSharedWithBySource( 'addressbook', |
|
6d9380f96
|
81 |
$addressBookId, |
|
d1bafeea1
|
82 83 |
Contacts\Share\Addressbook::FORMAT_ADDRESSBOOKS ); |
|
6d9380f96
|
84 |
|
|
d1bafeea1
|
85 86 87 |
// Not sure if I'm doing it wrongly, or if its supposed to return // the info in an array? $addressBook = (isset($addressBook['permissions']) ? $addressBook : $addressBook[0]); |
|
6d9380f96
|
88 89 90 91 |
if(!isset($addressBook['permissions'])) {
return null;
}
|
|
d1bafeea1
|
92 |
$addressBook['backend'] = $this->name; |
|
6d9380f96
|
93 |
$this->addressBooks[] = $addressBook; |
|
d1bafeea1
|
94 95 96 97 |
return $addressBook; } /** |
|
6d9380f96
|
98 99 100 |
* {@inheritdoc}
*/
public function getContacts($addressBookId, array $options = array()) {
|
|
d1bafeea1
|
101 |
|
|
6d9380f96
|
102 103 104 105 |
$addressBook = $this->getAddressBook($addressBookId);
if (!$addressBook) {
throw new \Exception('Shared Address Book not found: ' . $addressBookId, 404);
|
|
d1bafeea1
|
106 |
} |
|
6d9380f96
|
107 |
|
|
d1bafeea1
|
108 |
$permissions = $addressBook['permissions']; |
|
6d9380f96
|
109 |
$cards = parent::getContacts($addressBookId, $options); |
|
d1bafeea1
|
110 |
|
|
6d9380f96
|
111 |
foreach ($cards as &$card) {
|
|
d1bafeea1
|
112 113 114 115 116 117 118 |
$card['permissions'] = $permissions; } return $cards; } /** |
|
6d9380f96
|
119 120 121 122 123 124 125 126 |
* {@inheritdoc}
*/
public function getContact($addressBookId, $id, array $options = array()) {
$addressBook = $this->getAddressBook($addressBookId);
if (!$addressBook) {
throw new \Exception('Shared Address Book not found: ' . $addressBookId, 404);
|
|
d1bafeea1
|
127 |
} |
|
6d9380f96
|
128 |
|
|
d1bafeea1
|
129 |
$permissions = $addressBook['permissions']; |
|
6d9380f96
|
130 131 132 |
$card = parent::getContact($addressBookId, $id, $options);
if (!$card) {
|
|
d1bafeea1
|
133 134 |
throw new \Exception('Shared Contact not found: ' . implode(',', $id), 404);
}
|
|
6d9380f96
|
135 |
|
|
d1bafeea1
|
136 137 138 139 |
$card['permissions'] = $permissions; return $card; } } |