1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright 2020 Christoph Wurst <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author 2020 Christoph Wurst <[email protected]> |
9
|
|
|
* |
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
|
|
|
namespace OCP\Search; |
27
|
|
|
|
28
|
|
|
use JsonSerializable; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @since 20.0.0 |
32
|
|
|
*/ |
33
|
|
|
final class SearchResult implements JsonSerializable { |
34
|
|
|
|
35
|
|
|
/** @var string */ |
36
|
|
|
private $name; |
37
|
|
|
|
38
|
|
|
/** @var bool */ |
39
|
|
|
private $isPaginated; |
40
|
|
|
|
41
|
|
|
/** @var ASearchResultEntry[] */ |
42
|
|
|
private $entries; |
43
|
|
|
|
44
|
|
|
/** @var int|string|null */ |
45
|
|
|
private $cursor; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $name the translated name of the result section or group, e.g. "Mail" |
49
|
|
|
* @param bool $isPaginated |
50
|
|
|
* @param ASearchResultEntry[] $entries |
51
|
|
|
* @param null $cursor |
|
|
|
|
52
|
|
|
* |
53
|
|
|
* @since 20.0.0 |
54
|
|
|
*/ |
55
|
|
|
private function __construct(string $name, |
56
|
|
|
bool $isPaginated, |
57
|
|
|
array $entries, |
58
|
|
|
$cursor = null) { |
59
|
|
|
$this->name = $name; |
60
|
|
|
$this->isPaginated = $isPaginated; |
61
|
|
|
$this->entries = $entries; |
62
|
|
|
$this->cursor = $cursor; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param ASearchResultEntry[] $entries |
67
|
|
|
* |
68
|
|
|
* @return static |
69
|
|
|
* |
70
|
|
|
* @since 20.0.0 |
71
|
|
|
*/ |
72
|
|
|
public static function complete(string $name, array $entries): self { |
73
|
|
|
return new self( |
74
|
|
|
$name, |
75
|
|
|
false, |
76
|
|
|
$entries |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param ASearchResultEntry[] $entries |
82
|
|
|
* @param int|string $cursor |
83
|
|
|
* |
84
|
|
|
* @return static |
85
|
|
|
* |
86
|
|
|
* @since 20.0.0 |
87
|
|
|
*/ |
88
|
|
|
public static function paginated(string $name, |
89
|
|
|
array $entries, |
90
|
|
|
$cursor): self { |
91
|
|
|
return new self( |
92
|
|
|
$name, |
93
|
|
|
true, |
94
|
|
|
$entries, |
95
|
|
|
$cursor |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
* |
102
|
|
|
* @since 20.0.0 |
103
|
|
|
*/ |
104
|
|
|
public function jsonSerialize(): array { |
105
|
|
|
return [ |
106
|
|
|
'name' => $this->name, |
107
|
|
|
'isPaginated' => $this->isPaginated, |
108
|
|
|
'entries' => $this->entries, |
109
|
|
|
'cursor' => $this->cursor, |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|