@@ -40,238 +40,238 @@ |
||
| 40 | 40 | |
| 41 | 41 | class ContactsStore implements IContactsStore { |
| 42 | 42 | |
| 43 | - /** @var IManager */ |
|
| 44 | - private $contactsManager; |
|
| 45 | - |
|
| 46 | - /** @var IConfig */ |
|
| 47 | - private $config; |
|
| 48 | - |
|
| 49 | - /** @var IUserManager */ |
|
| 50 | - private $userManager; |
|
| 51 | - |
|
| 52 | - /** @var IGroupManager */ |
|
| 53 | - private $groupManager; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param IManager $contactsManager |
|
| 57 | - * @param IConfig $config |
|
| 58 | - * @param IUserManager $userManager |
|
| 59 | - * @param IGroupManager $groupManager |
|
| 60 | - */ |
|
| 61 | - public function __construct(IManager $contactsManager, |
|
| 62 | - IConfig $config, |
|
| 63 | - IUserManager $userManager, |
|
| 64 | - IGroupManager $groupManager) { |
|
| 65 | - $this->contactsManager = $contactsManager; |
|
| 66 | - $this->config = $config; |
|
| 67 | - $this->userManager = $userManager; |
|
| 68 | - $this->groupManager = $groupManager; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param IUser $user |
|
| 73 | - * @param string|null $filter |
|
| 74 | - * @return IEntry[] |
|
| 75 | - */ |
|
| 76 | - public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) { |
|
| 77 | - $options = []; |
|
| 78 | - if ($limit !== null) { |
|
| 79 | - $options['limit'] = $limit; |
|
| 80 | - } |
|
| 81 | - if ($offset !== null) { |
|
| 82 | - $options['offset'] = $offset; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $allContacts = $this->contactsManager->search( |
|
| 86 | - $filter ?: '', |
|
| 87 | - [ |
|
| 88 | - 'FN', |
|
| 89 | - 'EMAIL' |
|
| 90 | - ], |
|
| 91 | - $options |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - $entries = array_map(function (array $contact) { |
|
| 95 | - return $this->contactArrayToEntry($contact); |
|
| 96 | - }, $allContacts); |
|
| 97 | - return $this->filterContacts( |
|
| 98 | - $user, |
|
| 99 | - $entries, |
|
| 100 | - $filter |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Filters the contacts. Applies 3 filters: |
|
| 106 | - * 1. filter the current user |
|
| 107 | - * 2. if the `shareapi_allow_share_dialog_user_enumeration` config option is |
|
| 108 | - * enabled it will filter all local users |
|
| 109 | - * 3. if the `shareapi_exclude_groups` config option is enabled and the |
|
| 110 | - * current user is in an excluded group it will filter all local users. |
|
| 111 | - * 4. if the `shareapi_only_share_with_group_members` config option is |
|
| 112 | - * enabled it will filter all users which doens't have a common group |
|
| 113 | - * with the current user. |
|
| 114 | - * |
|
| 115 | - * @param IUser $self |
|
| 116 | - * @param Entry[] $entries |
|
| 117 | - * @param string $filter |
|
| 118 | - * @return Entry[] the filtered contacts |
|
| 119 | - */ |
|
| 120 | - private function filterContacts(IUser $self, |
|
| 121 | - array $entries, |
|
| 122 | - $filter) { |
|
| 123 | - $disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes'; |
|
| 124 | - $restrictEnumeration = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 125 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes'; |
|
| 126 | - |
|
| 127 | - // whether to filter out local users |
|
| 128 | - $skipLocal = false; |
|
| 129 | - // whether to filter out all users which doesn't have the same group as the current user |
|
| 130 | - $ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes' || $restrictEnumeration; |
|
| 131 | - |
|
| 132 | - $selfGroups = $this->groupManager->getUserGroupIds($self); |
|
| 133 | - |
|
| 134 | - if ($excludedGroups) { |
|
| 135 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 136 | - $decodedExcludeGroups = json_decode($excludedGroups, true); |
|
| 137 | - $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups : []; |
|
| 138 | - |
|
| 139 | - if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) { |
|
| 140 | - // a group of the current user is excluded -> filter all local users |
|
| 141 | - $skipLocal = true; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $selfUID = $self->getUID(); |
|
| 146 | - |
|
| 147 | - return array_values(array_filter($entries, function (IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) { |
|
| 148 | - if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) { |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Prevent enumerating local users |
|
| 153 | - if ($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) { |
|
| 154 | - $filterUser = true; |
|
| 155 | - |
|
| 156 | - $mailAddresses = $entry->getEMailAddresses(); |
|
| 157 | - foreach ($mailAddresses as $mailAddress) { |
|
| 158 | - if ($mailAddress === $filter) { |
|
| 159 | - $filterUser = false; |
|
| 160 | - break; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) { |
|
| 165 | - $filterUser = false; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if ($filterUser) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) { |
|
| 174 | - $uid = $this->userManager->get($entry->getProperty('UID')); |
|
| 175 | - |
|
| 176 | - if ($uid === null) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $contactGroups = $this->groupManager->getUserGroupIds($uid); |
|
| 181 | - if (count(array_intersect($contactGroups, $selfGroups)) === 0) { |
|
| 182 | - // no groups in common, so shouldn't see the contact |
|
| 183 | - return false; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $entry->getProperty('UID') !== $selfUID; |
|
| 188 | - })); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param IUser $user |
|
| 193 | - * @param integer $shareType |
|
| 194 | - * @param string $shareWith |
|
| 195 | - * @return IEntry|null |
|
| 196 | - */ |
|
| 197 | - public function findOne(IUser $user, $shareType, $shareWith) { |
|
| 198 | - switch ($shareType) { |
|
| 199 | - case 0: |
|
| 200 | - case 6: |
|
| 201 | - $filter = ['UID']; |
|
| 202 | - break; |
|
| 203 | - case 4: |
|
| 204 | - $filter = ['EMAIL']; |
|
| 205 | - break; |
|
| 206 | - default: |
|
| 207 | - return null; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $userId = $user->getUID(); |
|
| 211 | - $allContacts = $this->contactsManager->search($shareWith, $filter); |
|
| 212 | - $contacts = array_filter($allContacts, function ($contact) use ($userId) { |
|
| 213 | - return $contact['UID'] !== $userId; |
|
| 214 | - }); |
|
| 215 | - $match = null; |
|
| 216 | - |
|
| 217 | - foreach ($contacts as $contact) { |
|
| 218 | - if ($shareType === 4 && isset($contact['EMAIL'])) { |
|
| 219 | - if (in_array($shareWith, $contact['EMAIL'])) { |
|
| 220 | - $match = $contact; |
|
| 221 | - break; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - if ($shareType === 0 || $shareType === 6) { |
|
| 225 | - $isLocal = $contact['isLocalSystemBook'] ?? false; |
|
| 226 | - if ($contact['UID'] === $shareWith && $isLocal === true) { |
|
| 227 | - $match = $contact; |
|
| 228 | - break; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - if ($match) { |
|
| 234 | - $match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith); |
|
| 235 | - if (count($match) === 1) { |
|
| 236 | - $match = $match[0]; |
|
| 237 | - } else { |
|
| 238 | - $match = null; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return $match; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param array $contact |
|
| 247 | - * @return Entry |
|
| 248 | - */ |
|
| 249 | - private function contactArrayToEntry(array $contact) { |
|
| 250 | - $entry = new Entry(); |
|
| 251 | - |
|
| 252 | - if (isset($contact['id'])) { |
|
| 253 | - $entry->setId($contact['id']); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - if (isset($contact['FN'])) { |
|
| 257 | - $entry->setFullName($contact['FN']); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $avatarPrefix = "VALUE=uri:"; |
|
| 261 | - if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) { |
|
| 262 | - $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix))); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if (isset($contact['EMAIL'])) { |
|
| 266 | - foreach ($contact['EMAIL'] as $email) { |
|
| 267 | - $entry->addEMailAddress($email); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Attach all other properties to the entry too because some |
|
| 272 | - // providers might make use of it. |
|
| 273 | - $entry->setProperties($contact); |
|
| 274 | - |
|
| 275 | - return $entry; |
|
| 276 | - } |
|
| 43 | + /** @var IManager */ |
|
| 44 | + private $contactsManager; |
|
| 45 | + |
|
| 46 | + /** @var IConfig */ |
|
| 47 | + private $config; |
|
| 48 | + |
|
| 49 | + /** @var IUserManager */ |
|
| 50 | + private $userManager; |
|
| 51 | + |
|
| 52 | + /** @var IGroupManager */ |
|
| 53 | + private $groupManager; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param IManager $contactsManager |
|
| 57 | + * @param IConfig $config |
|
| 58 | + * @param IUserManager $userManager |
|
| 59 | + * @param IGroupManager $groupManager |
|
| 60 | + */ |
|
| 61 | + public function __construct(IManager $contactsManager, |
|
| 62 | + IConfig $config, |
|
| 63 | + IUserManager $userManager, |
|
| 64 | + IGroupManager $groupManager) { |
|
| 65 | + $this->contactsManager = $contactsManager; |
|
| 66 | + $this->config = $config; |
|
| 67 | + $this->userManager = $userManager; |
|
| 68 | + $this->groupManager = $groupManager; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param IUser $user |
|
| 73 | + * @param string|null $filter |
|
| 74 | + * @return IEntry[] |
|
| 75 | + */ |
|
| 76 | + public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) { |
|
| 77 | + $options = []; |
|
| 78 | + if ($limit !== null) { |
|
| 79 | + $options['limit'] = $limit; |
|
| 80 | + } |
|
| 81 | + if ($offset !== null) { |
|
| 82 | + $options['offset'] = $offset; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $allContacts = $this->contactsManager->search( |
|
| 86 | + $filter ?: '', |
|
| 87 | + [ |
|
| 88 | + 'FN', |
|
| 89 | + 'EMAIL' |
|
| 90 | + ], |
|
| 91 | + $options |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + $entries = array_map(function (array $contact) { |
|
| 95 | + return $this->contactArrayToEntry($contact); |
|
| 96 | + }, $allContacts); |
|
| 97 | + return $this->filterContacts( |
|
| 98 | + $user, |
|
| 99 | + $entries, |
|
| 100 | + $filter |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Filters the contacts. Applies 3 filters: |
|
| 106 | + * 1. filter the current user |
|
| 107 | + * 2. if the `shareapi_allow_share_dialog_user_enumeration` config option is |
|
| 108 | + * enabled it will filter all local users |
|
| 109 | + * 3. if the `shareapi_exclude_groups` config option is enabled and the |
|
| 110 | + * current user is in an excluded group it will filter all local users. |
|
| 111 | + * 4. if the `shareapi_only_share_with_group_members` config option is |
|
| 112 | + * enabled it will filter all users which doens't have a common group |
|
| 113 | + * with the current user. |
|
| 114 | + * |
|
| 115 | + * @param IUser $self |
|
| 116 | + * @param Entry[] $entries |
|
| 117 | + * @param string $filter |
|
| 118 | + * @return Entry[] the filtered contacts |
|
| 119 | + */ |
|
| 120 | + private function filterContacts(IUser $self, |
|
| 121 | + array $entries, |
|
| 122 | + $filter) { |
|
| 123 | + $disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes'; |
|
| 124 | + $restrictEnumeration = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 125 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes'; |
|
| 126 | + |
|
| 127 | + // whether to filter out local users |
|
| 128 | + $skipLocal = false; |
|
| 129 | + // whether to filter out all users which doesn't have the same group as the current user |
|
| 130 | + $ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes' || $restrictEnumeration; |
|
| 131 | + |
|
| 132 | + $selfGroups = $this->groupManager->getUserGroupIds($self); |
|
| 133 | + |
|
| 134 | + if ($excludedGroups) { |
|
| 135 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 136 | + $decodedExcludeGroups = json_decode($excludedGroups, true); |
|
| 137 | + $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups : []; |
|
| 138 | + |
|
| 139 | + if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) { |
|
| 140 | + // a group of the current user is excluded -> filter all local users |
|
| 141 | + $skipLocal = true; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $selfUID = $self->getUID(); |
|
| 146 | + |
|
| 147 | + return array_values(array_filter($entries, function (IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) { |
|
| 148 | + if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Prevent enumerating local users |
|
| 153 | + if ($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) { |
|
| 154 | + $filterUser = true; |
|
| 155 | + |
|
| 156 | + $mailAddresses = $entry->getEMailAddresses(); |
|
| 157 | + foreach ($mailAddresses as $mailAddress) { |
|
| 158 | + if ($mailAddress === $filter) { |
|
| 159 | + $filterUser = false; |
|
| 160 | + break; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) { |
|
| 165 | + $filterUser = false; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if ($filterUser) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) { |
|
| 174 | + $uid = $this->userManager->get($entry->getProperty('UID')); |
|
| 175 | + |
|
| 176 | + if ($uid === null) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $contactGroups = $this->groupManager->getUserGroupIds($uid); |
|
| 181 | + if (count(array_intersect($contactGroups, $selfGroups)) === 0) { |
|
| 182 | + // no groups in common, so shouldn't see the contact |
|
| 183 | + return false; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $entry->getProperty('UID') !== $selfUID; |
|
| 188 | + })); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param IUser $user |
|
| 193 | + * @param integer $shareType |
|
| 194 | + * @param string $shareWith |
|
| 195 | + * @return IEntry|null |
|
| 196 | + */ |
|
| 197 | + public function findOne(IUser $user, $shareType, $shareWith) { |
|
| 198 | + switch ($shareType) { |
|
| 199 | + case 0: |
|
| 200 | + case 6: |
|
| 201 | + $filter = ['UID']; |
|
| 202 | + break; |
|
| 203 | + case 4: |
|
| 204 | + $filter = ['EMAIL']; |
|
| 205 | + break; |
|
| 206 | + default: |
|
| 207 | + return null; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $userId = $user->getUID(); |
|
| 211 | + $allContacts = $this->contactsManager->search($shareWith, $filter); |
|
| 212 | + $contacts = array_filter($allContacts, function ($contact) use ($userId) { |
|
| 213 | + return $contact['UID'] !== $userId; |
|
| 214 | + }); |
|
| 215 | + $match = null; |
|
| 216 | + |
|
| 217 | + foreach ($contacts as $contact) { |
|
| 218 | + if ($shareType === 4 && isset($contact['EMAIL'])) { |
|
| 219 | + if (in_array($shareWith, $contact['EMAIL'])) { |
|
| 220 | + $match = $contact; |
|
| 221 | + break; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + if ($shareType === 0 || $shareType === 6) { |
|
| 225 | + $isLocal = $contact['isLocalSystemBook'] ?? false; |
|
| 226 | + if ($contact['UID'] === $shareWith && $isLocal === true) { |
|
| 227 | + $match = $contact; |
|
| 228 | + break; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + if ($match) { |
|
| 234 | + $match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith); |
|
| 235 | + if (count($match) === 1) { |
|
| 236 | + $match = $match[0]; |
|
| 237 | + } else { |
|
| 238 | + $match = null; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return $match; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param array $contact |
|
| 247 | + * @return Entry |
|
| 248 | + */ |
|
| 249 | + private function contactArrayToEntry(array $contact) { |
|
| 250 | + $entry = new Entry(); |
|
| 251 | + |
|
| 252 | + if (isset($contact['id'])) { |
|
| 253 | + $entry->setId($contact['id']); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + if (isset($contact['FN'])) { |
|
| 257 | + $entry->setFullName($contact['FN']); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $avatarPrefix = "VALUE=uri:"; |
|
| 261 | + if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) { |
|
| 262 | + $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix))); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if (isset($contact['EMAIL'])) { |
|
| 266 | + foreach ($contact['EMAIL'] as $email) { |
|
| 267 | + $entry->addEMailAddress($email); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Attach all other properties to the entry too because some |
|
| 272 | + // providers might make use of it. |
|
| 273 | + $entry->setProperties($contact); |
|
| 274 | + |
|
| 275 | + return $entry; |
|
| 276 | + } |
|
| 277 | 277 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $options |
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | - $entries = array_map(function (array $contact) { |
|
| 94 | + $entries = array_map(function(array $contact) { |
|
| 95 | 95 | return $this->contactArrayToEntry($contact); |
| 96 | 96 | }, $allContacts); |
| 97 | 97 | return $this->filterContacts( |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $selfUID = $self->getUID(); |
| 146 | 146 | |
| 147 | - return array_values(array_filter($entries, function (IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) { |
|
| 147 | + return array_values(array_filter($entries, function(IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) { |
|
| 148 | 148 | if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) { |
| 149 | 149 | return false; |
| 150 | 150 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | $userId = $user->getUID(); |
| 211 | 211 | $allContacts = $this->contactsManager->search($shareWith, $filter); |
| 212 | - $contacts = array_filter($allContacts, function ($contact) use ($userId) { |
|
| 212 | + $contacts = array_filter($allContacts, function($contact) use ($userId) { |
|
| 213 | 213 | return $contact['UID'] !== $userId; |
| 214 | 214 | }); |
| 215 | 215 | $match = null; |
@@ -32,90 +32,90 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Manager { |
| 34 | 34 | |
| 35 | - /** @var ContactsStore */ |
|
| 36 | - private $store; |
|
| 35 | + /** @var ContactsStore */ |
|
| 36 | + private $store; |
|
| 37 | 37 | |
| 38 | - /** @var ActionProviderStore */ |
|
| 39 | - private $actionProviderStore; |
|
| 38 | + /** @var ActionProviderStore */ |
|
| 39 | + private $actionProviderStore; |
|
| 40 | 40 | |
| 41 | - /** @var IAppManager */ |
|
| 42 | - private $appManager; |
|
| 41 | + /** @var IAppManager */ |
|
| 42 | + private $appManager; |
|
| 43 | 43 | |
| 44 | - /** @var IConfig */ |
|
| 45 | - private $config; |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + private $config; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param ContactsStore $store |
|
| 49 | - * @param ActionProviderStore $actionProviderStore |
|
| 50 | - * @param IAppManager $appManager |
|
| 51 | - */ |
|
| 52 | - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
| 53 | - $this->store = $store; |
|
| 54 | - $this->actionProviderStore = $actionProviderStore; |
|
| 55 | - $this->appManager = $appManager; |
|
| 56 | - $this->config = $config; |
|
| 57 | - } |
|
| 47 | + /** |
|
| 48 | + * @param ContactsStore $store |
|
| 49 | + * @param ActionProviderStore $actionProviderStore |
|
| 50 | + * @param IAppManager $appManager |
|
| 51 | + */ |
|
| 52 | + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
| 53 | + $this->store = $store; |
|
| 54 | + $this->actionProviderStore = $actionProviderStore; |
|
| 55 | + $this->appManager = $appManager; |
|
| 56 | + $this->config = $config; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param IUser $user |
|
| 61 | - * @param string $filter |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 64 | - public function getEntries(IUser $user, $filter) { |
|
| 65 | - $maxAutocompleteResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', 25); |
|
| 66 | - $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
| 67 | - $topEntries = []; |
|
| 68 | - if (strlen($filter) >= $minSearchStringLength) { |
|
| 69 | - $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
| 59 | + /** |
|
| 60 | + * @param IUser $user |
|
| 61 | + * @param string $filter |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | + public function getEntries(IUser $user, $filter) { |
|
| 65 | + $maxAutocompleteResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', 25); |
|
| 66 | + $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
| 67 | + $topEntries = []; |
|
| 68 | + if (strlen($filter) >= $minSearchStringLength) { |
|
| 69 | + $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
| 70 | 70 | |
| 71 | - $sortedEntries = $this->sortEntries($entries); |
|
| 72 | - $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
| 73 | - $this->processEntries($topEntries, $user); |
|
| 74 | - } |
|
| 71 | + $sortedEntries = $this->sortEntries($entries); |
|
| 72 | + $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
| 73 | + $this->processEntries($topEntries, $user); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
| 77 | - return [ |
|
| 78 | - 'contacts' => $topEntries, |
|
| 79 | - 'contactsAppEnabled' => $contactsEnabled, |
|
| 80 | - ]; |
|
| 81 | - } |
|
| 76 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
| 77 | + return [ |
|
| 78 | + 'contacts' => $topEntries, |
|
| 79 | + 'contactsAppEnabled' => $contactsEnabled, |
|
| 80 | + ]; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param IUser $user |
|
| 85 | - * @param integer $shareType |
|
| 86 | - * @param string $shareWith |
|
| 87 | - * @return IEntry |
|
| 88 | - */ |
|
| 89 | - public function findOne(IUser $user, $shareType, $shareWith) { |
|
| 90 | - $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
| 91 | - if ($entry) { |
|
| 92 | - $this->processEntries([$entry], $user); |
|
| 93 | - } |
|
| 83 | + /** |
|
| 84 | + * @param IUser $user |
|
| 85 | + * @param integer $shareType |
|
| 86 | + * @param string $shareWith |
|
| 87 | + * @return IEntry |
|
| 88 | + */ |
|
| 89 | + public function findOne(IUser $user, $shareType, $shareWith) { |
|
| 90 | + $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
| 91 | + if ($entry) { |
|
| 92 | + $this->processEntries([$entry], $user); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return $entry; |
|
| 96 | - } |
|
| 95 | + return $entry; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @param IEntry[] $entries |
|
| 100 | - * @return IEntry[] |
|
| 101 | - */ |
|
| 102 | - private function sortEntries(array $entries) { |
|
| 103 | - usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
| 104 | - return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
| 105 | - }); |
|
| 106 | - return $entries; |
|
| 107 | - } |
|
| 98 | + /** |
|
| 99 | + * @param IEntry[] $entries |
|
| 100 | + * @return IEntry[] |
|
| 101 | + */ |
|
| 102 | + private function sortEntries(array $entries) { |
|
| 103 | + usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
| 104 | + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
| 105 | + }); |
|
| 106 | + return $entries; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @param IEntry[] $entries |
|
| 111 | - * @param IUser $user |
|
| 112 | - */ |
|
| 113 | - private function processEntries(array $entries, IUser $user) { |
|
| 114 | - $providers = $this->actionProviderStore->getProviders($user); |
|
| 115 | - foreach ($entries as $entry) { |
|
| 116 | - foreach ($providers as $provider) { |
|
| 117 | - $provider->process($entry); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 109 | + /** |
|
| 110 | + * @param IEntry[] $entries |
|
| 111 | + * @param IUser $user |
|
| 112 | + */ |
|
| 113 | + private function processEntries(array $entries, IUser $user) { |
|
| 114 | + $providers = $this->actionProviderStore->getProviders($user); |
|
| 115 | + foreach ($entries as $entry) { |
|
| 116 | + foreach ($providers as $provider) { |
|
| 117 | + $provider->process($entry); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -31,23 +31,23 @@ |
||
| 31 | 31 | interface IContactsStore { |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param IUser $user |
|
| 36 | - * @param string $filter |
|
| 37 | - * @param int $limit added 19.0.2 |
|
| 38 | - * @param int $offset added 19.0.2 |
|
| 39 | - * @return IEntry[] |
|
| 40 | - * @since 13.0.0 |
|
| 41 | - */ |
|
| 42 | - public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null); |
|
| 34 | + /** |
|
| 35 | + * @param IUser $user |
|
| 36 | + * @param string $filter |
|
| 37 | + * @param int $limit added 19.0.2 |
|
| 38 | + * @param int $offset added 19.0.2 |
|
| 39 | + * @return IEntry[] |
|
| 40 | + * @since 13.0.0 |
|
| 41 | + */ |
|
| 42 | + public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith) |
|
| 46 | - * @param IUser $user |
|
| 47 | - * @param integer $shareType |
|
| 48 | - * @param string $shareWith |
|
| 49 | - * @return IEntry|null |
|
| 50 | - * @since 13.0.0 |
|
| 51 | - */ |
|
| 52 | - public function findOne(IUser $user, $shareType, $shareWith); |
|
| 44 | + /** |
|
| 45 | + * @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith) |
|
| 46 | + * @param IUser $user |
|
| 47 | + * @param integer $shareType |
|
| 48 | + * @param string $shareWith |
|
| 49 | + * @return IEntry|null |
|
| 50 | + * @since 13.0.0 |
|
| 51 | + */ |
|
| 52 | + public function findOne(IUser $user, $shareType, $shareWith); |
|
| 53 | 53 | } |