From aff7265cf2a12f79d6102871793d3a06605af57e Mon Sep 17 00:00:00 2001 From: thomas-sc Date: Tue, 14 May 2024 10:46:25 +0200 Subject: [PATCH] rename Controller Action in search, display localizedCitations in template --- Classes/Controller/BibliographyController.php | 21 +++++++++++++++++-- Classes/Services/ElasticSearchService.php | 2 +- .../Bibliography/{List.html => Search.html} | 14 +++++++++---- ext_localconf.php | 2 +- 4 files changed, 31 insertions(+), 8 deletions(-) rename Resources/Private/Templates/Bibliography/{List.html => Search.html} (77%) diff --git a/Classes/Controller/BibliographyController.php b/Classes/Controller/BibliographyController.php index 0fe42b3..ba937fc 100644 --- a/Classes/Controller/BibliographyController.php +++ b/Classes/Controller/BibliographyController.php @@ -13,6 +13,7 @@ namespace Slub\LisztBibliography\Controller; +use http\Env\Request; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -22,13 +23,17 @@ use Slub\LisztBibliography\Interfaces\ElasticSearchServiceInterface; +use TYPO3\CMS\Core\Context\Context; final class BibliographyController extends ClientEnabledController { + // set resultLimit as intern variable from $this->settings['resultLimit']; protected int $resultLimit; + + // Dependency Injection of Repository // https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/DependencyInjection/Index.html#Dependency-Injection @@ -36,13 +41,25 @@ public function __construct(private readonly ElasticSearchServiceInterface $elas { $this->resultLimit = $this->settings['resultLimit'] ?? 25; + + } - public function listAction(): ResponseInterface + public function searchAction(): ResponseInterface { - $this->view->assign('bibliographyList', $this->elasticSearchService->search()); + $language = $this->request->getAttribute('language'); + $locale = $language->getLocale(); + + $elasticResponse = $this->elasticSearchService->search(); + + $this->view->assign('locale', $locale); + + $this->view->assign('totalItems', $elasticResponse['hits']['total']['value']); + + + $this->view->assign('bibliographyList', $elasticResponse); return $this->htmlResponse(); } diff --git a/Classes/Services/ElasticSearchService.php b/Classes/Services/ElasticSearchService.php index 091c79e..5eba4cf 100644 --- a/Classes/Services/ElasticSearchService.php +++ b/Classes/Services/ElasticSearchService.php @@ -48,7 +48,7 @@ public function search(): Collection 'match_all' => new \stdClass() ], 'size' => 10, - '_source' => ['itemType', 'title', 'creators', 'pages','date','language'], + '_source' => ['itemType', 'title', 'creators', 'pages','date','language', 'localizedCitations'], 'aggs' => [ 'itemType' => [ 'terms' => [ diff --git a/Resources/Private/Templates/Bibliography/List.html b/Resources/Private/Templates/Bibliography/Search.html similarity index 77% rename from Resources/Private/Templates/Bibliography/List.html rename to Resources/Private/Templates/Bibliography/Search.html index d43125b..5b18e05 100644 --- a/Resources/Private/Templates/Bibliography/List.html +++ b/Resources/Private/Templates/Bibliography/Search.html @@ -25,15 +25,21 @@

{key}

-
-

{hit._source.title}

-

+ + + {hit._source.localizedCitations.{locale}} + + + {hit._source.localizedCitations.de-DE} +

else

+ + + {creator.firstName} {creator.lastName} - ,{hit._source.date}, {hit._source.pages}, {hit._source.language}

diff --git a/ext_localconf.php b/ext_localconf.php index a9c7b76..558ffbd 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -11,7 +11,7 @@ ExtensionUtility::configurePlugin( 'LisztBibliography', 'BibliographyListing', - [ BibliographyController::class => 'list' ], + [ BibliographyController::class => 'search' ], [ BibliographyController::class => '' ] );