Skip to content

Commit

Permalink
Merge pull request #77 from slub/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
dikastes authored Oct 15, 2024
2 parents a8f5177 + 1242101 commit fafa619
Show file tree
Hide file tree
Showing 50 changed files with 1,821 additions and 1,127 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
Build/dist/*
Build/node_modules/*
.idea/
.Build/
Build/testing-docker/.env
composer.lock
public/
20 changes: 10 additions & 10 deletions Classes/Command/CalculateTablesCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SLUB\MpdbPresentation\Command;
namespace Slub\MpdbPresentation\Command;

use Elastic\Elasticsearch\Client;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -135,7 +135,7 @@ protected function groupPublishedItems(): void
*/
protected function fetchPublishedItems(): void
{
$coreExtConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('mpdb_core');
$coreExtConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('mpdb_core');
$prefix = $coreExtConf['prefix'];

$params = [
Expand Down Expand Up @@ -243,13 +243,13 @@ protected function commitChunk(Collection $chunk, string $index): void
*/
protected function commitPublishedItemTables(): void
{
if ($this->client->indices()->exists(['index' => $this->prefix . PublishedItemController::TABLE_INDEX_NAME])) {
if ($this->client->indices()->exists(['index' => $this->prefix . PublishedItemController::TABLE_INDEX_NAME])->asBool()) {
$this->client->indices()->delete(['index' => $this->prefix . PublishedItemController::TABLE_INDEX_NAME]);
}
if ($this->client->indices()->exists(['index' => $this->prefix . WorkController::TABLE_INDEX_NAME])) {
if ($this->client->indices()->exists(['index' => $this->prefix . WorkController::TABLE_INDEX_NAME])->asBool()) {
$this->client->indices()->delete(['index' => $this->prefix . WorkController::TABLE_INDEX_NAME]);
}
if ($this->client->indices()->exists(['index' => $this->prefix . PersonController::TABLE_INDEX_NAME])) {
if ($this->client->indices()->exists(['index' => $this->prefix . PersonController::TABLE_INDEX_NAME])->asBool()) {
$this->client->indices()->delete(['index' => $this->prefix . PersonController::TABLE_INDEX_NAME]);
}

Expand Down Expand Up @@ -310,7 +310,7 @@ protected static function samplePublishedItemData(array $publishedItem): array
{
$publishedSubitems = Collection::wrap($publishedItem['_source']['published_subitems'])->
map(function ($item) { return self::samplePublishedSubitemData($item); })->
toArray();
all();

return [
$publishedItem['_id'] =>
Expand Down Expand Up @@ -356,10 +356,10 @@ protected static function samplePublishedSubitemData(array $publishedSubitem): a

$result = [
'id' => $publishedSubitem['mvdb_id'],
'prints_by_date' => $printsByDate->toArray(),
'prints_per_year' => $printsPerYear->toArray(),
'prints_by_date_cumulative' => $printsByDateCumulative->toArray(),
'prints_per_year_cumulative' => $printsPerYearCumulative->toArray()
'prints_by_date' => $printsByDate->values(),
'prints_per_year' => $printsPerYear->values(),
'prints_by_date_cumulative' => $printsByDateCumulative->values(),
'prints_per_year_cumulative' => $printsPerYearCumulative->values()
];

foreach(explode(',', $extConf['movingAverages']) as $years) {
Expand Down
5 changes: 2 additions & 3 deletions Classes/Command/IndexPublishersCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SLUB\MpdbPresentation\Command;
namespace Slub\MpdbPresentation\Command;

use Elastic\Elasticsearch\Client;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -78,13 +78,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
)->
from(self::TABLE_NAME);

if ($this->client->indices()->exists(['index' => $prefix . self::INDEX_NAME])) {
if ($this->client->indices()->exists(['index' => $prefix . self::INDEX_NAME])->asBool()) {
$this->client->indices()->delete(['index' => $prefix . self::INDEX_NAME]);
}

Collection::wrap($qb->execute()->fetchAll())->
filter(function ($publisher) { return $this->isPublic($publisher); })->
//pluck('uid', self::NAME_COLNAME, self::SHORTHAND_COLNAME)//->
each(function ($publisher) { $this->indexPublisher($publisher); });

return 0;
Expand Down
64 changes: 11 additions & 53 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use Illuminate\Support\Collection;
use Slub\MpdbCore\Controller\AbstractController as CoreAbstractController;
use Slub\MpdbCore\Services\SearchServiceInterface;
use Slub\MpdbCore\Services\SearchServiceNotFoundException;
use Slub\MpdbPresentation\Command\IndexPublishersCommand;
use Slub\MpdbPresentation\Services\SearchServiceInterface;
use Slub\MpdbPresentation\Services\SearchServiceNotFoundException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand All @@ -18,32 +18,18 @@ abstract class AbstractController extends CoreAbstractController
const DASHBOARD_TARGET = 'tx_mpdbpresentation_dashboard';
const RESULT_COUNT = 25;
const INDICES = [
'person' => [
'symbol' => '🧍',
'controller' => 'Person'
],
'work' => [
'symbol' => '📄',
'controller' => 'Work'
],
'published_item' => [
'symbol' => '📕',
'controller' => 'PublishedItem'
],
'instrument' => [
'symbol' => '🎺',
'controller' => 'Instrument'
],
'genre' => [
'symbol' => '🎶',
'controller' => 'Genre'
]
'person' => [
'controller' => 'Person',
'translation' => 'person' ],
'work' => [
'controller' => 'Work',
'translation' => 'work' ],
'published_item' => [
'controller' => 'PublishedItem',
'translation' => 'publishedItem' ]
];
const EXT_NAME = 'MpdbPresentation';

protected Collection $localizedIndices;
protected Collection $publishers;
protected SearchServiceInterface $searchService;

public function initializeShowAction()
{
Expand All @@ -55,34 +41,6 @@ public function initializeShowAction()
pluck('_source');
}

/**
* @throws SearchServiceNotFoundException
*/
protected function initializeAction(): void
{
$this->localizedIndices = Collection::wrap(self::INDICES)->
mapWithKeys(function ($array, $key) { return self::localizeIndex($array, $key); });

$searchService = GeneralUtility::makeInstanceService('search');
if (is_object($searchService)) {
$this->searchService = $searchService;
} else {
throw new SearchServiceNotFoundException();
}

$this->searchService->
setSize(self::RESULT_COUNT);
}

private static function localizeIndex(array $array, string $key): array
{
$coreExtConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('mpdb_core');
$body = $array;
$translation = LocalizationUtility::translate($key, self::EXT_NAME);
$body['translation'] = ucwords($translation);
return [ $key => $body ];
}

protected function getJsCall(Collection $data, Collection $publishers = null, string $title): string
{
$movingAverages = explode(',', GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('mpdb_presentation')['movingAverages']);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function searchAction(array $config = []): ResponseInterface

$this->view->assign('entities', $entities->all());
$this->view->assign('config', $config);
$this->view->assign('indices', $this->localizedIndices->all());
$this->view->assign('indices', self::INDICES);
$this->view->assign('totalItems', $totalItems);
$this->view->assign('publishers', $publishers->all());
$this->view->assign('resultCount', self::RESULT_COUNT);
Expand Down
28 changes: 14 additions & 14 deletions Classes/Controller/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public function showAction(GndPerson $person)
setIndex(self::TABLE_INDEX_NAME)->
setId($person->getGndId())->
search();
$hasPrints = $document->
get('published_items')->
pluck('published_subitems')->
flatten(1)->
pluck('prints_by_date')->
filter()->
count();

$visualizationCall = $this->getJsCall($document, $this->publishers, $personData['name']);
$this->view->assign('publishers', $this->publishers->all());
Expand All @@ -49,22 +56,15 @@ public function showAction(GndPerson $person)
$this->view->assign('dashboardTarget', self::DASHBOARD_TARGET);
$this->view->assign('person', $personData);
$this->view->assign('graphTarget', self::GRAPH_TARGET);
$this->view->assign('hasPrints', $hasPrints);
}

protected function get(GndPerson $person): array
protected function get(GndPerson $person): Collection
{
$params = [
'index' => 'person',
'body' => [
'query' => [
'match' => [
'uid' => $person->getUid()
]
]
]
];

$personData = $this->elasticClient->search($params);
return $personData['hits']['hits'][0]['_source'];
return $this->searchService->
reset()->
setIndex('person')->
setId($person->getGndId())->
search();
}
}
2 changes: 1 addition & 1 deletion Classes/Controller/PublishedItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function showAction(PublishedItem $publishedItem)
foreach ($publisherMikroItems as $publisherMikroItem) {
$publisherActions = array_merge(
$publisherActions,
$this->publisherActionRepository->findByPublisherMikroItem($publisherMikroItem)->toArray()
$this->publisherActionRepository->findByPublishedsubitem($publisherMikroItem)->toArray()
);
}
usort($publisherActions, $sortByDate);
Expand Down
62 changes: 62 additions & 0 deletions Classes/Controller/WelcomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Slub\MpdbPresentation\Controller;

use \Illuminate\Support\Collection;
use \Illuminate\Support\Str;
use \Psr\Http\Message\ResponseInterface;
use \TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use \Slub\MpdbPresentation\Domain\Model\Publisher;

/***
*
* This file is part of the "Publisher Database" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2021 Matthias Richter <[email protected]>, SLUB Dresden
*
***/
/**
* PublishedItemController
*/
class WelcomeController extends AbstractController
{

/**
* action welcome
*
* @return void
*/
public function welcomeAction(): ResponseInterface
{
$bodyText = $this->configurationManager->getContentObject()->getFieldVal('bodytext');
$and = LocalizationUtility::translate('LLL:EXT:mpdb_presentation/Resources/Private/Language/locallang:and');

$entityCount = $this->searchService->
setIndex(PublishedItemController::TABLE_INDEX_NAME)->
count();

$publishers = $this->searchService->
reset()->
setIndex(Publisher::INDEX_NAME)->
search()->
pluck('_source')->
map(function ($publisher) { return self::getPublisherName($publisher); })->
join(', ', ' ' . $and . ' ');

$processedText = Str::of($bodyText)->replace('{{ publishers }}', $publishers)->
replace('{{ count }}', $entityCount);

$this->view->assign('processedText', $processedText);

return $this->htmlResponse();
}

private static function getPublisherName(Collection $publisher): string
{
return $publisher->get('name') . ' (' . $publisher->get('shorthand') . ')';
}

}
Loading

0 comments on commit fafa619

Please sign in to comment.