1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017 Arthur Schiwon <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Arthur Schiwon <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OC\Collaboration\Collaborators; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
use OCP\Collaboration\Collaborators\ISearchResult; |
28
|
|
|
use OCP\Collaboration\Collaborators\SearchResultType; |
29
|
|
|
|
30
|
|
|
class SearchResult implements ISearchResult { |
31
|
|
|
|
32
|
|
|
protected $result = [ |
33
|
|
|
'exact' => [], |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
protected $exactIdMatches = []; |
37
|
|
|
|
38
|
|
|
public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
39
|
|
|
$type = $type->getLabel(); |
40
|
|
View Code Duplication |
if(!isset($this->result[$type])) { |
41
|
|
|
$this->result[$type] = []; |
42
|
|
|
$this->result['exact'][$type] = []; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->result[$type] = array_merge($this->result[$type], $matches); |
46
|
|
|
if(is_array($exactMatches)) { |
47
|
|
|
$this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function markExactIdMatch(SearchResultType $type) { |
52
|
|
|
$this->exactIdMatches[$type->getLabel()] = 1; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function hasExactIdMatch(SearchResultType$type) { |
56
|
|
|
return isset($this->exactIdMatches[$type->getLabel()]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function hasResult(SearchResultType $type, $collaboratorId) { |
60
|
|
|
$type = $type->getLabel(); |
61
|
|
|
if(!isset($this->result[$type])) { |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
66
|
|
|
foreach($resultArrays as $resultArray) { |
67
|
|
|
if ($resultArray['value']['shareWith'] === $collaboratorId) { |
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function asArray() { |
76
|
|
|
return $this->result; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function unsetResult(SearchResultType $type) { |
80
|
|
|
$type = $type->getLabel(); |
81
|
|
|
$this->result[$type] = []; |
82
|
|
View Code Duplication |
if(isset($this->result['exact'][$type])) { |
83
|
|
|
$this->result['exact'][$type] = []; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|