1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
7
|
|
|
* |
8
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
9
|
|
|
* later. See the COPYING file. |
10
|
|
|
* |
11
|
|
|
* @author Maxence Lange <[email protected]> |
12
|
|
|
* @copyright 2018 |
13
|
|
|
* @license GNU AGPL version 3 or any later version |
14
|
|
|
* |
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
18
|
|
|
* License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
namespace OC\FullTextSearch\Model; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
use JsonSerializable; |
35
|
|
|
use OCP\FullTextSearch\IFullTextSearchProvider; |
36
|
|
|
use OCP\FullTextSearch\Model\ISearchOption; |
37
|
|
|
use OCP\FullTextSearch\Model\ISearchTemplate; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Class ISearchTemplate |
42
|
|
|
* |
43
|
|
|
* This is a data transfer object that should be created by Content Provider |
44
|
|
|
* when the getSearchTemplate() method is called. |
45
|
|
|
* |
46
|
|
|
* The object will contain templates to be displayed, and the list of the different |
47
|
|
|
* options to be available to the user when he start a new search. |
48
|
|
|
* |
49
|
|
|
* The display of the Options is generated by the FullTextSearch app and Options |
50
|
|
|
* can be displayed in 2 places: |
51
|
|
|
* |
52
|
|
|
* - the navigation page of the app that generate the indexed content. |
53
|
|
|
* (files, bookmarks, deck, mails, ...) |
54
|
|
|
* - the navigation page of the FullTextSearch app. |
55
|
|
|
* |
56
|
|
|
* Both pages will have different Options, and only the first one can integrate |
57
|
|
|
* a specific template. |
58
|
|
|
* |
59
|
|
|
* @see IFullTextSearchProvider::getSearchTemplate |
60
|
|
|
* |
61
|
|
|
* @since 15.0.0 |
62
|
|
|
* |
63
|
|
|
* @package OC\FullTextSearch\Model |
64
|
|
|
*/ |
65
|
|
|
final class SearchTemplate implements ISearchTemplate, JsonSerializable { |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** @var string */ |
69
|
|
|
private $icon = ''; |
70
|
|
|
|
71
|
|
|
/** @var string */ |
72
|
|
|
private $css = ''; |
73
|
|
|
|
74
|
|
|
/** @var string */ |
75
|
|
|
private $template = ''; |
76
|
|
|
|
77
|
|
|
/** @var SearchOption[] */ |
78
|
|
|
private $panelOptions = []; |
79
|
|
|
|
80
|
|
|
/** @var SearchOption[] */ |
81
|
|
|
private $navigationOptions = []; |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* ISearchTemplate constructor. |
86
|
|
|
* |
87
|
|
|
* the class of the icon and the css file to be loaded can be set during the |
88
|
|
|
* creation of the object. |
89
|
|
|
* |
90
|
|
|
* @since 15.0.0 |
91
|
|
|
* |
92
|
|
|
* @param string $icon |
93
|
|
|
* @param string $css |
94
|
|
|
*/ |
95
|
|
|
public function __construct(string $icon = '', string $css = '') { |
96
|
|
|
$this->icon = $icon; |
97
|
|
|
$this->css = $css; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Set the class of the icon to be displayed in the left panel of the |
103
|
|
|
* FullTextSearch navigation page, in front of the related Content Provider. |
104
|
|
|
* |
105
|
|
|
* @since 15.0.0 |
106
|
|
|
* |
107
|
|
|
* @param string $class |
108
|
|
|
* |
109
|
|
|
* @return ISearchTemplate |
110
|
|
|
*/ |
111
|
|
|
public function setIcon(string $class): ISearchTemplate { |
112
|
|
|
$this->icon = $class; |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get the class of the icon. |
119
|
|
|
* |
120
|
|
|
* @since 15.0.0 |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getIcon(): string { |
125
|
|
|
return $this->icon; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Set the path of a CSS file that will be loaded when needed. |
131
|
|
|
* |
132
|
|
|
* @since 15.0.0 |
133
|
|
|
* |
134
|
|
|
* @param string $css |
135
|
|
|
* |
136
|
|
|
* @return ISearchTemplate |
137
|
|
|
*/ |
138
|
|
|
public function setCss(string $css): ISearchTemplate { |
139
|
|
|
$this->css = $css; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get the path of the CSS file. |
146
|
|
|
* |
147
|
|
|
* @since 15.0.0 |
148
|
|
|
* |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
|
|
public function getCss(): string { |
152
|
|
|
return $this->css; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Set the path of the file of a template that the HTML will be displayed |
158
|
|
|
* below the Options. |
159
|
|
|
* This should only be used if your Content Provider needs to set options in |
160
|
|
|
* a way not generated by FullTextSearch |
161
|
|
|
* |
162
|
|
|
* @since 15.0.0 |
163
|
|
|
* |
164
|
|
|
* @param string $template |
165
|
|
|
* |
166
|
|
|
* @return ISearchTemplate |
167
|
|
|
*/ |
168
|
|
|
public function setTemplate(string $template): ISearchTemplate { |
169
|
|
|
$this->template = $template; |
170
|
|
|
|
171
|
|
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Get the path of the template file. |
176
|
|
|
* |
177
|
|
|
* @since 15.0.0 |
178
|
|
|
* |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function getTemplate(): string { |
182
|
|
|
return $this->template; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Add an option in the Panel that is displayed when the user start a search |
188
|
|
|
* within the app that generate the content. |
189
|
|
|
* |
190
|
|
|
* @see ISearchOption |
191
|
|
|
* |
192
|
|
|
* @since 15.0.0 |
193
|
|
|
* |
194
|
|
|
* @param ISearchOption $option |
195
|
|
|
* |
196
|
|
|
* @return ISearchTemplate |
197
|
|
|
*/ |
198
|
|
|
public function addPanelOption(ISearchOption $option): ISearchTemplate { |
199
|
|
|
$this->panelOptions[] = $option; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get all options to be displayed in the Panel. |
206
|
|
|
* |
207
|
|
|
* @since 15.0.0 |
208
|
|
|
* |
209
|
|
|
* @return SearchOption[] |
210
|
|
|
*/ |
211
|
|
|
public function getPanelOptions(): array { |
212
|
|
|
return $this->panelOptions; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Add an option in the left panel of the FullTextSearch navigation page. |
218
|
|
|
* |
219
|
|
|
* @see ISearchOption |
220
|
|
|
* |
221
|
|
|
* @since 15.0.0 |
222
|
|
|
* |
223
|
|
|
* @param ISearchOption $option |
224
|
|
|
* |
225
|
|
|
* @return ISearchTemplate |
226
|
|
|
*/ |
227
|
|
|
public function addNavigationOption(ISearchOption $option): ISearchTemplate { |
228
|
|
|
$this->navigationOptions[] = $option; |
229
|
|
|
|
230
|
|
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get all options to be displayed in the FullTextSearch navigation page. |
235
|
|
|
* |
236
|
|
|
* @since 15.0.0 |
237
|
|
|
* |
238
|
|
|
* @return array |
239
|
|
|
*/ |
240
|
|
|
public function getNavigationOptions(): array { |
241
|
|
|
return $this->navigationOptions; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @since 15.0.0 |
247
|
|
|
* |
248
|
|
|
* @return array |
249
|
|
|
*/ |
250
|
|
|
public function jsonSerialize(): array { |
251
|
|
|
return [ |
252
|
|
|
'icon' => $this->getIcon(), |
253
|
|
|
'css' => $this->getCss(), |
254
|
|
|
'template' => $this->getTemplate(), |
255
|
|
|
'panel' => $this->getPanelOptions(), |
256
|
|
|
'navigation' => $this->getNavigationOptions() |
257
|
|
|
]; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|