@@ -80,245 +80,245 @@ |
||
80 | 80 | interface IFullTextSearchProvider { |
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Must returns a unique Id used to identify the Content Provider. |
|
85 | - * Id must contains only alphanumeric chars, with no space. |
|
86 | - * |
|
87 | - * @since 15.0.0 |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getId(): string; |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Must returns a descriptive name of the Content Provider. |
|
96 | - * This is used in multiple places, so better use a clear display name. |
|
97 | - * |
|
98 | - * @since 15.0.0 |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function getName(): string; |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Should returns the current configuration of the Content Provider. |
|
107 | - * This is used to display the configuration when using the |
|
108 | - * ./occ fulltextsearch:check command line. |
|
109 | - * |
|
110 | - * @since 15.0.0 |
|
111 | - * |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function getConfiguration(): array; |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * Must returns a ISearchTemplate that contains displayable items and |
|
119 | - * available options to users when searching. |
|
120 | - * |
|
121 | - * @see ISearchTemplate |
|
122 | - * |
|
123 | - * @since 15.0.0 |
|
124 | - * |
|
125 | - * @return ISearchTemplate |
|
126 | - */ |
|
127 | - public function getSearchTemplate(): ISearchTemplate; |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Called when FullTextSearch is loading your Content Provider. |
|
132 | - * |
|
133 | - * @since 15.0.0 |
|
134 | - */ |
|
135 | - public function loadProvider(); |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * Set the wrapper of the currently executed process. |
|
140 | - * Because the index process can be long and heavy, and because errors can |
|
141 | - * be encountered during the process, the IRunner is a wrapper that allow the |
|
142 | - * Content Provider to communicate with the process initiated by |
|
143 | - * FullTextSearch. |
|
144 | - * |
|
145 | - * The IRunner is coming with some methods so the Content Provider can |
|
146 | - * returns important information and errors to be displayed to the admin. |
|
147 | - * |
|
148 | - * @since 15.0.0 |
|
149 | - * |
|
150 | - * @param IRunner $runner |
|
151 | - */ |
|
152 | - public function setRunner(IRunner $runner); |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * This method is called when the administrator specify options when running |
|
157 | - * the ./occ fulltextsearch:index or ./occ fulltextsearch:live |
|
158 | - * |
|
159 | - * @since 15.0.0 |
|
160 | - * |
|
161 | - * @param IIndexOptions $options |
|
162 | - */ |
|
163 | - public function setIndexOptions(IIndexOptions $options); |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Allow the provider to generate a list of chunk to split a huge list of |
|
168 | - * indexable documents |
|
169 | - * |
|
170 | - * During the indexing the generateIndexableDocuments method will be called |
|
171 | - * for each entry of the returned array. |
|
172 | - * If the returned array is empty, the generateIndexableDocuments() will be |
|
173 | - * called only once (per user). |
|
174 | - * |
|
175 | - * @since 16.0.0 |
|
176 | - * |
|
177 | - * @param string $userId |
|
178 | - * |
|
179 | - * @return string[] |
|
180 | - */ |
|
181 | - public function generateChunks(string $userId): array; |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * Returns all indexable document for a user as an array of IIndexDocument. |
|
186 | - * |
|
187 | - * There is no need to fill each IIndexDocument with content; at this point, |
|
188 | - * only fill the object with the minimum information to not waste memory while |
|
189 | - * still being able to identify the document it is referring to. |
|
190 | - * |
|
191 | - * FullTextSearch will call 2 other methods of this interface for each |
|
192 | - * IIndexDocument of the array, prior to their indexing: |
|
193 | - * |
|
194 | - * - first, to compare the date of the last index, |
|
195 | - * - then, to fill each IIndexDocument with complete data |
|
196 | - * |
|
197 | - * @see IIndexDocument |
|
198 | - * |
|
199 | - * @since 15.0.0 |
|
200 | - * -> 16.0.0: the parameter "$chunk" was added |
|
201 | - * |
|
202 | - * @param string $userId |
|
203 | - * @param string $chunk |
|
204 | - * |
|
205 | - * @return IIndexDocument[] |
|
206 | - */ |
|
207 | - public function generateIndexableDocuments(string $userId, string $chunk): array; |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Called to verify that the document is not already indexed and that the |
|
212 | - * old index is not up-to-date, using the IIndex from |
|
213 | - * IIndexDocument->getIndex() |
|
214 | - * |
|
215 | - * Returning true will not queue the current IIndexDocument to any further |
|
216 | - * operation and will continue on the next element from the list returned by |
|
217 | - * generateIndexableDocuments(). |
|
218 | - * |
|
219 | - * @since 15.0.0 |
|
220 | - * |
|
221 | - * @param IIndexDocument $document |
|
222 | - * |
|
223 | - * @return bool |
|
224 | - */ |
|
225 | - public function isDocumentUpToDate(IIndexDocument $document): bool; |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Must fill IIndexDocument with all information relative to the document, |
|
230 | - * before its indexing by the Search Platform. |
|
231 | - * |
|
232 | - * Method is called for each element returned previously by |
|
233 | - * generateIndexableDocuments(). |
|
234 | - * |
|
235 | - * @see IIndexDocument |
|
236 | - * |
|
237 | - * @since 15.0.0 |
|
238 | - * |
|
239 | - * @param IIndexDocument $document |
|
240 | - */ |
|
241 | - public function fillIndexDocument(IIndexDocument $document); |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * The Search Provider must create and return an IIndexDocument |
|
246 | - * based on the IIndex and its status. The IIndexDocument must contains all |
|
247 | - * information as it will be send for indexing. |
|
248 | - * |
|
249 | - * Method is called during a cron or a ./occ fulltextsearch:live after a |
|
250 | - * new document is created, or an old document is set as modified. |
|
251 | - * |
|
252 | - * @since 15.0.0 |
|
253 | - * |
|
254 | - * @param IIndex $index |
|
255 | - * |
|
256 | - * @return IIndexDocument |
|
257 | - */ |
|
258 | - public function updateDocument(IIndex $index): IIndexDocument; |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * Called when an index is initiated by the administrator. |
|
263 | - * This is should only be used in case of a specific mapping is needed. |
|
264 | - * (ie. _almost_ never) |
|
265 | - * |
|
266 | - * @since 15.0.0 |
|
267 | - * |
|
268 | - * @param IFullTextSearchPlatform $platform |
|
269 | - */ |
|
270 | - public function onInitializingIndex(IFullTextSearchPlatform $platform); |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Called when administrator is resetting the index. |
|
275 | - * This is should only be used in case of a specific mapping has been |
|
276 | - * created. |
|
277 | - * |
|
278 | - * @since 15.0.0 |
|
279 | - * |
|
280 | - * @param IFullTextSearchPlatform $platform |
|
281 | - */ |
|
282 | - public function onResettingIndex(IFullTextSearchPlatform $platform); |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * Method is called when a search request is initiated by a user, prior to |
|
287 | - * be sent to the Search Platform. |
|
288 | - * |
|
289 | - * Your Content Provider can interact with the ISearchRequest to apply the |
|
290 | - * search options and make the search more precise. |
|
291 | - * |
|
292 | - * @see ISearchRequest |
|
293 | - * |
|
294 | - * @since 15.0.0 |
|
295 | - * |
|
296 | - * @param ISearchRequest $searchRequest |
|
297 | - */ |
|
298 | - public function improveSearchRequest(ISearchRequest $searchRequest); |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Method is called after results of a search are returned by the |
|
303 | - * Search Platform. |
|
304 | - * |
|
305 | - * Your Content Provider can detail each entry with local data to improve |
|
306 | - * the display of the search result. |
|
307 | - * |
|
308 | - * @see ISearchResult |
|
309 | - * |
|
310 | - * @since 15.0.0 |
|
311 | - * |
|
312 | - * @param ISearchResult $searchResult |
|
313 | - */ |
|
314 | - public function improveSearchResult(ISearchResult $searchResult); |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * not used yet. |
|
319 | - * |
|
320 | - * @since 15.0.0 |
|
321 | - */ |
|
322 | - public function unloadProvider(); |
|
83 | + /** |
|
84 | + * Must returns a unique Id used to identify the Content Provider. |
|
85 | + * Id must contains only alphanumeric chars, with no space. |
|
86 | + * |
|
87 | + * @since 15.0.0 |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getId(): string; |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Must returns a descriptive name of the Content Provider. |
|
96 | + * This is used in multiple places, so better use a clear display name. |
|
97 | + * |
|
98 | + * @since 15.0.0 |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function getName(): string; |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Should returns the current configuration of the Content Provider. |
|
107 | + * This is used to display the configuration when using the |
|
108 | + * ./occ fulltextsearch:check command line. |
|
109 | + * |
|
110 | + * @since 15.0.0 |
|
111 | + * |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function getConfiguration(): array; |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * Must returns a ISearchTemplate that contains displayable items and |
|
119 | + * available options to users when searching. |
|
120 | + * |
|
121 | + * @see ISearchTemplate |
|
122 | + * |
|
123 | + * @since 15.0.0 |
|
124 | + * |
|
125 | + * @return ISearchTemplate |
|
126 | + */ |
|
127 | + public function getSearchTemplate(): ISearchTemplate; |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Called when FullTextSearch is loading your Content Provider. |
|
132 | + * |
|
133 | + * @since 15.0.0 |
|
134 | + */ |
|
135 | + public function loadProvider(); |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * Set the wrapper of the currently executed process. |
|
140 | + * Because the index process can be long and heavy, and because errors can |
|
141 | + * be encountered during the process, the IRunner is a wrapper that allow the |
|
142 | + * Content Provider to communicate with the process initiated by |
|
143 | + * FullTextSearch. |
|
144 | + * |
|
145 | + * The IRunner is coming with some methods so the Content Provider can |
|
146 | + * returns important information and errors to be displayed to the admin. |
|
147 | + * |
|
148 | + * @since 15.0.0 |
|
149 | + * |
|
150 | + * @param IRunner $runner |
|
151 | + */ |
|
152 | + public function setRunner(IRunner $runner); |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * This method is called when the administrator specify options when running |
|
157 | + * the ./occ fulltextsearch:index or ./occ fulltextsearch:live |
|
158 | + * |
|
159 | + * @since 15.0.0 |
|
160 | + * |
|
161 | + * @param IIndexOptions $options |
|
162 | + */ |
|
163 | + public function setIndexOptions(IIndexOptions $options); |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Allow the provider to generate a list of chunk to split a huge list of |
|
168 | + * indexable documents |
|
169 | + * |
|
170 | + * During the indexing the generateIndexableDocuments method will be called |
|
171 | + * for each entry of the returned array. |
|
172 | + * If the returned array is empty, the generateIndexableDocuments() will be |
|
173 | + * called only once (per user). |
|
174 | + * |
|
175 | + * @since 16.0.0 |
|
176 | + * |
|
177 | + * @param string $userId |
|
178 | + * |
|
179 | + * @return string[] |
|
180 | + */ |
|
181 | + public function generateChunks(string $userId): array; |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * Returns all indexable document for a user as an array of IIndexDocument. |
|
186 | + * |
|
187 | + * There is no need to fill each IIndexDocument with content; at this point, |
|
188 | + * only fill the object with the minimum information to not waste memory while |
|
189 | + * still being able to identify the document it is referring to. |
|
190 | + * |
|
191 | + * FullTextSearch will call 2 other methods of this interface for each |
|
192 | + * IIndexDocument of the array, prior to their indexing: |
|
193 | + * |
|
194 | + * - first, to compare the date of the last index, |
|
195 | + * - then, to fill each IIndexDocument with complete data |
|
196 | + * |
|
197 | + * @see IIndexDocument |
|
198 | + * |
|
199 | + * @since 15.0.0 |
|
200 | + * -> 16.0.0: the parameter "$chunk" was added |
|
201 | + * |
|
202 | + * @param string $userId |
|
203 | + * @param string $chunk |
|
204 | + * |
|
205 | + * @return IIndexDocument[] |
|
206 | + */ |
|
207 | + public function generateIndexableDocuments(string $userId, string $chunk): array; |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Called to verify that the document is not already indexed and that the |
|
212 | + * old index is not up-to-date, using the IIndex from |
|
213 | + * IIndexDocument->getIndex() |
|
214 | + * |
|
215 | + * Returning true will not queue the current IIndexDocument to any further |
|
216 | + * operation and will continue on the next element from the list returned by |
|
217 | + * generateIndexableDocuments(). |
|
218 | + * |
|
219 | + * @since 15.0.0 |
|
220 | + * |
|
221 | + * @param IIndexDocument $document |
|
222 | + * |
|
223 | + * @return bool |
|
224 | + */ |
|
225 | + public function isDocumentUpToDate(IIndexDocument $document): bool; |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Must fill IIndexDocument with all information relative to the document, |
|
230 | + * before its indexing by the Search Platform. |
|
231 | + * |
|
232 | + * Method is called for each element returned previously by |
|
233 | + * generateIndexableDocuments(). |
|
234 | + * |
|
235 | + * @see IIndexDocument |
|
236 | + * |
|
237 | + * @since 15.0.0 |
|
238 | + * |
|
239 | + * @param IIndexDocument $document |
|
240 | + */ |
|
241 | + public function fillIndexDocument(IIndexDocument $document); |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * The Search Provider must create and return an IIndexDocument |
|
246 | + * based on the IIndex and its status. The IIndexDocument must contains all |
|
247 | + * information as it will be send for indexing. |
|
248 | + * |
|
249 | + * Method is called during a cron or a ./occ fulltextsearch:live after a |
|
250 | + * new document is created, or an old document is set as modified. |
|
251 | + * |
|
252 | + * @since 15.0.0 |
|
253 | + * |
|
254 | + * @param IIndex $index |
|
255 | + * |
|
256 | + * @return IIndexDocument |
|
257 | + */ |
|
258 | + public function updateDocument(IIndex $index): IIndexDocument; |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * Called when an index is initiated by the administrator. |
|
263 | + * This is should only be used in case of a specific mapping is needed. |
|
264 | + * (ie. _almost_ never) |
|
265 | + * |
|
266 | + * @since 15.0.0 |
|
267 | + * |
|
268 | + * @param IFullTextSearchPlatform $platform |
|
269 | + */ |
|
270 | + public function onInitializingIndex(IFullTextSearchPlatform $platform); |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Called when administrator is resetting the index. |
|
275 | + * This is should only be used in case of a specific mapping has been |
|
276 | + * created. |
|
277 | + * |
|
278 | + * @since 15.0.0 |
|
279 | + * |
|
280 | + * @param IFullTextSearchPlatform $platform |
|
281 | + */ |
|
282 | + public function onResettingIndex(IFullTextSearchPlatform $platform); |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * Method is called when a search request is initiated by a user, prior to |
|
287 | + * be sent to the Search Platform. |
|
288 | + * |
|
289 | + * Your Content Provider can interact with the ISearchRequest to apply the |
|
290 | + * search options and make the search more precise. |
|
291 | + * |
|
292 | + * @see ISearchRequest |
|
293 | + * |
|
294 | + * @since 15.0.0 |
|
295 | + * |
|
296 | + * @param ISearchRequest $searchRequest |
|
297 | + */ |
|
298 | + public function improveSearchRequest(ISearchRequest $searchRequest); |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Method is called after results of a search are returned by the |
|
303 | + * Search Platform. |
|
304 | + * |
|
305 | + * Your Content Provider can detail each entry with local data to improve |
|
306 | + * the display of the search result. |
|
307 | + * |
|
308 | + * @see ISearchResult |
|
309 | + * |
|
310 | + * @since 15.0.0 |
|
311 | + * |
|
312 | + * @param ISearchResult $searchResult |
|
313 | + */ |
|
314 | + public function improveSearchResult(ISearchResult $searchResult); |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * not used yet. |
|
319 | + * |
|
320 | + * @since 15.0.0 |
|
321 | + */ |
|
322 | + public function unloadProvider(); |
|
323 | 323 | |
324 | 324 | } |
@@ -45,247 +45,247 @@ |
||
45 | 45 | final class SearchOption implements ISearchOption, JsonSerializable { |
46 | 46 | |
47 | 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 | - } |
|
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 | 291 | } |
@@ -65,196 +65,196 @@ |
||
65 | 65 | final class SearchTemplate implements ISearchTemplate, JsonSerializable { |
66 | 66 | |
67 | 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 | - } |
|
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 | 259 | } |
260 | 260 |
@@ -58,308 +58,308 @@ |
||
58 | 58 | final class DocumentAccess implements IDocumentAccess, JsonSerializable { |
59 | 59 | |
60 | 60 | |
61 | - /** @var string */ |
|
62 | - private $ownerId; |
|
63 | - |
|
64 | - /** @var string */ |
|
65 | - private $viewerId = ''; |
|
66 | - |
|
67 | - /** @var array */ |
|
68 | - private $users = []; |
|
69 | - |
|
70 | - /** @var array */ |
|
71 | - private $groups = []; |
|
72 | - |
|
73 | - /** @var array */ |
|
74 | - private $circles = []; |
|
75 | - |
|
76 | - /** @var array */ |
|
77 | - private $links = []; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Owner of the document can be set at the init of the object. |
|
82 | - * |
|
83 | - * @since 16.0.0 |
|
84 | - * |
|
85 | - * IDocumentAccess constructor. |
|
86 | - * |
|
87 | - * @param string $ownerId |
|
88 | - */ |
|
89 | - public function __construct(string $ownerId = '') { |
|
90 | - $this->setOwnerId($ownerId); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Set the Owner of the document. |
|
96 | - * |
|
97 | - * @since 16.0.0 |
|
98 | - * |
|
99 | - * @param string $ownerId |
|
100 | - * |
|
101 | - * @return IDocumentAccess |
|
102 | - */ |
|
103 | - public function setOwnerId(string $ownerId): IDocumentAccess { |
|
104 | - $this->ownerId = $ownerId; |
|
105 | - |
|
106 | - return $this; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get the Owner of the document. |
|
111 | - * |
|
112 | - * @since 16.0.0 |
|
113 | - * |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function getOwnerId(): string { |
|
117 | - return $this->ownerId; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Set the viewer of the document. |
|
123 | - * |
|
124 | - * @since 16.0.0 |
|
125 | - * |
|
126 | - * @param string $viewerId |
|
127 | - * |
|
128 | - * @return IDocumentAccess |
|
129 | - */ |
|
130 | - public function setViewerId(string $viewerId): IDocumentAccess { |
|
131 | - $this->viewerId = $viewerId; |
|
132 | - |
|
133 | - return $this; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Get the viewer of the document. |
|
138 | - * |
|
139 | - * @since 16.0.0 |
|
140 | - * |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function getViewerId(): string { |
|
144 | - return $this->viewerId; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Set the list of users that have read access to the document. |
|
150 | - * |
|
151 | - * @since 16.0.0 |
|
152 | - * |
|
153 | - * @param array $users |
|
154 | - * |
|
155 | - * @return IDocumentAccess |
|
156 | - */ |
|
157 | - public function setUsers(array $users): IDocumentAccess { |
|
158 | - $this->users = $users; |
|
159 | - |
|
160 | - return $this; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Add an entry to the list of users that have read access to the document. |
|
165 | - * |
|
166 | - * @since 16.0.0 |
|
167 | - * |
|
168 | - * @param string $user |
|
169 | - * |
|
170 | - * @return IDocumentAccess |
|
171 | - */ |
|
172 | - public function addUser(string $user): IDocumentAccess { |
|
173 | - $this->users[] = $user; |
|
174 | - |
|
175 | - return $this; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Add multiple entries to the list of users that have read access to the |
|
180 | - * document. |
|
181 | - * |
|
182 | - * @since 16.0.0 |
|
183 | - * |
|
184 | - * @param array $users |
|
185 | - * |
|
186 | - * @return IDocumentAccess |
|
187 | - */ |
|
188 | - public function addUsers($users): IDocumentAccess { |
|
189 | - $this->users = array_merge($this->users, $users); |
|
190 | - |
|
191 | - return $this; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get the complete list of users that have read access to the document. |
|
196 | - * |
|
197 | - * @since 16.0.0 |
|
198 | - * |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - public function getUsers(): array { |
|
202 | - return $this->users; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Set the list of groups that have read access to the document. |
|
208 | - * |
|
209 | - * @since 16.0.0 |
|
210 | - * |
|
211 | - * @param array $groups |
|
212 | - * |
|
213 | - * @return IDocumentAccess |
|
214 | - */ |
|
215 | - public function setGroups(array $groups): IDocumentAccess { |
|
216 | - $this->groups = $groups; |
|
217 | - |
|
218 | - return $this; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Add an entry to the list of groups that have read access to the document. |
|
223 | - * |
|
224 | - * @since 16.0.0 |
|
225 | - * |
|
226 | - * @param string $group |
|
227 | - * |
|
228 | - * @return IDocumentAccess |
|
229 | - */ |
|
230 | - public function addGroup(string $group): IDocumentAccess { |
|
231 | - $this->groups[] = $group; |
|
232 | - |
|
233 | - return $this; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Add multiple entries to the list of groups that have read access to the |
|
238 | - * document. |
|
239 | - * |
|
240 | - * @since 16.0.0 |
|
241 | - * |
|
242 | - * @param array $groups |
|
243 | - * |
|
244 | - * @return IDocumentAccess |
|
245 | - */ |
|
246 | - public function addGroups(array $groups) { |
|
247 | - $this->groups = array_merge($this->groups, $groups); |
|
248 | - |
|
249 | - return $this; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the complete list of groups that have read access to the document. |
|
254 | - * |
|
255 | - * @since 16.0.0 |
|
256 | - * |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - public function getGroups(): array { |
|
260 | - return $this->groups; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Set the list of circles that have read access to the document. |
|
266 | - * |
|
267 | - * @since 16.0.0 |
|
268 | - * |
|
269 | - * @param array $circles |
|
270 | - * |
|
271 | - * @return IDocumentAccess |
|
272 | - */ |
|
273 | - public function setCircles(array $circles): IDocumentAccess { |
|
274 | - $this->circles = $circles; |
|
275 | - |
|
276 | - return $this; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Add an entry to the list of circles that have read access to the document. |
|
281 | - * |
|
282 | - * @since 16.0.0 |
|
283 | - * |
|
284 | - * @param string $circle |
|
285 | - * |
|
286 | - * @return IDocumentAccess |
|
287 | - */ |
|
288 | - public function addCircle(string $circle): IDocumentAccess { |
|
289 | - $this->circles[] = $circle; |
|
290 | - |
|
291 | - return $this; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Add multiple entries to the list of groups that have read access to the |
|
296 | - * document. |
|
297 | - * |
|
298 | - * @since 16.0.0 |
|
299 | - * |
|
300 | - * @param array $circles |
|
301 | - * |
|
302 | - * @return IDocumentAccess |
|
303 | - */ |
|
304 | - public function addCircles(array $circles): IDocumentAccess { |
|
305 | - $this->circles = array_merge($this->circles, $circles); |
|
306 | - |
|
307 | - return $this; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Get the complete list of circles that have read access to the document. |
|
312 | - * |
|
313 | - * @since 16.0.0 |
|
314 | - * |
|
315 | - * @return array |
|
316 | - */ |
|
317 | - public function getCircles(): array { |
|
318 | - return $this->circles; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Set the list of links that have read access to the document. |
|
324 | - * |
|
325 | - * @since 16.0.0 |
|
326 | - * |
|
327 | - * @param array $links |
|
328 | - * |
|
329 | - * @return IDocumentAccess |
|
330 | - */ |
|
331 | - public function setLinks(array $links): IDocumentAccess { |
|
332 | - $this->links = $links; |
|
333 | - |
|
334 | - return $this; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Get the list of links that have read access to the document. |
|
339 | - * |
|
340 | - * @since 16.0.0 |
|
341 | - * |
|
342 | - * @return array |
|
343 | - */ |
|
344 | - public function getLinks(): array { |
|
345 | - return $this->links; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @since 16.0.0 |
|
351 | - * |
|
352 | - * @return array |
|
353 | - */ |
|
354 | - public function jsonSerialize(): array { |
|
355 | - return [ |
|
356 | - 'ownerId' => $this->getOwnerId(), |
|
357 | - 'viewerId' => $this->getViewerId(), |
|
358 | - 'users' => $this->getUsers(), |
|
359 | - 'groups' => $this->getGroups(), |
|
360 | - 'circles' => $this->getCircles(), |
|
361 | - 'links' => $this->getLinks() |
|
362 | - ]; |
|
363 | - } |
|
61 | + /** @var string */ |
|
62 | + private $ownerId; |
|
63 | + |
|
64 | + /** @var string */ |
|
65 | + private $viewerId = ''; |
|
66 | + |
|
67 | + /** @var array */ |
|
68 | + private $users = []; |
|
69 | + |
|
70 | + /** @var array */ |
|
71 | + private $groups = []; |
|
72 | + |
|
73 | + /** @var array */ |
|
74 | + private $circles = []; |
|
75 | + |
|
76 | + /** @var array */ |
|
77 | + private $links = []; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Owner of the document can be set at the init of the object. |
|
82 | + * |
|
83 | + * @since 16.0.0 |
|
84 | + * |
|
85 | + * IDocumentAccess constructor. |
|
86 | + * |
|
87 | + * @param string $ownerId |
|
88 | + */ |
|
89 | + public function __construct(string $ownerId = '') { |
|
90 | + $this->setOwnerId($ownerId); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Set the Owner of the document. |
|
96 | + * |
|
97 | + * @since 16.0.0 |
|
98 | + * |
|
99 | + * @param string $ownerId |
|
100 | + * |
|
101 | + * @return IDocumentAccess |
|
102 | + */ |
|
103 | + public function setOwnerId(string $ownerId): IDocumentAccess { |
|
104 | + $this->ownerId = $ownerId; |
|
105 | + |
|
106 | + return $this; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get the Owner of the document. |
|
111 | + * |
|
112 | + * @since 16.0.0 |
|
113 | + * |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function getOwnerId(): string { |
|
117 | + return $this->ownerId; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Set the viewer of the document. |
|
123 | + * |
|
124 | + * @since 16.0.0 |
|
125 | + * |
|
126 | + * @param string $viewerId |
|
127 | + * |
|
128 | + * @return IDocumentAccess |
|
129 | + */ |
|
130 | + public function setViewerId(string $viewerId): IDocumentAccess { |
|
131 | + $this->viewerId = $viewerId; |
|
132 | + |
|
133 | + return $this; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Get the viewer of the document. |
|
138 | + * |
|
139 | + * @since 16.0.0 |
|
140 | + * |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function getViewerId(): string { |
|
144 | + return $this->viewerId; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Set the list of users that have read access to the document. |
|
150 | + * |
|
151 | + * @since 16.0.0 |
|
152 | + * |
|
153 | + * @param array $users |
|
154 | + * |
|
155 | + * @return IDocumentAccess |
|
156 | + */ |
|
157 | + public function setUsers(array $users): IDocumentAccess { |
|
158 | + $this->users = $users; |
|
159 | + |
|
160 | + return $this; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Add an entry to the list of users that have read access to the document. |
|
165 | + * |
|
166 | + * @since 16.0.0 |
|
167 | + * |
|
168 | + * @param string $user |
|
169 | + * |
|
170 | + * @return IDocumentAccess |
|
171 | + */ |
|
172 | + public function addUser(string $user): IDocumentAccess { |
|
173 | + $this->users[] = $user; |
|
174 | + |
|
175 | + return $this; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Add multiple entries to the list of users that have read access to the |
|
180 | + * document. |
|
181 | + * |
|
182 | + * @since 16.0.0 |
|
183 | + * |
|
184 | + * @param array $users |
|
185 | + * |
|
186 | + * @return IDocumentAccess |
|
187 | + */ |
|
188 | + public function addUsers($users): IDocumentAccess { |
|
189 | + $this->users = array_merge($this->users, $users); |
|
190 | + |
|
191 | + return $this; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get the complete list of users that have read access to the document. |
|
196 | + * |
|
197 | + * @since 16.0.0 |
|
198 | + * |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + public function getUsers(): array { |
|
202 | + return $this->users; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Set the list of groups that have read access to the document. |
|
208 | + * |
|
209 | + * @since 16.0.0 |
|
210 | + * |
|
211 | + * @param array $groups |
|
212 | + * |
|
213 | + * @return IDocumentAccess |
|
214 | + */ |
|
215 | + public function setGroups(array $groups): IDocumentAccess { |
|
216 | + $this->groups = $groups; |
|
217 | + |
|
218 | + return $this; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Add an entry to the list of groups that have read access to the document. |
|
223 | + * |
|
224 | + * @since 16.0.0 |
|
225 | + * |
|
226 | + * @param string $group |
|
227 | + * |
|
228 | + * @return IDocumentAccess |
|
229 | + */ |
|
230 | + public function addGroup(string $group): IDocumentAccess { |
|
231 | + $this->groups[] = $group; |
|
232 | + |
|
233 | + return $this; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Add multiple entries to the list of groups that have read access to the |
|
238 | + * document. |
|
239 | + * |
|
240 | + * @since 16.0.0 |
|
241 | + * |
|
242 | + * @param array $groups |
|
243 | + * |
|
244 | + * @return IDocumentAccess |
|
245 | + */ |
|
246 | + public function addGroups(array $groups) { |
|
247 | + $this->groups = array_merge($this->groups, $groups); |
|
248 | + |
|
249 | + return $this; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the complete list of groups that have read access to the document. |
|
254 | + * |
|
255 | + * @since 16.0.0 |
|
256 | + * |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + public function getGroups(): array { |
|
260 | + return $this->groups; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Set the list of circles that have read access to the document. |
|
266 | + * |
|
267 | + * @since 16.0.0 |
|
268 | + * |
|
269 | + * @param array $circles |
|
270 | + * |
|
271 | + * @return IDocumentAccess |
|
272 | + */ |
|
273 | + public function setCircles(array $circles): IDocumentAccess { |
|
274 | + $this->circles = $circles; |
|
275 | + |
|
276 | + return $this; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Add an entry to the list of circles that have read access to the document. |
|
281 | + * |
|
282 | + * @since 16.0.0 |
|
283 | + * |
|
284 | + * @param string $circle |
|
285 | + * |
|
286 | + * @return IDocumentAccess |
|
287 | + */ |
|
288 | + public function addCircle(string $circle): IDocumentAccess { |
|
289 | + $this->circles[] = $circle; |
|
290 | + |
|
291 | + return $this; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Add multiple entries to the list of groups that have read access to the |
|
296 | + * document. |
|
297 | + * |
|
298 | + * @since 16.0.0 |
|
299 | + * |
|
300 | + * @param array $circles |
|
301 | + * |
|
302 | + * @return IDocumentAccess |
|
303 | + */ |
|
304 | + public function addCircles(array $circles): IDocumentAccess { |
|
305 | + $this->circles = array_merge($this->circles, $circles); |
|
306 | + |
|
307 | + return $this; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get the complete list of circles that have read access to the document. |
|
312 | + * |
|
313 | + * @since 16.0.0 |
|
314 | + * |
|
315 | + * @return array |
|
316 | + */ |
|
317 | + public function getCircles(): array { |
|
318 | + return $this->circles; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Set the list of links that have read access to the document. |
|
324 | + * |
|
325 | + * @since 16.0.0 |
|
326 | + * |
|
327 | + * @param array $links |
|
328 | + * |
|
329 | + * @return IDocumentAccess |
|
330 | + */ |
|
331 | + public function setLinks(array $links): IDocumentAccess { |
|
332 | + $this->links = $links; |
|
333 | + |
|
334 | + return $this; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Get the list of links that have read access to the document. |
|
339 | + * |
|
340 | + * @since 16.0.0 |
|
341 | + * |
|
342 | + * @return array |
|
343 | + */ |
|
344 | + public function getLinks(): array { |
|
345 | + return $this->links; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @since 16.0.0 |
|
351 | + * |
|
352 | + * @return array |
|
353 | + */ |
|
354 | + public function jsonSerialize(): array { |
|
355 | + return [ |
|
356 | + 'ownerId' => $this->getOwnerId(), |
|
357 | + 'viewerId' => $this->getViewerId(), |
|
358 | + 'users' => $this->getUsers(), |
|
359 | + 'groups' => $this->getGroups(), |
|
360 | + 'circles' => $this->getCircles(), |
|
361 | + 'links' => $this->getLinks() |
|
362 | + ]; |
|
363 | + } |
|
364 | 364 | } |
365 | 365 |
@@ -31,129 +31,129 @@ |
||
31 | 31 | |
32 | 32 | class Resource implements IResource { |
33 | 33 | |
34 | - /** @var IManager */ |
|
35 | - protected $manager; |
|
36 | - |
|
37 | - /** @var IDBConnection */ |
|
38 | - protected $connection; |
|
39 | - |
|
40 | - /** @var string */ |
|
41 | - protected $type; |
|
42 | - |
|
43 | - /** @var string */ |
|
44 | - protected $id; |
|
45 | - |
|
46 | - /** @var IUser|null */ |
|
47 | - protected $userForAccess; |
|
48 | - |
|
49 | - /** @var bool|null */ |
|
50 | - protected $access; |
|
51 | - |
|
52 | - /** @var array|null */ |
|
53 | - protected $data; |
|
54 | - |
|
55 | - public function __construct( |
|
56 | - IManager $manager, |
|
57 | - IDBConnection $connection, |
|
58 | - string $type, |
|
59 | - string $id, |
|
60 | - ?IUser $userForAccess = null, |
|
61 | - ?bool $access = null |
|
62 | - ) { |
|
63 | - $this->manager = $manager; |
|
64 | - $this->connection = $connection; |
|
65 | - $this->type = $type; |
|
66 | - $this->id = $id; |
|
67 | - $this->userForAccess = $userForAccess; |
|
68 | - $this->access = $access; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return string |
|
73 | - * @since 16.0.0 |
|
74 | - */ |
|
75 | - public function getType(): string { |
|
76 | - return $this->type; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - * @since 16.0.0 |
|
82 | - */ |
|
83 | - public function getId(): string { |
|
84 | - return $this->id; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return array |
|
89 | - * @since 16.0.0 |
|
90 | - */ |
|
91 | - public function getRichObject(): array { |
|
92 | - if ($this->data === null) { |
|
93 | - $this->data = $this->manager->getResourceRichObject($this); |
|
94 | - } |
|
95 | - |
|
96 | - return $this->data; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Can a user/guest access the resource |
|
101 | - * |
|
102 | - * @param IUser|null $user |
|
103 | - * @return bool |
|
104 | - * @since 16.0.0 |
|
105 | - */ |
|
106 | - public function canAccess(?IUser $user): bool { |
|
107 | - if ($user instanceof IUser) { |
|
108 | - return $this->canUserAccess($user); |
|
109 | - } |
|
110 | - return $this->canGuestAccess(); |
|
111 | - } |
|
112 | - |
|
113 | - protected function canUserAccess(IUser $user): bool { |
|
114 | - if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
115 | - return $this->access; |
|
116 | - } |
|
117 | - |
|
118 | - $access = $this->manager->canAccessResource($this, $user); |
|
119 | - if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
120 | - $this->access = $access; |
|
121 | - } |
|
122 | - return $access; |
|
123 | - } |
|
124 | - |
|
125 | - protected function canGuestAccess(): bool { |
|
126 | - if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) { |
|
127 | - return $this->access; |
|
128 | - } |
|
129 | - |
|
130 | - $access = $this->manager->canAccessResource($this, null); |
|
131 | - if (!$this->userForAccess instanceof IUser) { |
|
132 | - $this->access = $access; |
|
133 | - } |
|
134 | - return $access; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return ICollection[] |
|
139 | - * @since 16.0.0 |
|
140 | - */ |
|
141 | - public function getCollections(): array { |
|
142 | - $collections = []; |
|
143 | - |
|
144 | - $query = $this->connection->getQueryBuilder(); |
|
145 | - |
|
146 | - $query->select('collection_id') |
|
147 | - ->from('collres_resources') |
|
148 | - ->where($query->expr()->eq('resource_type', $query->createNamedParameter($this->getType()))) |
|
149 | - ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId()))); |
|
150 | - |
|
151 | - $result = $query->execute(); |
|
152 | - while ($row = $result->fetch()) { |
|
153 | - $collections[] = $this->manager->getCollection((int) $row['collection_id']); |
|
154 | - } |
|
155 | - $result->closeCursor(); |
|
156 | - |
|
157 | - return $collections; |
|
158 | - } |
|
34 | + /** @var IManager */ |
|
35 | + protected $manager; |
|
36 | + |
|
37 | + /** @var IDBConnection */ |
|
38 | + protected $connection; |
|
39 | + |
|
40 | + /** @var string */ |
|
41 | + protected $type; |
|
42 | + |
|
43 | + /** @var string */ |
|
44 | + protected $id; |
|
45 | + |
|
46 | + /** @var IUser|null */ |
|
47 | + protected $userForAccess; |
|
48 | + |
|
49 | + /** @var bool|null */ |
|
50 | + protected $access; |
|
51 | + |
|
52 | + /** @var array|null */ |
|
53 | + protected $data; |
|
54 | + |
|
55 | + public function __construct( |
|
56 | + IManager $manager, |
|
57 | + IDBConnection $connection, |
|
58 | + string $type, |
|
59 | + string $id, |
|
60 | + ?IUser $userForAccess = null, |
|
61 | + ?bool $access = null |
|
62 | + ) { |
|
63 | + $this->manager = $manager; |
|
64 | + $this->connection = $connection; |
|
65 | + $this->type = $type; |
|
66 | + $this->id = $id; |
|
67 | + $this->userForAccess = $userForAccess; |
|
68 | + $this->access = $access; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + * @since 16.0.0 |
|
74 | + */ |
|
75 | + public function getType(): string { |
|
76 | + return $this->type; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + * @since 16.0.0 |
|
82 | + */ |
|
83 | + public function getId(): string { |
|
84 | + return $this->id; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return array |
|
89 | + * @since 16.0.0 |
|
90 | + */ |
|
91 | + public function getRichObject(): array { |
|
92 | + if ($this->data === null) { |
|
93 | + $this->data = $this->manager->getResourceRichObject($this); |
|
94 | + } |
|
95 | + |
|
96 | + return $this->data; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Can a user/guest access the resource |
|
101 | + * |
|
102 | + * @param IUser|null $user |
|
103 | + * @return bool |
|
104 | + * @since 16.0.0 |
|
105 | + */ |
|
106 | + public function canAccess(?IUser $user): bool { |
|
107 | + if ($user instanceof IUser) { |
|
108 | + return $this->canUserAccess($user); |
|
109 | + } |
|
110 | + return $this->canGuestAccess(); |
|
111 | + } |
|
112 | + |
|
113 | + protected function canUserAccess(IUser $user): bool { |
|
114 | + if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
115 | + return $this->access; |
|
116 | + } |
|
117 | + |
|
118 | + $access = $this->manager->canAccessResource($this, $user); |
|
119 | + if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
120 | + $this->access = $access; |
|
121 | + } |
|
122 | + return $access; |
|
123 | + } |
|
124 | + |
|
125 | + protected function canGuestAccess(): bool { |
|
126 | + if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) { |
|
127 | + return $this->access; |
|
128 | + } |
|
129 | + |
|
130 | + $access = $this->manager->canAccessResource($this, null); |
|
131 | + if (!$this->userForAccess instanceof IUser) { |
|
132 | + $this->access = $access; |
|
133 | + } |
|
134 | + return $access; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return ICollection[] |
|
139 | + * @since 16.0.0 |
|
140 | + */ |
|
141 | + public function getCollections(): array { |
|
142 | + $collections = []; |
|
143 | + |
|
144 | + $query = $this->connection->getQueryBuilder(); |
|
145 | + |
|
146 | + $query->select('collection_id') |
|
147 | + ->from('collres_resources') |
|
148 | + ->where($query->expr()->eq('resource_type', $query->createNamedParameter($this->getType()))) |
|
149 | + ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId()))); |
|
150 | + |
|
151 | + $result = $query->execute(); |
|
152 | + while ($row = $result->fetch()) { |
|
153 | + $collections[] = $this->manager->getCollection((int) $row['collection_id']); |
|
154 | + } |
|
155 | + $result->closeCursor(); |
|
156 | + |
|
157 | + return $collections; |
|
158 | + } |
|
159 | 159 | } |
@@ -29,36 +29,36 @@ |
||
29 | 29 | */ |
30 | 30 | interface IResource { |
31 | 31 | |
32 | - /** |
|
33 | - * @return string |
|
34 | - * @since 16.0.0 |
|
35 | - */ |
|
36 | - public function getType(): string; |
|
32 | + /** |
|
33 | + * @return string |
|
34 | + * @since 16.0.0 |
|
35 | + */ |
|
36 | + public function getType(): string; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return string |
|
40 | - * @since 16.0.0 |
|
41 | - */ |
|
42 | - public function getId(): string; |
|
38 | + /** |
|
39 | + * @return string |
|
40 | + * @since 16.0.0 |
|
41 | + */ |
|
42 | + public function getId(): string; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return array |
|
46 | - * @since 16.0.0 |
|
47 | - */ |
|
48 | - public function getRichObject(): array; |
|
44 | + /** |
|
45 | + * @return array |
|
46 | + * @since 16.0.0 |
|
47 | + */ |
|
48 | + public function getRichObject(): array; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Can a user/guest access the resource |
|
52 | - * |
|
53 | - * @param IUser|null $user |
|
54 | - * @return bool |
|
55 | - * @since 16.0.0 |
|
56 | - */ |
|
57 | - public function canAccess(?IUser $user): bool; |
|
50 | + /** |
|
51 | + * Can a user/guest access the resource |
|
52 | + * |
|
53 | + * @param IUser|null $user |
|
54 | + * @return bool |
|
55 | + * @since 16.0.0 |
|
56 | + */ |
|
57 | + public function canAccess(?IUser $user): bool; |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return ICollection[] |
|
61 | - * @since 16.0.0 |
|
62 | - */ |
|
63 | - public function getCollections(): array; |
|
59 | + /** |
|
60 | + * @return ICollection[] |
|
61 | + * @since 16.0.0 |
|
62 | + */ |
|
63 | + public function getCollections(): array; |
|
64 | 64 | } |
@@ -29,31 +29,31 @@ |
||
29 | 29 | */ |
30 | 30 | interface IProvider { |
31 | 31 | |
32 | - /** |
|
33 | - * Get the resource type of the provider |
|
34 | - * |
|
35 | - * @return string |
|
36 | - * @since 16.0.0 |
|
37 | - */ |
|
38 | - public function getType(): string; |
|
32 | + /** |
|
33 | + * Get the resource type of the provider |
|
34 | + * |
|
35 | + * @return string |
|
36 | + * @since 16.0.0 |
|
37 | + */ |
|
38 | + public function getType(): string; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get the rich object data of a resource |
|
42 | - * |
|
43 | - * @param IResource $resource |
|
44 | - * @return array |
|
45 | - * @since 16.0.0 |
|
46 | - */ |
|
47 | - public function getResourceRichObject(IResource $resource): array; |
|
40 | + /** |
|
41 | + * Get the rich object data of a resource |
|
42 | + * |
|
43 | + * @param IResource $resource |
|
44 | + * @return array |
|
45 | + * @since 16.0.0 |
|
46 | + */ |
|
47 | + public function getResourceRichObject(IResource $resource): array; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Can a user/guest access the collection |
|
51 | - * |
|
52 | - * @param IResource $resource |
|
53 | - * @param IUser|null $user |
|
54 | - * @return bool |
|
55 | - * @since 16.0.0 |
|
56 | - */ |
|
57 | - public function canAccessResource(IResource $resource, ?IUser $user): bool; |
|
49 | + /** |
|
50 | + * Can a user/guest access the collection |
|
51 | + * |
|
52 | + * @param IResource $resource |
|
53 | + * @param IUser|null $user |
|
54 | + * @return bool |
|
55 | + * @since 16.0.0 |
|
56 | + */ |
|
57 | + public function canAccessResource(IResource $resource, ?IUser $user): bool; |
|
58 | 58 | |
59 | 59 | } |
@@ -37,256 +37,256 @@ |
||
37 | 37 | |
38 | 38 | class CollaborationResourcesController extends OCSController { |
39 | 39 | |
40 | - /** @var IManager */ |
|
41 | - private $manager; |
|
42 | - /** @var IUserSession */ |
|
43 | - private $userSession; |
|
44 | - /** @var ILogger */ |
|
45 | - private $logger; |
|
46 | - |
|
47 | - public function __construct( |
|
48 | - string $appName, |
|
49 | - IRequest $request, |
|
50 | - IManager $manager, |
|
51 | - IUserSession $userSession, |
|
52 | - ILogger $logger |
|
53 | - ) { |
|
54 | - parent::__construct($appName, $request); |
|
55 | - |
|
56 | - $this->manager = $manager; |
|
57 | - $this->userSession = $userSession; |
|
58 | - $this->logger = $logger; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param int $collectionId |
|
63 | - * @return ICollection |
|
64 | - * @throws CollectionException when the collection was not found for the user |
|
65 | - */ |
|
66 | - protected function getCollection(int $collectionId): ICollection { |
|
67 | - $collection = $this->manager->getCollectionForUser($collectionId, $this->userSession->getUser()); |
|
68 | - |
|
69 | - if (!$collection->canAccess($this->userSession->getUser())) { |
|
70 | - throw new CollectionException('Not found'); |
|
71 | - } |
|
72 | - |
|
73 | - return $collection; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @NoAdminRequired |
|
78 | - * |
|
79 | - * @param int $collectionId |
|
80 | - * @return DataResponse |
|
81 | - */ |
|
82 | - public function listCollection(int $collectionId): DataResponse { |
|
83 | - try { |
|
84 | - $collection = $this->getCollection($collectionId); |
|
85 | - } catch (CollectionException $e) { |
|
86 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
87 | - } |
|
88 | - |
|
89 | - return $this->respondCollection($collection); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @NoAdminRequired |
|
94 | - * |
|
95 | - * @param string $filter |
|
96 | - * @return DataResponse |
|
97 | - */ |
|
98 | - public function searchCollections(string $filter): DataResponse { |
|
99 | - try { |
|
100 | - $collections = $this->manager->searchCollections($this->userSession->getUser(), $filter); |
|
101 | - } catch (CollectionException $e) { |
|
102 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
103 | - } |
|
104 | - |
|
105 | - return new DataResponse($this->prepareCollections($collections)); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @NoAdminRequired |
|
110 | - * |
|
111 | - * @param int $collectionId |
|
112 | - * @param string $resourceType |
|
113 | - * @param string $resourceId |
|
114 | - * @return DataResponse |
|
115 | - */ |
|
116 | - public function addResource(int $collectionId, string $resourceType, string $resourceId): DataResponse { |
|
117 | - try { |
|
118 | - $collection = $this->getCollection($collectionId); |
|
119 | - } catch (CollectionException $e) { |
|
120 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
121 | - } |
|
122 | - |
|
123 | - $resource = $this->manager->createResource($resourceType, $resourceId); |
|
124 | - |
|
125 | - if (!$resource->canAccess($this->userSession->getUser())) { |
|
126 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
127 | - } |
|
128 | - |
|
129 | - try { |
|
130 | - $collection->addResource($resource); |
|
131 | - } catch (ResourceException $e) { |
|
132 | - } |
|
133 | - |
|
134 | - return $this->respondCollection($collection); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @NoAdminRequired |
|
139 | - * |
|
140 | - * @param int $collectionId |
|
141 | - * @param string $resourceType |
|
142 | - * @param string $resourceId |
|
143 | - * @return DataResponse |
|
144 | - */ |
|
145 | - public function removeResource(int $collectionId, string $resourceType, string $resourceId): DataResponse { |
|
146 | - try { |
|
147 | - $collection = $this->getCollection($collectionId); |
|
148 | - } catch (CollectionException $e) { |
|
149 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
150 | - } |
|
151 | - |
|
152 | - try { |
|
153 | - $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser()); |
|
154 | - } catch (CollectionException $e) { |
|
155 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
156 | - } |
|
157 | - |
|
158 | - $collection->removeResource($resource); |
|
159 | - |
|
160 | - return $this->respondCollection($collection); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @NoAdminRequired |
|
165 | - * |
|
166 | - * @param string $resourceType |
|
167 | - * @param string $resourceId |
|
168 | - * @return DataResponse |
|
169 | - */ |
|
170 | - public function getCollectionsByResource(string $resourceType, string $resourceId): DataResponse { |
|
171 | - try { |
|
172 | - $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser()); |
|
173 | - } catch (ResourceException $e) { |
|
174 | - $resource = $this->manager->createResource($resourceType, $resourceId); |
|
175 | - } |
|
176 | - |
|
177 | - if (!$resource->canAccess($this->userSession->getUser())) { |
|
178 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
179 | - } |
|
180 | - |
|
181 | - return new DataResponse($this->prepareCollections($resource->getCollections())); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @NoAdminRequired |
|
186 | - * |
|
187 | - * @param string $baseResourceType |
|
188 | - * @param string $baseResourceId |
|
189 | - * @param string $name |
|
190 | - * @return DataResponse |
|
191 | - */ |
|
192 | - public function createCollectionOnResource(string $baseResourceType, string $baseResourceId, string $name): DataResponse { |
|
193 | - if (!isset($name[0]) || isset($name[64])) { |
|
194 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
195 | - } |
|
196 | - |
|
197 | - try { |
|
198 | - $resource = $this->manager->createResource($baseResourceType, $baseResourceId); |
|
199 | - } catch (CollectionException $e) { |
|
200 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
201 | - } |
|
202 | - |
|
203 | - if (!$resource->canAccess($this->userSession->getUser())) { |
|
204 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
205 | - } |
|
206 | - |
|
207 | - $collection = $this->manager->newCollection($name); |
|
208 | - $collection->addResource($resource); |
|
209 | - |
|
210 | - return $this->respondCollection($collection); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @NoAdminRequired |
|
215 | - * |
|
216 | - * @param int $collectionId |
|
217 | - * @param string $collectionName |
|
218 | - * @return DataResponse |
|
219 | - */ |
|
220 | - public function renameCollection(int $collectionId, string $collectionName): DataResponse { |
|
221 | - try { |
|
222 | - $collection = $this->getCollection($collectionId); |
|
223 | - } catch (CollectionException $exception) { |
|
224 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
225 | - } |
|
226 | - |
|
227 | - $collection->setName($collectionName); |
|
228 | - |
|
229 | - return $this->respondCollection($collection); |
|
230 | - } |
|
231 | - |
|
232 | - protected function respondCollection(ICollection $collection): DataResponse { |
|
233 | - try { |
|
234 | - return new DataResponse($this->prepareCollection($collection)); |
|
235 | - } catch (CollectionException $e) { |
|
236 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
237 | - } catch (Exception $e) { |
|
238 | - $this->logger->logException($e); |
|
239 | - return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - protected function prepareCollections(array $collections): array { |
|
244 | - $result = []; |
|
245 | - |
|
246 | - foreach ($collections as $collection) { |
|
247 | - try { |
|
248 | - $result[] = $this->prepareCollection($collection); |
|
249 | - } catch (CollectionException $e) { |
|
250 | - } catch (Exception $e) { |
|
251 | - $this->logger->logException($e); |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - return $result; |
|
256 | - } |
|
257 | - |
|
258 | - protected function prepareCollection(ICollection $collection): array { |
|
259 | - if (!$collection->canAccess($this->userSession->getUser())) { |
|
260 | - throw new CollectionException('Can not access collection'); |
|
261 | - } |
|
262 | - |
|
263 | - return [ |
|
264 | - 'id' => $collection->getId(), |
|
265 | - 'name' => $collection->getName(), |
|
266 | - 'resources' => $this->prepareResources($collection->getResources()), |
|
267 | - ]; |
|
268 | - } |
|
269 | - |
|
270 | - protected function prepareResources(array $resources): ?array { |
|
271 | - $result = []; |
|
272 | - |
|
273 | - foreach ($resources as $resource) { |
|
274 | - try { |
|
275 | - $result[] = $this->prepareResource($resource); |
|
276 | - } catch (ResourceException $e) { |
|
277 | - } catch (Exception $e) { |
|
278 | - $this->logger->logException($e); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - return $result; |
|
283 | - } |
|
284 | - |
|
285 | - protected function prepareResource(IResource $resource): array { |
|
286 | - if (!$resource->canAccess($this->userSession->getUser())) { |
|
287 | - throw new ResourceException('Can not access resource'); |
|
288 | - } |
|
289 | - |
|
290 | - return $resource->getRichObject(); |
|
291 | - } |
|
40 | + /** @var IManager */ |
|
41 | + private $manager; |
|
42 | + /** @var IUserSession */ |
|
43 | + private $userSession; |
|
44 | + /** @var ILogger */ |
|
45 | + private $logger; |
|
46 | + |
|
47 | + public function __construct( |
|
48 | + string $appName, |
|
49 | + IRequest $request, |
|
50 | + IManager $manager, |
|
51 | + IUserSession $userSession, |
|
52 | + ILogger $logger |
|
53 | + ) { |
|
54 | + parent::__construct($appName, $request); |
|
55 | + |
|
56 | + $this->manager = $manager; |
|
57 | + $this->userSession = $userSession; |
|
58 | + $this->logger = $logger; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param int $collectionId |
|
63 | + * @return ICollection |
|
64 | + * @throws CollectionException when the collection was not found for the user |
|
65 | + */ |
|
66 | + protected function getCollection(int $collectionId): ICollection { |
|
67 | + $collection = $this->manager->getCollectionForUser($collectionId, $this->userSession->getUser()); |
|
68 | + |
|
69 | + if (!$collection->canAccess($this->userSession->getUser())) { |
|
70 | + throw new CollectionException('Not found'); |
|
71 | + } |
|
72 | + |
|
73 | + return $collection; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @NoAdminRequired |
|
78 | + * |
|
79 | + * @param int $collectionId |
|
80 | + * @return DataResponse |
|
81 | + */ |
|
82 | + public function listCollection(int $collectionId): DataResponse { |
|
83 | + try { |
|
84 | + $collection = $this->getCollection($collectionId); |
|
85 | + } catch (CollectionException $e) { |
|
86 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
87 | + } |
|
88 | + |
|
89 | + return $this->respondCollection($collection); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @NoAdminRequired |
|
94 | + * |
|
95 | + * @param string $filter |
|
96 | + * @return DataResponse |
|
97 | + */ |
|
98 | + public function searchCollections(string $filter): DataResponse { |
|
99 | + try { |
|
100 | + $collections = $this->manager->searchCollections($this->userSession->getUser(), $filter); |
|
101 | + } catch (CollectionException $e) { |
|
102 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
103 | + } |
|
104 | + |
|
105 | + return new DataResponse($this->prepareCollections($collections)); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @NoAdminRequired |
|
110 | + * |
|
111 | + * @param int $collectionId |
|
112 | + * @param string $resourceType |
|
113 | + * @param string $resourceId |
|
114 | + * @return DataResponse |
|
115 | + */ |
|
116 | + public function addResource(int $collectionId, string $resourceType, string $resourceId): DataResponse { |
|
117 | + try { |
|
118 | + $collection = $this->getCollection($collectionId); |
|
119 | + } catch (CollectionException $e) { |
|
120 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
121 | + } |
|
122 | + |
|
123 | + $resource = $this->manager->createResource($resourceType, $resourceId); |
|
124 | + |
|
125 | + if (!$resource->canAccess($this->userSession->getUser())) { |
|
126 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
127 | + } |
|
128 | + |
|
129 | + try { |
|
130 | + $collection->addResource($resource); |
|
131 | + } catch (ResourceException $e) { |
|
132 | + } |
|
133 | + |
|
134 | + return $this->respondCollection($collection); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @NoAdminRequired |
|
139 | + * |
|
140 | + * @param int $collectionId |
|
141 | + * @param string $resourceType |
|
142 | + * @param string $resourceId |
|
143 | + * @return DataResponse |
|
144 | + */ |
|
145 | + public function removeResource(int $collectionId, string $resourceType, string $resourceId): DataResponse { |
|
146 | + try { |
|
147 | + $collection = $this->getCollection($collectionId); |
|
148 | + } catch (CollectionException $e) { |
|
149 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
150 | + } |
|
151 | + |
|
152 | + try { |
|
153 | + $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser()); |
|
154 | + } catch (CollectionException $e) { |
|
155 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
156 | + } |
|
157 | + |
|
158 | + $collection->removeResource($resource); |
|
159 | + |
|
160 | + return $this->respondCollection($collection); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @NoAdminRequired |
|
165 | + * |
|
166 | + * @param string $resourceType |
|
167 | + * @param string $resourceId |
|
168 | + * @return DataResponse |
|
169 | + */ |
|
170 | + public function getCollectionsByResource(string $resourceType, string $resourceId): DataResponse { |
|
171 | + try { |
|
172 | + $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser()); |
|
173 | + } catch (ResourceException $e) { |
|
174 | + $resource = $this->manager->createResource($resourceType, $resourceId); |
|
175 | + } |
|
176 | + |
|
177 | + if (!$resource->canAccess($this->userSession->getUser())) { |
|
178 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
179 | + } |
|
180 | + |
|
181 | + return new DataResponse($this->prepareCollections($resource->getCollections())); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @NoAdminRequired |
|
186 | + * |
|
187 | + * @param string $baseResourceType |
|
188 | + * @param string $baseResourceId |
|
189 | + * @param string $name |
|
190 | + * @return DataResponse |
|
191 | + */ |
|
192 | + public function createCollectionOnResource(string $baseResourceType, string $baseResourceId, string $name): DataResponse { |
|
193 | + if (!isset($name[0]) || isset($name[64])) { |
|
194 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
195 | + } |
|
196 | + |
|
197 | + try { |
|
198 | + $resource = $this->manager->createResource($baseResourceType, $baseResourceId); |
|
199 | + } catch (CollectionException $e) { |
|
200 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
201 | + } |
|
202 | + |
|
203 | + if (!$resource->canAccess($this->userSession->getUser())) { |
|
204 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
205 | + } |
|
206 | + |
|
207 | + $collection = $this->manager->newCollection($name); |
|
208 | + $collection->addResource($resource); |
|
209 | + |
|
210 | + return $this->respondCollection($collection); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @NoAdminRequired |
|
215 | + * |
|
216 | + * @param int $collectionId |
|
217 | + * @param string $collectionName |
|
218 | + * @return DataResponse |
|
219 | + */ |
|
220 | + public function renameCollection(int $collectionId, string $collectionName): DataResponse { |
|
221 | + try { |
|
222 | + $collection = $this->getCollection($collectionId); |
|
223 | + } catch (CollectionException $exception) { |
|
224 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
225 | + } |
|
226 | + |
|
227 | + $collection->setName($collectionName); |
|
228 | + |
|
229 | + return $this->respondCollection($collection); |
|
230 | + } |
|
231 | + |
|
232 | + protected function respondCollection(ICollection $collection): DataResponse { |
|
233 | + try { |
|
234 | + return new DataResponse($this->prepareCollection($collection)); |
|
235 | + } catch (CollectionException $e) { |
|
236 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
237 | + } catch (Exception $e) { |
|
238 | + $this->logger->logException($e); |
|
239 | + return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + protected function prepareCollections(array $collections): array { |
|
244 | + $result = []; |
|
245 | + |
|
246 | + foreach ($collections as $collection) { |
|
247 | + try { |
|
248 | + $result[] = $this->prepareCollection($collection); |
|
249 | + } catch (CollectionException $e) { |
|
250 | + } catch (Exception $e) { |
|
251 | + $this->logger->logException($e); |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + return $result; |
|
256 | + } |
|
257 | + |
|
258 | + protected function prepareCollection(ICollection $collection): array { |
|
259 | + if (!$collection->canAccess($this->userSession->getUser())) { |
|
260 | + throw new CollectionException('Can not access collection'); |
|
261 | + } |
|
262 | + |
|
263 | + return [ |
|
264 | + 'id' => $collection->getId(), |
|
265 | + 'name' => $collection->getName(), |
|
266 | + 'resources' => $this->prepareResources($collection->getResources()), |
|
267 | + ]; |
|
268 | + } |
|
269 | + |
|
270 | + protected function prepareResources(array $resources): ?array { |
|
271 | + $result = []; |
|
272 | + |
|
273 | + foreach ($resources as $resource) { |
|
274 | + try { |
|
275 | + $result[] = $this->prepareResource($resource); |
|
276 | + } catch (ResourceException $e) { |
|
277 | + } catch (Exception $e) { |
|
278 | + $this->logger->logException($e); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + return $result; |
|
283 | + } |
|
284 | + |
|
285 | + protected function prepareResource(IResource $resource): array { |
|
286 | + if (!$resource->canAccess($this->userSession->getUser())) { |
|
287 | + throw new ResourceException('Can not access resource'); |
|
288 | + } |
|
289 | + |
|
290 | + return $resource->getRichObject(); |
|
291 | + } |
|
292 | 292 | } |
@@ -51,145 +51,145 @@ |
||
51 | 51 | interface IFullTextSearchManager { |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * Register a IProviderService. |
|
56 | - * |
|
57 | - * @since 15.0.0 |
|
58 | - * |
|
59 | - * @param IProviderService $providerService |
|
60 | - */ |
|
61 | - public function registerProviderService(IProviderService $providerService); |
|
62 | - |
|
63 | - /** |
|
64 | - * Register a IIndexService. |
|
65 | - * |
|
66 | - * @since 15.0.0 |
|
67 | - * |
|
68 | - * @param IIndexService $indexService |
|
69 | - */ |
|
70 | - public function registerIndexService(IIndexService $indexService); |
|
71 | - |
|
72 | - /** |
|
73 | - * Register a ISearchService. |
|
74 | - * |
|
75 | - * @since 15.0.0 |
|
76 | - * |
|
77 | - * @param ISearchService $searchService |
|
78 | - */ |
|
79 | - public function registerSearchService(ISearchService $searchService); |
|
80 | - |
|
81 | - /** |
|
82 | - * returns true is Full Text Search is available (app is present and Service |
|
83 | - * are registered) |
|
84 | - * |
|
85 | - * @since 16.0.0 |
|
86 | - * |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function isAvailable(): bool; |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Add the Javascript API in the navigation page of an app. |
|
94 | - * Needed to replace the default search. |
|
95 | - * |
|
96 | - * @since 15.0.0 |
|
97 | - */ |
|
98 | - public function addJavascriptAPI(); |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Check if the provider $providerId is already indexed. |
|
103 | - * |
|
104 | - * @since 15.0.0 |
|
105 | - * |
|
106 | - * @param string $providerId |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public function isProviderIndexed(string $providerId): bool; |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Retrieve an Index from the database, based on the Id of the Provider |
|
115 | - * and the Id of the Document |
|
116 | - * |
|
117 | - * @since 15.0.0 |
|
118 | - * |
|
119 | - * @param string $providerId |
|
120 | - * @param string $documentId |
|
121 | - * |
|
122 | - * @return IIndex |
|
123 | - */ |
|
124 | - public function getIndex(string $providerId, string $documentId): IIndex; |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Create a new Index. |
|
129 | - * |
|
130 | - * This method must be called when a new document is created. |
|
131 | - * |
|
132 | - * @since 15.0.0 |
|
133 | - * |
|
134 | - * @param string $providerId |
|
135 | - * @param string $documentId |
|
136 | - * @param string $userId |
|
137 | - * @param int $status |
|
138 | - * |
|
139 | - * @return IIndex |
|
140 | - */ |
|
141 | - public function createIndex(string $providerId, string $documentId, string $userId, int $status = 0): IIndex; |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Update the status of an Index. status is a bitflag, setting $reset to |
|
146 | - * true will reset the status to the value defined in the parameter. |
|
147 | - * |
|
148 | - * @since 15.0.0 |
|
149 | - * |
|
150 | - * @param string $providerId |
|
151 | - * @param string $documentId |
|
152 | - * @param int $status |
|
153 | - * @param bool $reset |
|
154 | - */ |
|
155 | - public function updateIndexStatus(string $providerId, string $documentId, int $status, bool $reset = false); |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Update the status of an array of Index. status is a bit flag, setting $reset to |
|
160 | - * true will reset the status to the value defined in the parameter. |
|
161 | - * |
|
162 | - * @since 15.0.0 |
|
163 | - * |
|
164 | - * @param string $providerId |
|
165 | - * @param array $documentIds |
|
166 | - * @param int $status |
|
167 | - * @param bool $reset |
|
168 | - */ |
|
169 | - public function updateIndexesStatus(string $providerId, array $documentIds, int $status, bool $reset = false); |
|
170 | - |
|
171 | - /** |
|
172 | - * Update an array of Index. |
|
173 | - * |
|
174 | - * @since 15.0.0 |
|
175 | - * |
|
176 | - * @param IIndex[] $indexes |
|
177 | - */ |
|
178 | - public function updateIndexes(array $indexes); |
|
179 | - |
|
180 | - /** |
|
181 | - * Search using an array as request. If $userId is empty, will use the |
|
182 | - * current session. |
|
183 | - * |
|
184 | - * @see ISearchService::generateSearchRequest |
|
185 | - * |
|
186 | - * @since 15.0.0 |
|
187 | - * |
|
188 | - * @param array $request |
|
189 | - * @param string $userId |
|
190 | - * @return ISearchResult[] |
|
191 | - */ |
|
192 | - public function search(array $request, string $userId = ''): array; |
|
54 | + /** |
|
55 | + * Register a IProviderService. |
|
56 | + * |
|
57 | + * @since 15.0.0 |
|
58 | + * |
|
59 | + * @param IProviderService $providerService |
|
60 | + */ |
|
61 | + public function registerProviderService(IProviderService $providerService); |
|
62 | + |
|
63 | + /** |
|
64 | + * Register a IIndexService. |
|
65 | + * |
|
66 | + * @since 15.0.0 |
|
67 | + * |
|
68 | + * @param IIndexService $indexService |
|
69 | + */ |
|
70 | + public function registerIndexService(IIndexService $indexService); |
|
71 | + |
|
72 | + /** |
|
73 | + * Register a ISearchService. |
|
74 | + * |
|
75 | + * @since 15.0.0 |
|
76 | + * |
|
77 | + * @param ISearchService $searchService |
|
78 | + */ |
|
79 | + public function registerSearchService(ISearchService $searchService); |
|
80 | + |
|
81 | + /** |
|
82 | + * returns true is Full Text Search is available (app is present and Service |
|
83 | + * are registered) |
|
84 | + * |
|
85 | + * @since 16.0.0 |
|
86 | + * |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function isAvailable(): bool; |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Add the Javascript API in the navigation page of an app. |
|
94 | + * Needed to replace the default search. |
|
95 | + * |
|
96 | + * @since 15.0.0 |
|
97 | + */ |
|
98 | + public function addJavascriptAPI(); |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Check if the provider $providerId is already indexed. |
|
103 | + * |
|
104 | + * @since 15.0.0 |
|
105 | + * |
|
106 | + * @param string $providerId |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public function isProviderIndexed(string $providerId): bool; |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Retrieve an Index from the database, based on the Id of the Provider |
|
115 | + * and the Id of the Document |
|
116 | + * |
|
117 | + * @since 15.0.0 |
|
118 | + * |
|
119 | + * @param string $providerId |
|
120 | + * @param string $documentId |
|
121 | + * |
|
122 | + * @return IIndex |
|
123 | + */ |
|
124 | + public function getIndex(string $providerId, string $documentId): IIndex; |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Create a new Index. |
|
129 | + * |
|
130 | + * This method must be called when a new document is created. |
|
131 | + * |
|
132 | + * @since 15.0.0 |
|
133 | + * |
|
134 | + * @param string $providerId |
|
135 | + * @param string $documentId |
|
136 | + * @param string $userId |
|
137 | + * @param int $status |
|
138 | + * |
|
139 | + * @return IIndex |
|
140 | + */ |
|
141 | + public function createIndex(string $providerId, string $documentId, string $userId, int $status = 0): IIndex; |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Update the status of an Index. status is a bitflag, setting $reset to |
|
146 | + * true will reset the status to the value defined in the parameter. |
|
147 | + * |
|
148 | + * @since 15.0.0 |
|
149 | + * |
|
150 | + * @param string $providerId |
|
151 | + * @param string $documentId |
|
152 | + * @param int $status |
|
153 | + * @param bool $reset |
|
154 | + */ |
|
155 | + public function updateIndexStatus(string $providerId, string $documentId, int $status, bool $reset = false); |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Update the status of an array of Index. status is a bit flag, setting $reset to |
|
160 | + * true will reset the status to the value defined in the parameter. |
|
161 | + * |
|
162 | + * @since 15.0.0 |
|
163 | + * |
|
164 | + * @param string $providerId |
|
165 | + * @param array $documentIds |
|
166 | + * @param int $status |
|
167 | + * @param bool $reset |
|
168 | + */ |
|
169 | + public function updateIndexesStatus(string $providerId, array $documentIds, int $status, bool $reset = false); |
|
170 | + |
|
171 | + /** |
|
172 | + * Update an array of Index. |
|
173 | + * |
|
174 | + * @since 15.0.0 |
|
175 | + * |
|
176 | + * @param IIndex[] $indexes |
|
177 | + */ |
|
178 | + public function updateIndexes(array $indexes); |
|
179 | + |
|
180 | + /** |
|
181 | + * Search using an array as request. If $userId is empty, will use the |
|
182 | + * current session. |
|
183 | + * |
|
184 | + * @see ISearchService::generateSearchRequest |
|
185 | + * |
|
186 | + * @since 15.0.0 |
|
187 | + * |
|
188 | + * @param array $request |
|
189 | + * @param string $userId |
|
190 | + * @return ISearchResult[] |
|
191 | + */ |
|
192 | + public function search(array $request, string $userId = ''): array; |
|
193 | 193 | |
194 | 194 | |
195 | 195 | } |