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\Model\ISearchOption; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @since 15.0.0 |
40
|
|
|
* |
41
|
|
|
* Class ISearchOption |
42
|
|
|
* |
43
|
|
|
* @package OC\FullTextSearch\Model |
44
|
|
|
*/ |
45
|
|
|
final class SearchOption implements ISearchOption, JsonSerializable { |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** @var string */ |
49
|
|
|
private $name = ''; |
50
|
|
|
|
51
|
|
|
/** @var string */ |
52
|
|
|
private $title = ''; |
53
|
|
|
|
54
|
|
|
/** @var string */ |
55
|
|
|
private $type = ''; |
56
|
|
|
|
57
|
|
|
/** @var string */ |
58
|
|
|
private $size = ''; |
59
|
|
|
|
60
|
|
|
/** @var string */ |
61
|
|
|
private $placeholder = ''; |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* * |
66
|
|
|
* |
67
|
|
|
* The array can be empty in case no search options are available. |
68
|
|
|
* The format of the array must be like this: |
69
|
|
|
* |
70
|
|
|
* [ |
71
|
|
|
* 'panel' => [ |
72
|
|
|
* 'options' => [ |
73
|
|
|
* OPTION1, |
74
|
|
|
* OPTION2, |
75
|
|
|
* OPTION3 |
76
|
|
|
* ] |
77
|
|
|
* ], |
78
|
|
|
* 'navigation' => [ |
79
|
|
|
* 'icon' => 'css-class-of-the-icon', |
80
|
|
|
* 'options' => [ |
81
|
|
|
* OPTION1, |
82
|
|
|
* OPTION2, |
83
|
|
|
* OPTION3 |
84
|
|
|
* ] |
85
|
|
|
* ] |
86
|
|
|
* ] |
87
|
|
|
* |
88
|
|
|
* - PANEL contains entries that will be displayed in the app itself, when |
89
|
|
|
* a search is initiated. |
90
|
|
|
* - NAVIGATION contains entries that will be available when using the |
91
|
|
|
* FullTextSearch navigation page |
92
|
|
|
* - OPTION is an element that define each option available to the user. |
93
|
|
|
* |
94
|
|
|
* The format for the options must be like this: |
95
|
|
|
* |
96
|
|
|
* [ |
97
|
|
|
* 'name' => 'name_of_the_option', |
98
|
|
|
* 'title' => 'Name displayed in the panel', |
99
|
|
|
* 'type' => '', |
100
|
|
|
* 'size' => '' (optional), |
101
|
|
|
* 'placeholder' => '' (optional) |
102
|
|
|
* ] |
103
|
|
|
* |
104
|
|
|
* - NAME is the variable name that is sent to the IFullTextSearchProvider |
105
|
|
|
* when a ISearchRequest is requested. (keys in the array returned by the |
106
|
|
|
* ISearchRequest->getOptions()) |
107
|
|
|
* - TYPE can be 'input' or 'checkbox' |
108
|
|
|
* - SIZE is only used in case TYPE='input', default is 'large' but can be |
109
|
|
|
* 'small' |
110
|
|
|
* - PLACEHOLDER is only used in case TYPE='input', default is empty. |
111
|
|
|
*/ |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* ISearchOption constructor. |
115
|
|
|
* |
116
|
|
|
* Some value can be setduring the creation of the object. |
117
|
|
|
* |
118
|
|
|
* @since 15.0.0 |
119
|
|
|
* |
120
|
|
|
* @param string $name |
121
|
|
|
* @param string $title |
122
|
|
|
* @param string $type |
123
|
|
|
* @param string $size |
124
|
|
|
* @param string $placeholder |
125
|
|
|
*/ |
126
|
|
|
public function __construct(string $name = '', string $title = '', string $type = '', string $size = '', string $placeholder = '') { |
127
|
|
|
$this->name = $name; |
128
|
|
|
$this->title = $title; |
129
|
|
|
$this->type = $type; |
130
|
|
|
$this->size = $size; |
131
|
|
|
$this->placeholder = $placeholder; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Set the name/key of the option. |
137
|
|
|
* The string should only contains alphanumerical chars and underscore. |
138
|
|
|
* The key can be retrieve when using ISearchRequest::getOption |
139
|
|
|
* |
140
|
|
|
* @see ISearchRequest::getOption |
141
|
|
|
* |
142
|
|
|
* @since 15.0.0 |
143
|
|
|
* |
144
|
|
|
* @param string $name |
145
|
|
|
* |
146
|
|
|
* @return ISearchOption |
147
|
|
|
*/ |
148
|
|
|
public function setName(string $name): ISearchOption { |
149
|
|
|
$this->name = $name; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get the name/key of the option. |
156
|
|
|
* |
157
|
|
|
* @since 15.0.0 |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
public function getName(): string { |
162
|
|
|
return $this->name; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set the title/display name of the option. |
168
|
|
|
* |
169
|
|
|
* @since 15.0.0 |
170
|
|
|
* |
171
|
|
|
* @param string $title |
172
|
|
|
* |
173
|
|
|
* @return ISearchOption |
174
|
|
|
*/ |
175
|
|
|
public function setTitle(string $title): ISearchOption { |
176
|
|
|
$this->title = $title; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get the title of the option. |
183
|
|
|
* |
184
|
|
|
* @since 15.0.0 |
185
|
|
|
* |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function getTitle(): string { |
189
|
|
|
return $this->title; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Set the type of the option. |
195
|
|
|
* $type can be ISearchOption::CHECKBOX or ISearchOption::INPUT |
196
|
|
|
* |
197
|
|
|
* @since 15.0.0 |
198
|
|
|
* |
199
|
|
|
* @param string $type |
200
|
|
|
* |
201
|
|
|
* @return ISearchOption |
202
|
|
|
*/ |
203
|
|
|
public function setType(string $type): ISearchOption { |
204
|
|
|
$this->type = $type; |
205
|
|
|
|
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Get the type of the option. |
211
|
|
|
* |
212
|
|
|
* @since 15.0.0 |
213
|
|
|
* |
214
|
|
|
* @return string |
215
|
|
|
*/ |
216
|
|
|
public function getType(): string { |
217
|
|
|
return $this->type; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* In case of Type is INPUT, set the size of the input field. |
223
|
|
|
* Value can be ISearchOption::INPUT_SMALL or not defined. |
224
|
|
|
* |
225
|
|
|
* @since 15.0.0 |
226
|
|
|
* |
227
|
|
|
* @param string $size |
228
|
|
|
* |
229
|
|
|
* @return ISearchOption |
230
|
|
|
*/ |
231
|
|
|
public function setSize(string $size): ISearchOption { |
232
|
|
|
$this->size = $size; |
233
|
|
|
|
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get the size of the INPUT. |
239
|
|
|
* |
240
|
|
|
* @since 15.0.0 |
241
|
|
|
* |
242
|
|
|
* @return string |
243
|
|
|
*/ |
244
|
|
|
public function getSize(): string { |
245
|
|
|
return $this->size; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* In case of Type is , set the placeholder to be displayed in the input |
251
|
|
|
* field. |
252
|
|
|
* |
253
|
|
|
* @since 15.0.0 |
254
|
|
|
* |
255
|
|
|
* @param string $placeholder |
256
|
|
|
* |
257
|
|
|
* @return ISearchOption |
258
|
|
|
*/ |
259
|
|
|
public function setPlaceholder(string $placeholder): ISearchOption { |
260
|
|
|
$this->placeholder = $placeholder; |
261
|
|
|
|
262
|
|
|
return $this; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Get the placeholder. |
267
|
|
|
* |
268
|
|
|
* @since 15.0.0 |
269
|
|
|
* |
270
|
|
|
* @return string |
271
|
|
|
*/ |
272
|
|
|
public function getPlaceholder(): string { |
273
|
|
|
return $this->placeholder; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @since 15.0.0 |
279
|
|
|
* |
280
|
|
|
* @return array |
281
|
|
|
*/ |
282
|
|
|
public function jsonSerialize(): array { |
283
|
|
|
return [ |
284
|
|
|
'name' => $this->getName(), |
285
|
|
|
'title' => $this->getTitle(), |
286
|
|
|
'type' => $this->getType(), |
287
|
|
|
'size' => $this->getSize(), |
288
|
|
|
'placeholder' => $this->getPlaceholder() |
289
|
|
|
]; |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|