Skip to content

Commit

Permalink
rename Controller Action in search, display localizedCitations in tem…
Browse files Browse the repository at this point in the history
…plate
thomas-sc committed May 14, 2024
1 parent 6af58c5 commit aff7265
Showing 4 changed files with 31 additions and 8 deletions.
21 changes: 19 additions & 2 deletions Classes/Controller/BibliographyController.php
Original file line number Diff line number Diff line change
@@ -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,27 +23,43 @@

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

public function __construct(private readonly ElasticSearchServiceInterface $elasticSearchService)
{
$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();
}

2 changes: 1 addition & 1 deletion Classes/Services/ElasticSearchService.php
Original file line number Diff line number Diff line change
@@ -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' => [
Original file line number Diff line number Diff line change
@@ -25,15 +25,21 @@ <h4 class="">{key}</h4>

</div>
<div class="col-12 col-md-9 col-lg-10 filter">

<f:for each="{bibliographyList.hits.hits}" as="hit">
<div class="search-result-item">
<h3>{hit._source.title}</h3>
<p>
<f:if condition="{hit._source.localizedCitations.{locale}}">
<f:then>
<f:format.html >{hit._source.localizedCitations.{locale}}</f:format.html>
</f:then>
<f:else>
<f:format.html >{hit._source.localizedCitations.de-DE}</f:format.html>
<p>else</p>
</f:else>
</f:if>

<f:for each="{hit._source.creators}" as="creator">
{creator.firstName} {creator.lastName}
</f:for>
,{hit._source.date}, {hit._source.pages}, {hit._source.language}</p>
</div>
</f:for>

2 changes: 1 addition & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
ExtensionUtility::configurePlugin(
'LisztBibliography',
'BibliographyListing',
[ BibliographyController::class => 'list' ],
[ BibliographyController::class => 'search' ],
[ BibliographyController::class => '' ]
);

0 comments on commit aff7265

Please sign in to comment.