@@ -31,91 +31,91 @@ |
||
31 | 31 | |
32 | 32 | class Manager { |
33 | 33 | |
34 | - /** @var ContactsStore */ |
|
35 | - private $store; |
|
36 | - |
|
37 | - /** @var ActionProviderStore */ |
|
38 | - private $actionProviderStore; |
|
39 | - |
|
40 | - /** @var IAppManager */ |
|
41 | - private $appManager; |
|
42 | - |
|
43 | - /** @var IConfig */ |
|
44 | - private $config; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param ContactsStore $store |
|
48 | - * @param ActionProviderStore $actionProviderStore |
|
49 | - * @param IAppManager $appManager |
|
50 | - */ |
|
51 | - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
52 | - $this->store = $store; |
|
53 | - $this->actionProviderStore = $actionProviderStore; |
|
54 | - $this->appManager = $appManager; |
|
55 | - $this->config = $config; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param IUser $user |
|
60 | - * @param string $filter |
|
61 | - * @return array |
|
62 | - */ |
|
63 | - public function getEntries(IUser $user, $filter) { |
|
64 | - $maxAutocompleteResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', 25); |
|
65 | - $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
66 | - $topEntries = []; |
|
67 | - if (strlen($filter) >= $minSearchStringLength) { |
|
68 | - $entries = $this->store->getContacts($user, $filter); |
|
69 | - |
|
70 | - $sortedEntries = $this->sortEntries($entries); |
|
71 | - $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
72 | - $this->processEntries($topEntries, $user); |
|
73 | - } |
|
74 | - |
|
75 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
76 | - return [ |
|
77 | - 'contacts' => $topEntries, |
|
78 | - 'contactsAppEnabled' => $contactsEnabled, |
|
79 | - ]; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param IUser $user |
|
84 | - * @param integer $shareType |
|
85 | - * @param string $shareWith |
|
86 | - * @return IEntry |
|
87 | - */ |
|
88 | - public function findOne(IUser $user, $shareType, $shareWith) { |
|
89 | - $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
90 | - if ($entry) { |
|
91 | - $this->processEntries([$entry], $user); |
|
92 | - } |
|
93 | - |
|
94 | - return $entry; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param IEntry[] $entries |
|
99 | - * @return IEntry[] |
|
100 | - */ |
|
101 | - private function sortEntries(array $entries) { |
|
102 | - usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
103 | - return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
104 | - }); |
|
105 | - return $entries; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param IEntry[] $entries |
|
110 | - * @param IUser $user |
|
111 | - */ |
|
112 | - private function processEntries(array $entries, IUser $user) { |
|
113 | - $providers = $this->actionProviderStore->getProviders($user); |
|
114 | - foreach ($entries as $entry) { |
|
115 | - foreach ($providers as $provider) { |
|
116 | - $provider->process($entry); |
|
117 | - } |
|
118 | - } |
|
119 | - } |
|
34 | + /** @var ContactsStore */ |
|
35 | + private $store; |
|
36 | + |
|
37 | + /** @var ActionProviderStore */ |
|
38 | + private $actionProviderStore; |
|
39 | + |
|
40 | + /** @var IAppManager */ |
|
41 | + private $appManager; |
|
42 | + |
|
43 | + /** @var IConfig */ |
|
44 | + private $config; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param ContactsStore $store |
|
48 | + * @param ActionProviderStore $actionProviderStore |
|
49 | + * @param IAppManager $appManager |
|
50 | + */ |
|
51 | + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
52 | + $this->store = $store; |
|
53 | + $this->actionProviderStore = $actionProviderStore; |
|
54 | + $this->appManager = $appManager; |
|
55 | + $this->config = $config; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param IUser $user |
|
60 | + * @param string $filter |
|
61 | + * @return array |
|
62 | + */ |
|
63 | + public function getEntries(IUser $user, $filter) { |
|
64 | + $maxAutocompleteResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', 25); |
|
65 | + $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
66 | + $topEntries = []; |
|
67 | + if (strlen($filter) >= $minSearchStringLength) { |
|
68 | + $entries = $this->store->getContacts($user, $filter); |
|
69 | + |
|
70 | + $sortedEntries = $this->sortEntries($entries); |
|
71 | + $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
72 | + $this->processEntries($topEntries, $user); |
|
73 | + } |
|
74 | + |
|
75 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
76 | + return [ |
|
77 | + 'contacts' => $topEntries, |
|
78 | + 'contactsAppEnabled' => $contactsEnabled, |
|
79 | + ]; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param IUser $user |
|
84 | + * @param integer $shareType |
|
85 | + * @param string $shareWith |
|
86 | + * @return IEntry |
|
87 | + */ |
|
88 | + public function findOne(IUser $user, $shareType, $shareWith) { |
|
89 | + $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
90 | + if ($entry) { |
|
91 | + $this->processEntries([$entry], $user); |
|
92 | + } |
|
93 | + |
|
94 | + return $entry; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param IEntry[] $entries |
|
99 | + * @return IEntry[] |
|
100 | + */ |
|
101 | + private function sortEntries(array $entries) { |
|
102 | + usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
103 | + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
104 | + }); |
|
105 | + return $entries; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param IEntry[] $entries |
|
110 | + * @param IUser $user |
|
111 | + */ |
|
112 | + private function processEntries(array $entries, IUser $user) { |
|
113 | + $providers = $this->actionProviderStore->getProviders($user); |
|
114 | + foreach ($entries as $entry) { |
|
115 | + foreach ($providers as $provider) { |
|
116 | + $provider->process($entry); |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | } |