Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 282 |
|
0.00% |
0 / 27 |
CRAP | |
0.00% |
0 / 1 |
Lists | |
0.00% |
0 / 282 |
|
0.00% |
0 / 27 |
4692 | |
0.00% |
0 / 1 |
index | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
remote | |
0.00% |
0 / 40 |
|
0.00% |
0 / 1 |
56 | |||
reloadRemoteList | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
20 | |||
sync | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
getListsData | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
getListElements | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
saveLists | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
20 | |||
create | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
56 | |||
rename | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
removeList | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
removeListElement | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
createList | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
6 | |||
getListData | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
getSortedElementsDependingOnListClass | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
createRemoteSourceContext | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
6 | |||
createListElementsFinderContext | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
isListsDependencyEnabled | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
assertIsXmlHttpRequest | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getFeatureFlagChecker | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getListService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getListCreator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getListElementsFinder | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getListUpdater | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getListDeleter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLanguageClassSpecification | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLanguageListElementSortService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOntology | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
19 | * (under the project TAO & TAO2); |
20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
21 | * (under the project TAO-TRANSFER); |
22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
24 | * 2013-2022 (update and modification) Open Assessment Technologies SA; |
25 | */ |
26 | |
27 | declare(strict_types=1); |
28 | |
29 | namespace oat\taoBackOffice\controller; |
30 | |
31 | use oat\generis\model\data\Ontology; |
32 | use oat\tao\helpers\Template; |
33 | use oat\tao\model\featureFlag\FeatureFlagChecker; |
34 | use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; |
35 | use oat\tao\model\http\HttpJsonResponseTrait; |
36 | use oat\tao\model\Language\Business\Specification\LanguageClassSpecification; |
37 | use oat\tao\model\Language\Service\LanguageListElementSortService; |
38 | use oat\tao\model\Lists\Business\Contract\ListElementSorterInterface; |
39 | use oat\tao\model\Lists\Business\Domain\CollectionType; |
40 | use oat\tao\model\Lists\Business\Domain\ValueCollection; |
41 | use oat\tao\model\Lists\Business\Domain\RemoteSourceContext; |
42 | use oat\tao\model\Lists\Business\Service\RemoteSource; |
43 | use oat\tao\model\Lists\Business\Service\RemoteSourcedListOntology; |
44 | use oat\tao\model\Lists\Business\Service\ValueCollectionService; |
45 | use oat\tao\model\Lists\DataAccess\Repository\ValueConflictException; |
46 | use oat\tao\model\Specification\ClassSpecificationInterface; |
47 | use oat\taoBackOffice\model\lists\Contract\ListDeleterInterface; |
48 | use oat\taoBackOffice\model\lists\Contract\ListUpdaterInterface; |
49 | use oat\taoBackOffice\model\lists\Exception\ListDeletionException; |
50 | use oat\taoBackOffice\model\lists\Service\ListDeleter; |
51 | use oat\taoBackOffice\model\lists\Service\ListUpdater; |
52 | use oat\taoBackOffice\model\lists\ListCreatedResponse; |
53 | use oat\taoBackOffice\model\lists\ListCreator; |
54 | use oat\taoBackOffice\model\lists\ListService; |
55 | use oat\taoBackOffice\model\ListElement\Context\ListElementsFinderContext; |
56 | use oat\taoBackOffice\model\ListElement\Contract\ListElementsFinderInterface; |
57 | use oat\taoBackOffice\model\ListElement\Service\ListElementsFinder; |
58 | use BadFunctionCallException; |
59 | use common_Exception; |
60 | use common_exception_BadRequest; |
61 | use common_exception_Error; |
62 | use common_ext_ExtensionException; |
63 | use core_kernel_classes_Class; |
64 | use core_kernel_persistence_Exception; |
65 | use tao_actions_CommonModule; |
66 | use tao_actions_form_RemoteList; |
67 | use tao_helpers_Scriptloader; |
68 | use tao_helpers_Uri; |
69 | use OverflowException; |
70 | use RuntimeException; |
71 | use Throwable; |
72 | |
73 | class Lists extends tao_actions_CommonModule |
74 | { |
75 | use HttpJsonResponseTrait; |
76 | |
77 | /** @var bool */ |
78 | private $isListsDependencyEnabled; |
79 | |
80 | /** |
81 | * This REST endpoint: |
82 | * - Returns the page with the lists for GET requests |
83 | * - Creates a new list and returns its name and URI for POST requests |
84 | * |
85 | * @throws common_Exception |
86 | * @throws common_ext_ExtensionException |
87 | * @throws core_kernel_persistence_Exception |
88 | */ |
89 | public function index(): void |
90 | { |
91 | if ($this->getPsrRequest()->getMethod() === 'POST') { |
92 | $this->assertIsXmlHttpRequest(); |
93 | |
94 | $createdResponse = $this->getListCreator()->createEmptyList(); |
95 | $this->setSuccessJsonResponse($createdResponse, 201); |
96 | |
97 | return; |
98 | } |
99 | |
100 | tao_helpers_Scriptloader::addCssFile(Template::css('lists.css', 'tao')); |
101 | $this->defaultData(); |
102 | |
103 | $this->setData('lists', $this->getListData()); |
104 | $this->setData('maxItems', $this->getListService()->getMaxItems()); |
105 | $this->setView('Lists/index.tpl'); |
106 | } |
107 | |
108 | /** |
109 | * @throws common_Exception |
110 | * @throws common_ext_ExtensionException |
111 | * @throws core_kernel_persistence_Exception |
112 | */ |
113 | public function remote(ValueCollectionService $valueCollectionService, RemoteSource $remoteSource): void |
114 | { |
115 | tao_helpers_Scriptloader::addCssFile(Template::css('lists.css', 'tao')); |
116 | |
117 | $this->defaultData(); |
118 | |
119 | $remoteListFormFactory = new tao_actions_form_RemoteList( |
120 | [], |
121 | [ |
122 | tao_actions_form_RemoteList::IS_LISTS_DEPENDENCY_ENABLED => $this->isListsDependencyEnabled(), |
123 | ] |
124 | ); |
125 | $remoteListForm = $remoteListFormFactory->getForm(); |
126 | |
127 | if ($remoteListForm === null) { |
128 | throw new RuntimeException('Impossible to create remote sourced list form'); |
129 | } |
130 | |
131 | if ($remoteListForm->isSubmited()) { |
132 | if ($remoteListForm->isValid()) { |
133 | $values = $remoteListForm->getValues(); |
134 | $newList = $this->createList($values); |
135 | |
136 | try { |
137 | $this->sync($valueCollectionService, $remoteSource, $newList); |
138 | $listElements = $this->getListElementsFinder()->find( |
139 | $this->createListElementsFinderContext($newList) |
140 | ); |
141 | |
142 | $this->setSuccessJsonResponse( |
143 | new ListCreatedResponse( |
144 | $newList, |
145 | $listElements->jsonSerialize(), |
146 | $listElements->getTotalCount() |
147 | ), |
148 | 201 |
149 | ); |
150 | |
151 | return; |
152 | } catch (ValueConflictException $exception) { |
153 | $this->setErrorJsonResponse($exception->getUserMessage()); |
154 | |
155 | return; |
156 | } catch (RuntimeException $exception) { |
157 | throw $exception; |
158 | } finally { |
159 | if (isset($exception)) { |
160 | $this->getListDeleter()->delete($newList); |
161 | } |
162 | } |
163 | } |
164 | } else { |
165 | $newListLabel = __('List') . ' ' . (count($this->getListService()->getLists()) + 1); |
166 | $remoteListForm->getElement(tao_actions_form_RemoteList::FIELD_NAME)->setValue($newListLabel); |
167 | } |
168 | |
169 | $this->setData('form', $remoteListForm->render()); |
170 | $this->setData('lists', $this->getListData(true)); |
171 | $this->setView('RemoteLists/index.tpl'); |
172 | } |
173 | |
174 | /** |
175 | * @throws common_Exception |
176 | */ |
177 | public function reloadRemoteList(ValueCollectionService $valueCollectionService, RemoteSource $remoteSource): void |
178 | { |
179 | $this->assertIsXmlHttpRequest(); |
180 | |
181 | $saved = false; |
182 | $message = __('Attempt for reloading of remote list was not successful'); |
183 | |
184 | $uri = $_POST['uri'] ?? null; |
185 | |
186 | if ($uri !== null) { |
187 | try { |
188 | $this->sync( |
189 | $valueCollectionService, |
190 | $remoteSource, |
191 | $this->getListService()->getList(tao_helpers_Uri::decode($uri)), |
192 | true |
193 | ); |
194 | |
195 | $saved = true; |
196 | $message = __('Remote list was successfully reloaded'); |
197 | } catch (Throwable $exception) { |
198 | if ($exception instanceof ValueConflictException) { |
199 | $message = $exception->getUserMessage(); |
200 | } |
201 | } |
202 | } |
203 | |
204 | $this->returnJson([ |
205 | 'saved' => $saved, |
206 | 'message' => $message, |
207 | ]); |
208 | } |
209 | |
210 | private function sync( |
211 | ValueCollectionService $valueCollectionService, |
212 | RemoteSource $remoteSource, |
213 | core_kernel_classes_Class $collectionClass, |
214 | bool $isReloading = false |
215 | ): void { |
216 | $context = $this->createRemoteSourceContext($collectionClass); |
217 | $collection = new ValueCollection( |
218 | $collectionClass->getUri(), |
219 | ...iterator_to_array($remoteSource->fetchByContext($context)) |
220 | ); |
221 | |
222 | $result = $valueCollectionService->persist($collection); |
223 | |
224 | if (!$result) { |
225 | throw new RuntimeException( |
226 | sprintf( |
227 | 'Attempt for %s of remote list was not successful', |
228 | $isReloading ? 'reloading' : 'loading' |
229 | ) |
230 | ); |
231 | } |
232 | } |
233 | |
234 | /** |
235 | * @throws common_Exception |
236 | * @throws common_exception_Error |
237 | */ |
238 | public function getListsData(): void |
239 | { |
240 | $this->assertIsXmlHttpRequest(); |
241 | |
242 | $data = []; |
243 | |
244 | foreach ($this->getListService()->getLists() as $listClass) { |
245 | $data[] = $this->getListService()->toTree($listClass); |
246 | } |
247 | |
248 | $this->returnJson( |
249 | [ |
250 | 'data' => __('Lists'), |
251 | 'attributes' => ['class' => 'node-root'], |
252 | 'children' => $data, |
253 | 'state' => 'open', |
254 | ] |
255 | ); |
256 | } |
257 | |
258 | /** |
259 | * @throws common_Exception |
260 | */ |
261 | public function getListElements(): void |
262 | { |
263 | $this->assertIsXmlHttpRequest(); |
264 | |
265 | $data = [ |
266 | 'elements' => [], |
267 | 'totalCount' => 0, |
268 | ]; |
269 | |
270 | if ($this->hasGetParameter('listUri')) { |
271 | $listUri = tao_helpers_Uri::decode($this->getGetParameter('listUri')); |
272 | $list = $this->getListService()->getList($listUri); |
273 | |
274 | if ($list !== null) { |
275 | $listElements = $this->getListElementsFinder()->find( |
276 | $this->createListElementsFinderContext($list) |
277 | ); |
278 | |
279 | $data['elements'] = $this->getSortedElementsDependingOnListClass($list, $listElements); |
280 | $data['totalCount'] = $listElements->getTotalCount(); |
281 | } |
282 | } |
283 | |
284 | $this->setSuccessJsonResponse($data); |
285 | } |
286 | |
287 | /** |
288 | * @throws common_exception_BadRequest |
289 | * |
290 | * @todo Use $this->setSuccessJsonResponse() & setErrorJsonResponse() |
291 | * instead of returnJson(). For that, frontend should access |
292 | * 'success' attribute from the response instead of 'saved' |
293 | */ |
294 | public function saveLists(ValueCollectionService $valueCollectionService): void |
295 | { |
296 | $this->assertIsXmlHttpRequest(); |
297 | |
298 | $valueCollectionService->setMaxItems( |
299 | $this->getListService()->getMaxItems() |
300 | ); |
301 | |
302 | try { |
303 | $this->getListUpdater()->updateByRequest($this->getPsrRequest()); |
304 | |
305 | $this->returnJson( |
306 | [ |
307 | 'saved' => true |
308 | ] |
309 | ); |
310 | } catch (BadFunctionCallException | RuntimeException $exception) { |
311 | $this->returnJson( |
312 | [ |
313 | 'saved' => false, |
314 | 'errors' => [ |
315 | __($exception->getMessage()), |
316 | ], |
317 | ] |
318 | ); |
319 | } catch (OverflowException $exception) { |
320 | $this->returnJson( |
321 | [ |
322 | 'saved' => false, |
323 | 'errors' => [ |
324 | __('The list exceeds the allowed number of items'), |
325 | ], |
326 | ] |
327 | ); |
328 | } catch (ValueConflictException $exception) { |
329 | $this->returnJson( |
330 | [ |
331 | 'saved' => false, |
332 | 'errors' => [ |
333 | __('The list should contain unique URIs'), |
334 | ], |
335 | ] |
336 | ); |
337 | } |
338 | } |
339 | |
340 | /** |
341 | * @throws common_Exception |
342 | * @throws core_kernel_persistence_Exception |
343 | */ |
344 | public function create(): void |
345 | { |
346 | $this->assertIsXmlHttpRequest(); |
347 | |
348 | $response = []; |
349 | |
350 | if ($this->hasRequestParameter('classUri')) { |
351 | $listService = $this->getListService(); |
352 | $type = $this->getRequestParameter('type'); |
353 | |
354 | if ($type === 'class' && $this->getRequestParameter('classUri') === 'root') { |
355 | $createdResource = $listService->createList(); |
356 | } elseif ($type === 'instance') { |
357 | $classUri = tao_helpers_Uri::decode($this->getRequestParameter('classUri')); |
358 | $listClass = $listService->getList($classUri); |
359 | |
360 | if ($listClass !== null) { |
361 | $listService->createListElement($listClass); |
362 | $createdResource = iterator_to_array($listService->getListElements($listClass))[0] ?? null; |
363 | } |
364 | } |
365 | |
366 | if (isset($createdResource)) { |
367 | $response['label'] = $createdResource->getLabel(); |
368 | $response['uri'] = tao_helpers_Uri::encode($createdResource->getUri()); |
369 | } |
370 | } |
371 | |
372 | $this->returnJson($response); |
373 | } |
374 | |
375 | /** |
376 | * @throws common_exception_BadRequest |
377 | */ |
378 | public function rename(): void |
379 | { |
380 | $this->assertIsXmlHttpRequest(); |
381 | |
382 | $data = ['renamed' => false]; |
383 | |
384 | if ($this->hasRequestParameter('uri') && $this->hasRequestParameter('newName')) { |
385 | $listService = $this->getListService(); |
386 | $newName = $this->getRequestParameter('newName'); |
387 | |
388 | if ($this->hasRequestParameter('classUri')) { |
389 | $classUri = tao_helpers_Uri::decode($this->getRequestParameter('classUri')); |
390 | $listClass = $listService->getList($classUri); |
391 | $resourceToRename = $listService->getListElement( |
392 | $listClass, |
393 | tao_helpers_Uri::decode($this->getRequestParameter('uri')) |
394 | ); |
395 | } else { |
396 | $classUri = tao_helpers_Uri::decode($this->getRequestParameter('uri')); |
397 | $resourceToRename = $listService->getList($classUri); |
398 | } |
399 | |
400 | if ($resourceToRename !== null) { |
401 | $resourceToRename->setLabel($newName); |
402 | $data['renamed'] = true; |
403 | } |
404 | } |
405 | |
406 | $this->returnJson($data); |
407 | } |
408 | |
409 | /** |
410 | * @throws common_exception_BadRequest |
411 | */ |
412 | public function removeList(string $uri = null): void |
413 | { |
414 | $this->assertIsXmlHttpRequest(); |
415 | |
416 | $deleted = false; |
417 | |
418 | if ($uri !== null) { |
419 | try { |
420 | $list = $this->getListService()->getList(tao_helpers_Uri::decode($uri)); |
421 | $this->getListDeleter()->delete($list); |
422 | |
423 | $deleted = true; |
424 | } catch (ListDeletionException $exception) { |
425 | $deleted = false; |
426 | } |
427 | } |
428 | |
429 | $this->returnJson(['deleted' => $deleted]); |
430 | } |
431 | |
432 | /** |
433 | * @throws common_exception_BadRequest |
434 | */ |
435 | public function removeListElement(): void |
436 | { |
437 | $this->assertIsXmlHttpRequest(); |
438 | |
439 | $deleted = false; |
440 | |
441 | if ($this->hasRequestParameter('uri')) { |
442 | $deleted = $this->getListService()->removeListElement( |
443 | $this->getOntology()->getResource( |
444 | tao_helpers_Uri::decode($this->getRequestParameter('uri')) |
445 | ) |
446 | ); |
447 | } |
448 | |
449 | $this->returnJson(['deleted' => $deleted]); |
450 | } |
451 | |
452 | private function createList(array $values): core_kernel_classes_Class |
453 | { |
454 | $class = $this->getListService()->createList($values[tao_actions_form_RemoteList::FIELD_NAME]); |
455 | |
456 | $propertyType = $class->getProperty(CollectionType::TYPE_PROPERTY); |
457 | $propertyRemote = $class->getProperty((string) CollectionType::remote()); |
458 | $class->setPropertyValue($propertyType, $propertyRemote); |
459 | |
460 | $propertySource = $class->getProperty(RemoteSourcedListOntology::PROPERTY_SOURCE_URI); |
461 | $class->setPropertyValue($propertySource, $values[tao_actions_form_RemoteList::FIELD_SOURCE_URL]); |
462 | |
463 | $propertySource = $class->getProperty(RemoteSourcedListOntology::PROPERTY_ITEM_LABEL_PATH); |
464 | $class->setPropertyValue($propertySource, $values[tao_actions_form_RemoteList::FIELD_ITEM_LABEL_PATH]); |
465 | |
466 | $propertySource = $class->getProperty(RemoteSourcedListOntology::PROPERTY_ITEM_URI_PATH); |
467 | $class->setPropertyValue($propertySource, $values[tao_actions_form_RemoteList::FIELD_ITEM_URI_PATH]); |
468 | |
469 | if ($this->isListsDependencyEnabled()) { |
470 | $propertySource = $class->getProperty(RemoteSourcedListOntology::PROPERTY_DEPENDENCY_ITEM_URI_PATH); |
471 | $class->setPropertyValue( |
472 | $propertySource, |
473 | $values[tao_actions_form_RemoteList::FIELD_DEPENDENCY_ITEM_URI_PATH] |
474 | ); |
475 | } |
476 | |
477 | return $class; |
478 | } |
479 | |
480 | /** |
481 | * @throws core_kernel_persistence_Exception |
482 | */ |
483 | private function getListData(bool $showRemoteLists = false): array |
484 | { |
485 | $listService = $this->getListService(); |
486 | $listElementsFinder = $this->getListElementsFinder(); |
487 | $lists = []; |
488 | |
489 | foreach ($listService->getLists() as $listClass) { |
490 | if ($listService->isRemote($listClass) !== $showRemoteLists) { |
491 | continue; |
492 | } |
493 | |
494 | $listElements = $listElementsFinder->find($this->createListElementsFinderContext($listClass)); |
495 | |
496 | $lists[] = [ |
497 | 'uri' => tao_helpers_Uri::encode($listClass->getUri()), |
498 | 'label' => $listClass->getLabel(), |
499 | 'editable' => $listService->isEditable($listClass), |
500 | 'elements' => $this->getSortedElementsDependingOnListClass($listClass, $listElements), |
501 | 'totalCount' => $listElements->getTotalCount(), |
502 | ]; |
503 | } |
504 | |
505 | return $lists; |
506 | } |
507 | |
508 | private function getSortedElementsDependingOnListClass( |
509 | core_kernel_classes_Class $listClass, |
510 | ValueCollection $listElements |
511 | ): array { |
512 | if ($this->getLanguageClassSpecification()->isSatisfiedBy($listClass)) { |
513 | return $this->getLanguageListElementSortService()->getSortedListCollectionValues($listElements); |
514 | } |
515 | |
516 | return $listElements->jsonSerialize(); |
517 | } |
518 | |
519 | private function createRemoteSourceContext(core_kernel_classes_Class $collectionClass): RemoteSourceContext |
520 | { |
521 | $sourceUrl = (string) $collectionClass->getOnePropertyValue( |
522 | $collectionClass->getProperty(RemoteSourcedListOntology::PROPERTY_SOURCE_URI) |
523 | ); |
524 | $uriPath = (string) $collectionClass->getOnePropertyValue( |
525 | $collectionClass->getProperty(RemoteSourcedListOntology::PROPERTY_ITEM_URI_PATH) |
526 | ); |
527 | $labelPath = (string) $collectionClass->getOnePropertyValue( |
528 | $collectionClass->getProperty(RemoteSourcedListOntology::PROPERTY_ITEM_LABEL_PATH) |
529 | ); |
530 | |
531 | $parameters = [ |
532 | RemoteSourceContext::PARAM_SOURCE_URL => $sourceUrl, |
533 | RemoteSourceContext::PARAM_URI_PATH => $uriPath, |
534 | RemoteSourceContext::PARAM_LABEL_PATH => $labelPath, |
535 | RemoteSourceContext::PARAM_PARSER => 'jsonpath', |
536 | ]; |
537 | |
538 | if ($this->isListsDependencyEnabled()) { |
539 | $dependencyUriPath = (string) $collectionClass->getOnePropertyValue( |
540 | $collectionClass->getProperty(RemoteSourcedListOntology::PROPERTY_DEPENDENCY_ITEM_URI_PATH) |
541 | ); |
542 | $parameters[RemoteSourceContext::PARAM_DEPENDENCY_URI_PATH] = $dependencyUriPath; |
543 | } |
544 | |
545 | return new RemoteSourceContext($parameters); |
546 | } |
547 | |
548 | private function createListElementsFinderContext(core_kernel_classes_Class $listClass): ListElementsFinderContext |
549 | { |
550 | $parameters = [ |
551 | ListElementsFinderContext::PARAMETER_LIST_CLASS => $listClass, |
552 | ]; |
553 | |
554 | if ($this->hasGetParameter('offset')) { |
555 | $parameters[ListElementsFinderContext::PARAMETER_OFFSET] = (int) $this->getGetParameter('offset'); |
556 | } |
557 | |
558 | if ($this->hasGetParameter('limit')) { |
559 | $parameters[ListElementsFinderContext::PARAMETER_LIMIT] = (int) $this->getGetParameter('limit'); |
560 | } |
561 | |
562 | // Todo to be able to sort limited selection we need to sort by RDBS now disabling limit for Language list |
563 | if ($this->getLanguageClassSpecification()->isSatisfiedBy($listClass)) { |
564 | $parameters[ListElementsFinderContext::PARAMETER_LIMIT] = 0; |
565 | } |
566 | |
567 | return new ListElementsFinderContext($parameters); |
568 | } |
569 | |
570 | private function isListsDependencyEnabled(): bool |
571 | { |
572 | if (!isset($this->isListsDependencyEnabled)) { |
573 | $this->isListsDependencyEnabled = $this->getFeatureFlagChecker()->isEnabled( |
574 | FeatureFlagCheckerInterface::FEATURE_FLAG_LISTS_DEPENDENCY_ENABLED |
575 | ); |
576 | } |
577 | |
578 | return $this->isListsDependencyEnabled; |
579 | } |
580 | |
581 | private function assertIsXmlHttpRequest(): void |
582 | { |
583 | if (!$this->isXmlHttpRequest()) { |
584 | throw new common_exception_BadRequest('wrong request mode'); |
585 | } |
586 | } |
587 | |
588 | private function getFeatureFlagChecker(): FeatureFlagCheckerInterface |
589 | { |
590 | return $this->getPsrContainer()->get(FeatureFlagChecker::class); |
591 | } |
592 | |
593 | private function getListService(): ListService |
594 | { |
595 | return $this->getPsrContainer()->get(ListService::class); |
596 | } |
597 | |
598 | private function getListCreator(): ListCreator |
599 | { |
600 | return $this->getPsrContainer()->get(ListCreator::class); |
601 | } |
602 | |
603 | private function getListElementsFinder(): ListElementsFinderInterface |
604 | { |
605 | return $this->getPsrContainer()->get(ListElementsFinder::class); |
606 | } |
607 | |
608 | private function getListUpdater(): ListUpdaterInterface |
609 | { |
610 | return $this->getPsrContainer()->get(ListUpdater::class); |
611 | } |
612 | |
613 | private function getListDeleter(): ListDeleterInterface |
614 | { |
615 | return $this->getPsrContainer()->get(ListDeleter::class); |
616 | } |
617 | |
618 | private function getLanguageClassSpecification(): ClassSpecificationInterface |
619 | { |
620 | return $this->getPsrContainer()->get(LanguageClassSpecification::class); |
621 | } |
622 | |
623 | private function getLanguageListElementSortService(): ListElementSorterInterface |
624 | { |
625 | return $this->getPsrContainer()->get(LanguageListElementSortService::class); |
626 | } |
627 | |
628 | private function getOntology(): Ontology |
629 | { |
630 | return $this->getPsrContainer()->get(Ontology::SERVICE_ID); |
631 | } |
632 | } |