|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Circles\Service; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
use OCA\Circles\ISearch; |
|
31
|
|
|
use OCP\IL10N; |
|
32
|
|
|
use OCP\IUserManager; |
|
33
|
|
|
|
|
34
|
|
|
class SearchService { |
|
35
|
|
|
|
|
36
|
|
|
/** @var IL10N */ |
|
37
|
|
|
private $l10n; |
|
38
|
|
|
|
|
39
|
|
|
/** @var IUserManager */ |
|
40
|
|
|
private $userManager; |
|
41
|
|
|
|
|
42
|
|
|
/** @var ConfigService */ |
|
43
|
|
|
private $configService; |
|
44
|
|
|
|
|
45
|
|
|
/** @var MiscService */ |
|
46
|
|
|
private $miscService; |
|
47
|
|
|
|
|
48
|
|
|
/** @var string[] */ |
|
49
|
|
|
private $searchList; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* MembersService constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @param IL10N $l10n |
|
55
|
|
|
* @param IUserManager $userManager |
|
56
|
|
|
* @param ConfigService $configService |
|
57
|
|
|
* @param MiscService $miscService |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct( |
|
60
|
|
|
IL10N $l10n, IUserManager $userManager, ConfigService $configService, |
|
61
|
|
|
MiscService $miscService |
|
62
|
|
|
) { |
|
63
|
|
|
$this->l10n = $l10n; |
|
64
|
|
|
$this->userManager = $userManager; |
|
65
|
|
|
$this->configService = $configService; |
|
66
|
|
|
$this->miscService = $miscService; |
|
67
|
|
|
|
|
68
|
|
|
$this->loadSearch(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* load list of search engine |
|
74
|
|
|
*/ |
|
75
|
|
|
public function loadSearch() { |
|
76
|
|
|
$this->searchList = [ |
|
77
|
|
|
'OCA\Circles\Search\LocalUsers', |
|
78
|
|
|
'OCA\Circles\Search\LocalGroups', |
|
79
|
|
|
'OCA\Circles\Search\Contacts' |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
public function searchGlobal($str) { |
|
85
|
|
|
|
|
86
|
|
|
$result = []; |
|
87
|
|
|
foreach ($this->searchList as $container) { |
|
88
|
|
|
$searcher = \OC::$server->query((string)$container); |
|
89
|
|
|
|
|
90
|
|
|
if (!($searcher instanceof ISearch)) { |
|
91
|
|
|
$this->miscService->log('Search ' . $container . ' is not compatible exception'); |
|
92
|
|
|
continue; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$result = array_merge($result, $searcher->search($str)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $result; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |