| Total Complexity | 56 |
| Total Lines | 666 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like SearchController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SearchController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class SearchController extends \EWW\Dpf\Controller\AbstractController |
||
| 30 | { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * documentRepository |
||
| 34 | * |
||
| 35 | * @var \EWW\Dpf\Domain\Repository\DocumentRepository |
||
| 36 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 37 | */ |
||
| 38 | protected $documentRepository = null; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * documenTypeRepository |
||
| 42 | * |
||
| 43 | * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
||
| 44 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 45 | */ |
||
| 46 | protected $documentTypeRepository; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * clientRepository |
||
| 50 | * |
||
| 51 | * @var \EWW\Dpf\Domain\Repository\ClientRepository |
||
| 52 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 53 | */ |
||
| 54 | protected $clientRepository = null; |
||
| 55 | |||
| 56 | |||
| 57 | /** |
||
| 58 | * elasticSearch |
||
| 59 | * |
||
| 60 | * @var \EWW\Dpf\Services\ElasticSearch\ElasticSearch |
||
| 61 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 62 | */ |
||
| 63 | protected $elasticSearch = null; |
||
| 64 | |||
| 65 | |||
| 66 | /** |
||
| 67 | * queryBuilder |
||
| 68 | * |
||
| 69 | * @var \EWW\Dpf\Services\ElasticSearch\QueryBuilder |
||
| 70 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 71 | */ |
||
| 72 | protected $queryBuilder = null; |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * persistence manager |
||
| 77 | * |
||
| 78 | * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface |
||
| 79 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 80 | */ |
||
| 81 | protected $persistenceManager; |
||
| 82 | |||
| 83 | |||
| 84 | /** |
||
| 85 | * bookmarkRepository |
||
| 86 | * |
||
| 87 | * @var \EWW\Dpf\Domain\Repository\BookmarkRepository |
||
| 88 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 89 | */ |
||
| 90 | protected $bookmarkRepository = null; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * fisDataService |
||
| 94 | * |
||
| 95 | * @var \EWW\Dpf\Services\FeUser\FisDataService |
||
| 96 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 97 | */ |
||
| 98 | protected $fisDataService = null; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * metadataGroupRepository |
||
| 102 | * |
||
| 103 | * @var \EWW\Dpf\Domain\Repository\MetadataGroupRepository |
||
| 104 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 105 | */ |
||
| 106 | protected $metadataGroupRepository; |
||
| 107 | |||
| 108 | const RESULT_COUNT = 500; |
||
| 109 | const NEXT_RESULT_COUNT = 500; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * list |
||
| 113 | * |
||
| 114 | * @param int $from |
||
| 115 | * @param int $queryString |
||
| 116 | * |
||
| 117 | * @return void |
||
| 118 | */ |
||
| 119 | protected function list($from = 0, $queryString = '') |
||
| 120 | { |
||
| 121 | /** @var SearchSessionData $workspaceSessionData */ |
||
| 122 | $workspaceSessionData = $this->session->getWorkspaceData(); |
||
| 123 | $filters = $workspaceSessionData->getFilters(); |
||
| 124 | $excludeFilters = $workspaceSessionData->getExcludeFilters(); |
||
| 125 | |||
| 126 | if (array_key_exists('bookmarks', $excludeFilters)) { |
||
| 127 | unset($excludeFilters['bookmarks']); |
||
| 128 | } |
||
| 129 | |||
| 130 | $sortField = $workspaceSessionData->getSortField(); |
||
| 131 | $sortOrder = $workspaceSessionData->getSortOrder(); |
||
| 132 | |||
| 133 | if ($this->security->getUserRole() == Security::ROLE_LIBRARIAN) { |
||
| 134 | $query = $this->getSearchQuery($from, [], |
||
| 135 | $filters, $excludeFilters, $sortField, $sortOrder, $queryString); |
||
| 136 | } elseif ($this->security->getUserRole() == Security::ROLE_RESEARCHER) { |
||
| 137 | $query = $this->getSearchQuery($from, [], |
||
| 138 | $filters, $excludeFilters, $sortField, $sortOrder, $queryString); |
||
| 139 | } |
||
| 140 | |||
| 141 | try { |
||
| 142 | $results = $this->elasticSearch->search($query, 'object'); |
||
|
|
|||
| 143 | } catch (\Exception $e) { |
||
| 144 | $workspaceSessionData->clearSort(); |
||
| 145 | $workspaceSessionData->clearFilters(); |
||
| 146 | $this->session->setWorkspaceData($workspaceSessionData); |
||
| 147 | |||
| 148 | $this->addFlashMessage( |
||
| 149 | "Error while building the list!", '', AbstractMessage::ERROR |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | |||
| 153 | if ($this->request->hasArgument('message')) { |
||
| 154 | $this->view->assign('message', $this->request->getArgument('message')); |
||
| 155 | } |
||
| 156 | |||
| 157 | if ($this->request->hasArgument('errorFiles')) { |
||
| 158 | $this->view->assign('errorFiles', $this->request->getArgument('errorFiles')); |
||
| 159 | } |
||
| 160 | |||
| 161 | |||
| 162 | $this->view->assign('documentCount', $results['hits']['total']['value']); |
||
| 163 | $this->view->assign('documents', $results['hits']['hits']); |
||
| 164 | $this->view->assign('pages', range(1, $results['hits']['total']['value'])); |
||
| 165 | $this->view->assign('itemsPerPage', $this->itemsPerPage()); |
||
| 166 | $this->view->assign('aggregations', $results['aggregations']); |
||
| 167 | $this->view->assign('filters', $filters); |
||
| 168 | $this->view->assign('isHideDiscarded', array_key_exists('aliasState', $excludeFilters)); |
||
| 169 | $this->view->assign('isBookmarksOnly', array_key_exists('bookmarks', $excludeFilters)); |
||
| 170 | $this->view->assign('bookmarkIdentifiers', []); |
||
| 171 | |||
| 172 | if ($this->fisDataService->getPersonData($this->security->getFisPersId())) { |
||
| 173 | $this->view->assign('currentFisPersId', $this->security->getFisPersId()); |
||
| 174 | } |
||
| 175 | |||
| 176 | try { |
||
| 177 | $personGroup = $this->metadataGroupRepository->findPersonGroup(); |
||
| 178 | $this->view->assign('personGroup', $personGroup->getUid()); |
||
| 179 | } catch (\Throwable $e) { |
||
| 180 | $this->addFlashMessage( |
||
| 181 | "Missing configuration: Person group.", '', AbstractMessage::ERROR |
||
| 182 | ); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * action list |
||
| 188 | * |
||
| 189 | * @return void |
||
| 190 | */ |
||
| 191 | public function searchAction() |
||
| 235 | } |
||
| 236 | |||
| 237 | |||
| 238 | /** |
||
| 239 | * get list view data for the workspace |
||
| 240 | * |
||
| 241 | * @param int $from |
||
| 242 | * @param array $bookmarkIdentifiers |
||
| 243 | * @param array $filters |
||
| 244 | * @param array $excludeFilters |
||
| 245 | * @param string $sortField |
||
| 246 | * @param string $sortOrder |
||
| 247 | * @param string $queryString |
||
| 248 | * |
||
| 249 | * @return array |
||
| 250 | */ |
||
| 251 | protected function getSearchQuery( |
||
| 252 | $from = 0, $bookmarkIdentifiers = [], $filters= [], $excludeFilters = [], |
||
| 253 | $sortField = null, $sortOrder = null, $queryString = null |
||
| 254 | ) |
||
| 255 | { |
||
| 256 | $workspaceFilter = [ |
||
| 257 | 'bool' => [ |
||
| 258 | 'must' => [ |
||
| 259 | [ |
||
| 260 | 'bool' => [ |
||
| 261 | 'should' => [ |
||
| 262 | [ |
||
| 263 | 'term' => [ |
||
| 264 | 'creator' => $this->security->getUser()->getUid() |
||
| 265 | ] |
||
| 266 | ], |
||
| 267 | [ |
||
| 268 | 'bool' => [ |
||
| 269 | 'must_not' => [ |
||
| 270 | [ |
||
| 271 | 'term' => [ |
||
| 272 | 'state' => DocumentWorkflow::STATE_NEW_NONE |
||
| 273 | ] |
||
| 274 | ] |
||
| 275 | ] |
||
| 276 | ] |
||
| 277 | ] |
||
| 278 | ] |
||
| 279 | ] |
||
| 280 | ] |
||
| 281 | ] |
||
| 282 | ] |
||
| 283 | ]; |
||
| 284 | |||
| 285 | return $this->queryBuilder->buildQuery( |
||
| 286 | $this->itemsPerPage(), $workspaceFilter, $from, $bookmarkIdentifiers, $filters, |
||
| 287 | $excludeFilters, $sortField, $sortOrder, $queryString |
||
| 288 | ); |
||
| 289 | } |
||
| 290 | |||
| 291 | |||
| 292 | /** |
||
| 293 | * Batch operations action. |
||
| 294 | * @param array $listData |
||
| 295 | */ |
||
| 296 | public function batchAction($listData) |
||
| 297 | { |
||
| 298 | if (array_key_exists('action', $listData)) { |
||
| 299 | $this->forward($listData['action'], null, null, ['listData' => $listData]); |
||
| 300 | } |
||
| 301 | } |
||
| 302 | |||
| 303 | |||
| 304 | /** |
||
| 305 | * Batch operation, bookmark documents. |
||
| 306 | * @param array $listData |
||
| 307 | */ |
||
| 308 | public function batchBookmarkAction($listData) |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * extended search action |
||
| 361 | */ |
||
| 362 | public function extendedSearchAction() |
||
| 363 | { |
||
| 364 | /** @var FrontendUser $feUser */ |
||
| 365 | $feUser = $this->security->getUser(); |
||
| 366 | |||
| 367 | $args = $this->request->getArguments(); |
||
| 368 | |||
| 369 | /** @var SearchSessionData $workspaceSessionData */ |
||
| 370 | $workspaceSessionData = $this->session->getWorkspaceData(); |
||
| 371 | |||
| 372 | if ($args['query'] && array_key_exists('fulltext', $args['query'])) { |
||
| 373 | $queryString = $args['query']['fulltext']; |
||
| 374 | $workspaceSessionData->setSimpleQuery($queryString); |
||
| 375 | } |
||
| 376 | |||
| 377 | if ($args['refresh']) { |
||
| 378 | $workspaceSessionData->clearSort(); |
||
| 379 | $workspaceSessionData->clearFilters(); |
||
| 380 | $workspaceSessionData->setSimpleQuery(""); |
||
| 381 | } |
||
| 382 | $this->session->setWorkspaceData($workspaceSessionData); |
||
| 383 | |||
| 384 | $simpleSearch = $workspaceSessionData->getSimpleQuery(); |
||
| 385 | |||
| 386 | $documentTypes = $this->documentTypeRepository->findAll(); |
||
| 387 | |||
| 388 | $docTypes = []; |
||
| 389 | foreach ($documentTypes as $documentType) { |
||
| 390 | $docTypes[$documentType->getName()] = $documentType->getDisplayName(); |
||
| 391 | } |
||
| 392 | asort($docTypes, SORT_LOCALE_STRING); |
||
| 393 | $this->view->assign('documentTypes', $docTypes); |
||
| 394 | |||
| 395 | $states[DocumentWorkflow::ALIAS_STATE_NEW] = LocalizationUtility::translate( |
||
| 396 | "manager.documentList.state.".DocumentWorkflow::ALIAS_STATE_NEW, 'dpf' |
||
| 397 | ); |
||
| 398 | $states[DocumentWorkflow::ALIAS_STATE_REGISTERED] = LocalizationUtility::translate( |
||
| 399 | "manager.documentList.state.".DocumentWorkflow::ALIAS_STATE_REGISTERED, 'dpf' |
||
| 400 | ); |
||
| 401 | $states[DocumentWorkflow::ALIAS_STATE_IN_PROGRESS] = LocalizationUtility::translate( |
||
| 402 | "manager.documentList.state.".DocumentWorkflow::ALIAS_STATE_IN_PROGRESS, 'dpf' |
||
| 403 | ); |
||
| 404 | $states[DocumentWorkflow::ALIAS_STATE_RELEASED] = LocalizationUtility::translate( |
||
| 405 | "manager.documentList.state.".DocumentWorkflow::ALIAS_STATE_RELEASED, 'dpf' |
||
| 406 | ); |
||
| 407 | $states[DocumentWorkflow::ALIAS_STATE_POSTPONED] = LocalizationUtility::translate( |
||
| 408 | "manager.documentList.state.".DocumentWorkflow::ALIAS_STATE_POSTPONED, 'dpf' |
||
| 409 | ); |
||
| 410 | $states[DocumentWorkflow::ALIAS_STATE_DISCARDED] = LocalizationUtility::translate( |
||
| 411 | "manager.documentList.state.".DocumentWorkflow::ALIAS_STATE_DISCARDED, 'dpf' |
||
| 412 | ); |
||
| 413 | |||
| 414 | $this->view->assign('states', $states); |
||
| 415 | |||
| 416 | $this->session->setStoredAction($this->getCurrentAction(), $this->getCurrentController(), |
||
| 417 | $this->uriBuilder->getRequest()->getRequestUri() |
||
| 418 | ); |
||
| 419 | |||
| 420 | $currentPage = null; |
||
| 421 | $checkedDocumentIdentifiers = []; |
||
| 422 | $pagination = $this->getParametersSafely('@widget_0'); |
||
| 423 | if ($pagination) { |
||
| 424 | $checkedDocumentIdentifiers = []; |
||
| 425 | $currentPage = $pagination['currentPage']; |
||
| 426 | } else { |
||
| 427 | $currentPage = 1; |
||
| 428 | } |
||
| 429 | |||
| 430 | $this->list((empty($currentPage)? 0 : ($currentPage-1) * $this->itemsPerPage()), $simpleSearch); |
||
| 431 | |||
| 432 | $this->view->assign('simpleSearch', $simpleSearch); |
||
| 433 | $this->view->assign('currentPage', $currentPage); |
||
| 434 | $this->view->assign('workspaceListAction', $this->getCurrentAction()); |
||
| 435 | $this->view->assign('checkedDocumentIdentifiers', $checkedDocumentIdentifiers); |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * gets a list of latest documents |
||
| 440 | */ |
||
| 441 | public function latestAction() |
||
| 442 | { |
||
| 443 | try { |
||
| 444 | $query = $this->searchLatest(); |
||
| 445 | |||
| 446 | // set type local vs object |
||
| 447 | $type = 'object'; |
||
| 448 | |||
| 449 | $results = $this->getResultList($query, $type); |
||
| 450 | } catch (\Exception $exception) { |
||
| 451 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR; |
||
| 452 | |||
| 453 | if ($exception instanceof DPFExceptionInterface) { |
||
| 454 | $key = $exception->messageLanguageKey(); |
||
| 455 | } else { |
||
| 456 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected'; |
||
| 457 | } |
||
| 458 | |||
| 459 | $message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf'); |
||
| 460 | |||
| 461 | $this->addFlashMessage( |
||
| 462 | $message, |
||
| 463 | '', |
||
| 464 | $severity, |
||
| 465 | true |
||
| 466 | ); |
||
| 467 | } |
||
| 468 | |||
| 469 | if ($extSearch) { |
||
| 470 | // redirect to extended search view |
||
| 471 | $this->forward("extendedSearch", null, null, array('results' => $results, 'query' => $args['query'])); |
||
| 472 | } else { |
||
| 473 | // redirect to list view |
||
| 474 | $this->forward("list", null, null, array('results' => $results, 'query' => $args['query'])); |
||
| 475 | } |
||
| 476 | } |
||
| 477 | |||
| 478 | /** |
||
| 479 | * action import |
||
| 480 | * |
||
| 481 | * @param string $documentObjectIdentifier |
||
| 482 | * @param string $objectState |
||
| 483 | * @return void |
||
| 484 | */ |
||
| 485 | public function importAction($documentObjectIdentifier, $objectState) |
||
| 486 | { |
||
| 487 | $documentTransferManager = $this->objectManager->get(DocumentTransferManager::class); |
||
| 488 | $remoteRepository = $this->objectManager->get(FedoraRepository::class); |
||
| 489 | $documentTransferManager->setRemoteRepository($remoteRepository); |
||
| 490 | |||
| 491 | $args = array(); |
||
| 492 | |||
| 493 | try { |
||
| 494 | if ($documentTransferManager->retrieve($documentObjectIdentifier)) { |
||
| 495 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_retrieve.success'; |
||
| 496 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::OK; |
||
| 497 | $document = $this->documentRepository->findOneByObjectIdentifier($documentObjectIdentifier); |
||
| 498 | $args[] = $document->getObjectIdentifier()." (".$document->getTitle().")"; |
||
| 499 | } else { |
||
| 500 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR; |
||
| 501 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.retrieve_failed'; |
||
| 502 | } |
||
| 503 | } catch (\Exception $exception) { |
||
| 504 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR; |
||
| 505 | |||
| 506 | if ($exception instanceof DPFExceptionInterface) { |
||
| 507 | $key = $exception->messageLanguageKey(); |
||
| 508 | } else { |
||
| 509 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected'; |
||
| 510 | } |
||
| 511 | } |
||
| 512 | |||
| 513 | // Show success or failure of the action in a flash message |
||
| 514 | |||
| 515 | $message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf', $args); |
||
| 516 | |||
| 517 | $this->addFlashMessage( |
||
| 518 | $message, |
||
| 519 | '', |
||
| 520 | $severity, |
||
| 521 | true |
||
| 522 | ); |
||
| 523 | |||
| 524 | $this->forward('updateIndex', null, null, array('documentObjectIdentifier' => $documentObjectIdentifier)); |
||
| 525 | } |
||
| 526 | |||
| 527 | /** |
||
| 528 | * |
||
| 529 | * @param string $documentObjectIdentifier |
||
| 530 | * @return void |
||
| 531 | */ |
||
| 532 | public function updateIndexAction($documentObjectIdentifier) |
||
| 533 | { |
||
| 534 | $document = $this->documentRepository->findByObjectIdentifier($documentObjectIdentifier); |
||
| 535 | |||
| 536 | if (is_a($document, Document::class)) { |
||
| 537 | $elasticsearchRepository = $this->objectManager->get(ElasticsearchRepository::class); |
||
| 538 | $elasticsearchMapper = $this->objectManager->get(ElasticsearchMapper::class); |
||
| 539 | $json = $elasticsearchMapper->getElasticsearchJson($document); |
||
| 540 | // send document to index |
||
| 541 | $elasticsearchRepository->add($document, $json); |
||
| 542 | } |
||
| 543 | |||
| 544 | $this->redirect('search'); |
||
| 545 | } |
||
| 546 | |||
| 547 | |||
| 548 | /** |
||
| 549 | * action doubletCheck |
||
| 550 | * |
||
| 551 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
| 552 | * @return void |
||
| 553 | */ |
||
| 554 | public function doubletCheckAction(\EWW\Dpf\Domain\Model\Document $document) |
||
| 555 | { |
||
| 556 | $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::DOUBLET_CHECK, $document); |
||
| 557 | |||
| 558 | try { |
||
| 559 | $elasticSearch = $this->objectManager->get(ElasticSearch::class); |
||
| 560 | |||
| 561 | $client = $this->clientRepository->findAll()->current(); |
||
| 562 | |||
| 563 | // es source fields |
||
| 564 | // title |
||
| 565 | // abstract |
||
| 566 | // author |
||
| 567 | // language |
||
| 568 | // publisher |
||
| 569 | // publisher_place |
||
| 570 | // distributor |
||
| 571 | // distributor_place |
||
| 572 | // distributor_date |
||
| 573 | // classification |
||
| 574 | // tag |
||
| 575 | // identifier |
||
| 576 | // submitter |
||
| 577 | // project |
||
| 578 | |||
| 579 | // is doublet existing? |
||
| 580 | $query['body']['query']['bool']['must'][]['match']['title'] = $document->getTitle(); |
||
| 581 | |||
| 582 | // set owner id |
||
| 583 | $query['body']['query']['bool']['must'][]['term']['OWNER_ID'] = $client->getOwnerId(); |
||
| 584 | |||
| 585 | $results = $elasticSearch->search($query, ''); |
||
| 586 | |||
| 587 | $searchList = array(); |
||
| 588 | |||
| 589 | // filter out identical document from the search result list |
||
| 590 | foreach ($results['hits'] as $entry) { |
||
| 591 | |||
| 592 | if ($document->getObjectIdentifier() && ($document->getObjectIdentifier() === $entry['_source']['PID'])) { |
||
| 593 | continue; |
||
| 594 | } |
||
| 595 | |||
| 596 | $entryIdentifier = $entry['_source']['_dissemination']['_content']['identifier'][0]; |
||
| 597 | if (is_numeric($entryIdentifier) && $document->getUid() == $entryIdentifier) { |
||
| 598 | continue; |
||
| 599 | } |
||
| 600 | |||
| 601 | $searchList[] = $entry; |
||
| 602 | } |
||
| 603 | |||
| 604 | |||
| 605 | $objectIdentifiers = $this->documentRepository->getObjectIdentifiers(); |
||
| 606 | |||
| 607 | $this->view->assign('document', $document); |
||
| 608 | $this->view->assign('searchList', $searchList); |
||
| 609 | $this->view->assign('alreadyImported', $objectIdentifiers); |
||
| 610 | |||
| 611 | } catch (\Exception $exception) { |
||
| 612 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR; |
||
| 613 | |||
| 614 | if ($exception instanceof DPFExceptionInterface) { |
||
| 615 | $key = $exception->messageLanguageKey(); |
||
| 616 | } else { |
||
| 617 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected'; |
||
| 618 | } |
||
| 619 | |||
| 620 | $message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf'); |
||
| 621 | |||
| 622 | $this->addFlashMessage( |
||
| 623 | $message, |
||
| 624 | '', |
||
| 625 | $severity, |
||
| 626 | true |
||
| 627 | ); |
||
| 628 | |||
| 629 | $this->redirect('list', 'Document', null); |
||
| 630 | } |
||
| 631 | |||
| 632 | } |
||
| 633 | |||
| 634 | /** |
||
| 635 | * returns the query to get latest documents |
||
| 636 | * @return mixed |
||
| 637 | */ |
||
| 638 | public function searchLatest() |
||
| 639 | { |
||
| 640 | $client = $this->clientRepository->findAll()->current(); |
||
| 641 | |||
| 642 | // get the latest documents /CREATED_DATE |
||
| 643 | $query['body']['sort'] = array('CREATED_DATE' => array('order' => 'desc')); |
||
| 644 | |||
| 645 | // add owner id |
||
| 646 | $query['body']['query']['bool']['must']['term']['OWNER_ID'] = $client->getOwnerId(); |
||
| 647 | |||
| 648 | $query['body']['query']['bool']['should'][0]['query_string']['query'] = '*'; |
||
| 649 | $query['body']['query']['bool']['should'][1]['has_child']['query']['query_string']['query'] = '*'; |
||
| 650 | |||
| 651 | $query['body']['query']['bool']['minimum_should_match'] = "1"; // 1 |
||
| 652 | |||
| 653 | // child_type is invalid in elasticsearch 7.5 |
||
| 654 | $query['body']['query']['bool']['should'][1]['has_child']['type'] = "datastream"; // 1 |
||
| 655 | |||
| 656 | return $query; |
||
| 657 | } |
||
| 658 | |||
| 659 | |||
| 660 | /** |
||
| 661 | * Returns the number of items to be shown per page. |
||
| 662 | * |
||
| 663 | * @return int |
||
| 664 | */ |
||
| 665 | protected function itemsPerPage() |
||
| 666 | { |
||
| 667 | /** @var SearchSessionData $workspaceData */ |
||
| 668 | $workspaceData = $this->session->getWorkspaceData(); |
||
| 669 | $itemsPerPage = $workspaceData->getItemsPerPage(); |
||
| 670 | |||
| 671 | $default = ($this->settings['workspaceItemsPerPage'])? $this->settings['workspaceItemsPerPage'] : 10; |
||
| 672 | return ($itemsPerPage)? $itemsPerPage : $default; |
||
| 673 | } |
||
| 674 | |||
| 675 | |||
| 676 | /** |
||
| 677 | * escapes lucene reserved characters from string |
||
| 678 | * @param $string |
||
| 679 | * @return mixed |
||
| 680 | */ |
||
| 681 | private function escapeQuery($string) |
||
| 695 | } |
||
| 696 | |||
| 697 | } |
||
| 698 |