Skip to content

Commit b1dcdd9

Browse files
Merge branch 'main' into fix-mimtypefilter
2 parents 06582dc + 9b6fbb2 commit b1dcdd9

File tree

13 files changed

+275
-22
lines changed

13 files changed

+275
-22
lines changed

.github/phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ parameters:
2323
- '#Constant LOG_SEVERITY_ERROR not found\.#'
2424
- '#Constant LOG_SEVERITY_NOTICE not found\.#'
2525
- '#Constant LOG_SEVERITY_WARNING not found\.#'
26+
- '#^Parameter \#2 \$callback of function array_filter expects \(callable\(mixed\)\: bool\)\|null, ''strlen'' given\.$#'
2627
level: 5
2728
paths:
2829
- ../Classes/

Build/Test/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ services:
4444
"
4545
4646
solr:
47-
image: docker.io/solr:9
47+
image: docker.io/solr:9.7
4848
volumes:
4949
- ${DLF_ROOT}/Configuration/ApacheSolr/configsets:/var/solr/data/configsets
5050
- ./solr/modules/ocrsearch:/opt/solr/modules/ocrsearch

Classes/Controller/ListViewController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,13 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
7979
public function mainAction(): ResponseInterface
8080
{
8181
$this->searchParams = $this->getParametersSafely('searchParameter');
82+
$this->searchParams = is_array($this->searchParams) ? array_filter($this->searchParams, 'strlen') : [];
8283

8384
// extract collection(s) from collection parameter
8485
$collections = [];
85-
if (is_array($this->searchParams) && array_key_exists('collection', $this->searchParams)) {
86+
if (array_key_exists('collection', $this->searchParams)) {
8687
foreach(explode(',', $this->searchParams['collection']) as $collectionEntry) {
87-
if (!empty($collectionEntry)) {
88-
$collections[] = $this->collectionRepository->findByUid((int) $collectionEntry);
89-
}
88+
$collections[] = $this->collectionRepository->findByUid((int) $collectionEntry);
9089
}
9190
}
9291

@@ -104,7 +103,7 @@ public function mainAction(): ResponseInterface
104103

105104
$solrResults = null;
106105
$numResults = 0;
107-
if (is_array($this->searchParams) && !empty($this->searchParams)) {
106+
if (!empty($this->searchParams)) {
108107
$solrResults = $this->documentRepository->findSolrByCollections($collections, $this->settings, $this->searchParams, $listedMetadata, $indexedMetadata);
109108
$numResults = $solrResults->getNumFound();
110109

Classes/Controller/NavigationController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ public function mainAction(): ResponseInterface
8181
$this->viewData['requestData'] = $this->requestData;
8282
}
8383

84+
// get the closest previous sibling or leaf node
85+
$prevDocumentUid = $this->documentRepository->getPreviousDocumentUid($this->document->getUid());
86+
$this->view->assign('documentBack', $prevDocumentUid);
87+
88+
// get the closest next sibling or leaf node
89+
$nextDocumentUid = $this->documentRepository->getNextDocumentUid($this->document->getUid());
90+
$this->view->assign('documentForward', $nextDocumentUid);
91+
8492
// Steps for X pages backward / forward. Double page view uses double steps.
8593
$pageSteps = $this->settings['pageStep'] * ($this->requestData['double'] + 1);
8694

Classes/Controller/SearchController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function mainAction(): ResponseInterface
115115

116116
// if search was triggered, get search parameters from POST variables
117117
$this->searchParams = $this->getParametersSafely('searchParameter');
118+
118119
// if search was triggered by the ListView plugin, get the parameters from GET variables
119120
// replace with $this->request->getQueryParams() when dropping support for Typo3 v11, see Deprecation-100596
120121
$listRequestData = GeneralUtility::_GPmerged('tx_dlf_listview');
@@ -130,13 +131,15 @@ public function mainAction(): ResponseInterface
130131
$GLOBALS['TSFE']->fe_user->setKey('ses', 'search', $this->searchParams);
131132
}
132133

134+
$this->searchParams = is_array($this->searchParams) ? array_filter($this->searchParams, 'strlen') : [];
135+
133136
// sanitize date search input
134-
if (!empty($this->searchParams['dateFrom']) || !empty($this->searchParams['dateTo'])) {
135-
if (empty($this->searchParams['dateFrom']) && !empty($this->searchParams['dateTo'])) {
137+
if (array_key_exists('dateFrom', $this->searchParams) || array_key_exists('dateTo', $this->searchParams)) {
138+
if (!array_key_exists('dateFrom', $this->searchParams) && array_key_exists('dateTo', $this->searchParams)) {
136139
$this->searchParams['dateFrom'] = '*';
137140
}
138141

139-
if (empty($this->searchParams['dateTo']) && !empty($this->searchParams['dateFrom'])) {
142+
if (!array_key_exists('dateTo', $this->searchParams) && array_key_exists('dateFrom', $this->searchParams)) {
140143
$this->searchParams['dateTo'] = 'NOW';
141144
}
142145

@@ -168,7 +171,7 @@ public function mainAction(): ResponseInterface
168171

169172
// If no search has been executed, no variables have to be prepared.
170173
// An empty form will be shown.
171-
if (is_array($this->searchParams) && !empty($this->searchParams)) {
174+
if (!empty($this->searchParams)) {
172175
// get all sortable metadata records
173176
$sortableMetadata = $this->metadataRepository->findByIsSortable(true);
174177

@@ -276,7 +279,7 @@ public function makeFacetsMenuArray(array $facets): array
276279
// Set search query.
277280
$searchParams = $this->searchParams;
278281
if (
279-
(!empty($searchParams['fulltext']))
282+
(array_key_exists('fulltext', $searchParams))
280283
|| preg_match('/' . $fields['fulltext'] . ':\((.*)\)/', trim($searchParams['query']), $matches)
281284
) {
282285
// If the query already is a fulltext query e.g using the facets
@@ -298,7 +301,7 @@ public function makeFacetsMenuArray(array $facets): array
298301
}
299302

300303
// add filter query for date search
301-
if (!empty($this->searchParams['dateFrom']) && !empty($this->searchParams['dateTo'])) {
304+
if (array_key_exists('dateFrom', $this->searchParams) && array_key_exists('dateTo', $this->searchParams)) {
302305
// combine dateFrom and dateTo into filterquery as range search
303306
$search['params']['filterquery'][]['query'] = '{!join from=' . $fields['uid'] . ' to=' . $fields['uid'] . '}' . $fields['date'] . ':[' . $this->searchParams['dateFrom'] . ' TO ' . $this->searchParams['dateTo'] . ']';
304307
}
@@ -326,7 +329,7 @@ public function makeFacetsMenuArray(array $facets): array
326329
}
327330
}
328331

329-
if (isset($this->searchParams['fq']) && is_array($this->searchParams['fq'])) {
332+
if (array_key_exists('fq', $this->searchParams) && is_array($this->searchParams['fq'])) {
330333
foreach ($this->searchParams['fq'] as $fq) {
331334
$search['params']['filterquery'][]['query'] = $fq;
332335
}

Classes/Controller/ToolboxController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,18 @@ private function renderImageDownloadTool(): void
321321
private function getFile(int $page, array $fileGrps): array
322322
{
323323
$file = [];
324+
$physicalStructureInfo = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$page]] ?? null;
324325
while ($fileGrp = @array_pop($fileGrps)) {
325-
$physicalStructureInfo = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$page]];
326-
$fileId = $physicalStructureInfo['files'][$fileGrp];
327-
if (!empty($fileId)) {
328-
$file['url'] = $this->currentDocument->getDownloadLocation($fileId);
329-
$file['mimetype'] = $this->currentDocument->getFileMimeType($fileId);
326+
if (isset($physicalStructureInfo['files'][$fileGrp])) {
327+
$fileId = $physicalStructureInfo['files'][$fileGrp];
328+
if (!empty($fileId)) {
329+
$file['url'] = $this->currentDocument->getDownloadLocation($fileId);
330+
$file['mimetype'] = $this->currentDocument->getFileMimeType($fileId);
331+
} else {
332+
$this->logger->warning('File not found in fileGrp "' . $fileGrp . '"');
333+
}
330334
} else {
331-
$this->logger->warning('File not found in fileGrp "' . $fileGrp . '"');
335+
$this->logger->warning('fileGrp "' . $fileGrp . '" not found in Document mets:fileSec');
332336
}
333337
}
334338
return $file;

Classes/Domain/Repository/DocumentRepository.php

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,4 +645,172 @@ private function findSolr($collections, $settings, $searchParams, $listedMetadat
645645
$search->prepare();
646646
return $search;
647647
}
648+
649+
/**
650+
* Find the uid of the previous document relative to the current document uid.
651+
* Otherwise backtrack the closest previous leaf node.
652+
*
653+
* @access public
654+
*
655+
* @param int $uid
656+
*
657+
* @return int|null
658+
*/
659+
public function getPreviousDocumentUid($uid)
660+
{
661+
$currentDocument = $this->findOneByUid($uid);
662+
if ($currentDocument) {
663+
$currentVolume = '';
664+
$parentId = $currentDocument->getPartof();
665+
666+
if ($parentId) {
667+
668+
$currentVolume = (string) $currentDocument->getVolumeSorting();
669+
670+
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
671+
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_documents');
672+
673+
// Grab previous volume
674+
$prevDocument = $queryBuilder
675+
->select(
676+
'tx_dlf_documents.uid AS uid'
677+
)
678+
->from('tx_dlf_documents')
679+
->where(
680+
$queryBuilder->expr()->eq('tx_dlf_documents.partof', (int) $parentId),
681+
'tx_dlf_documents.volume_sorting < \'' . $currentVolume . '\''
682+
)
683+
->add('orderBy', 'volume_sorting desc')
684+
->addOrderBy('tx_dlf_documents.volume_sorting')
685+
->execute()
686+
->fetch();
687+
688+
if (!empty($prevDocument)) {
689+
return $prevDocument['uid'];
690+
}
691+
692+
return $this->getLastChild($this->getPreviousDocumentUid($parentId));
693+
}
694+
}
695+
696+
return null;
697+
}
698+
699+
/**
700+
* Find the uid of the next document relative to the current document uid.
701+
* Otherwise backtrack the closest next leaf node.
702+
*
703+
* @access public
704+
*
705+
* @param int $uid
706+
*
707+
* @return int|null
708+
*/
709+
public function getNextDocumentUid($uid)
710+
{
711+
$currentDocument = $this->findOneByUid($uid);
712+
if ($currentDocument) {
713+
$currentVolume = '';
714+
$parentId = $currentDocument->getPartof();
715+
716+
if ($parentId) {
717+
718+
$currentVolume = (string) $currentDocument->getVolumeSorting();
719+
720+
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
721+
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_documents');
722+
723+
// Grab next volume
724+
$nextDocument = $queryBuilder
725+
->select(
726+
'tx_dlf_documents.uid AS uid'
727+
)
728+
->from('tx_dlf_documents')
729+
->where(
730+
$queryBuilder->expr()->eq('tx_dlf_documents.partof', (int) $parentId),
731+
'tx_dlf_documents.volume_sorting > \'' . $currentVolume . '\''
732+
)
733+
->add('orderBy', 'volume_sorting asc')
734+
->addOrderBy('tx_dlf_documents.volume_sorting')
735+
->execute()
736+
->fetch();
737+
738+
if (!empty($nextDocument)) {
739+
return $nextDocument['uid'];
740+
}
741+
742+
return $this->getFirstChild($this->getNextDocumentUid($parentId));
743+
}
744+
}
745+
746+
return null;
747+
}
748+
749+
/**
750+
* Find the uid of the first leaf node
751+
*
752+
* @access public
753+
*
754+
* @param int $uid
755+
*
756+
* @return int
757+
*/
758+
public function getFirstChild($uid)
759+
{
760+
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
761+
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_documents');
762+
763+
$child = $queryBuilder
764+
->select(
765+
'tx_dlf_documents.uid AS uid'
766+
)
767+
->from('tx_dlf_documents')
768+
->where(
769+
$queryBuilder->expr()->eq('tx_dlf_documents.partof', (int) $uid)
770+
)
771+
->add('orderBy', 'volume_sorting asc')
772+
->addOrderBy('tx_dlf_documents.volume_sorting')
773+
->execute()
774+
->fetch();
775+
776+
if (empty($child['uid'])) {
777+
return $uid;
778+
}
779+
780+
return $this->getFirstChild($child['uid']);
781+
}
782+
783+
/**
784+
* Find the uid of the last leaf node
785+
*
786+
* @access public
787+
*
788+
* @param int $uid
789+
*
790+
* @return int
791+
*/
792+
public function getLastChild($uid)
793+
{
794+
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
795+
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_documents');
796+
797+
$child = $queryBuilder
798+
->select(
799+
'tx_dlf_documents.uid AS uid'
800+
)
801+
->from('tx_dlf_documents')
802+
->where(
803+
$queryBuilder->expr()->eq('tx_dlf_documents.partof', (int) $uid)
804+
)
805+
->add('orderBy', 'volume_sorting desc')
806+
->addOrderBy('tx_dlf_documents.volume_sorting')
807+
->execute()
808+
->fetch();
809+
810+
if (empty($child['uid'])) {
811+
return $uid;
812+
}
813+
814+
return $this->getFirstChild($child['uid']);
815+
}
648816
}

Configuration/FlexForms/Navigation.xml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,24 @@
7272
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.rotation</numIndex>
7373
<numIndex index="1">rotation</numIndex>
7474
</numIndex>
75-
<numIndex index="10">
75+
<numIndex index="11">
7676
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.measureForward</numIndex>
7777
<numIndex index="1">measureForward</numIndex>
7878
</numIndex>
79-
<numIndex index="11">
79+
<numIndex index="12">
8080
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.measureBack</numIndex>
8181
<numIndex index="1">measureBack</numIndex>
8282
</numIndex>
83+
<numIndex index="13">
84+
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.documentBack</numIndex>
85+
<numIndex index="1">documentBack</numIndex>
86+
</numIndex>
87+
<numIndex index="14">
88+
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.documentForward</numIndex>
89+
<numIndex index="1">documentForward</numIndex>
90+
</numIndex>
8391
</items>
84-
<default>doublePage,pageFirst,pageBack,pageStepBack,pageSelect,pageForward,pageStepForward,pageLast,listView,zoom,rotation,measureForward,measureBack</default>
92+
<default>doublePage,pageFirst,pageBack,pageStepBack,pageSelect,pageForward,pageStepForward,pageLast,listView,zoom,rotation,measureForward,measureBack,documentBack,documentForward</default>
8593
<minitems>1</minitems>
8694
</config>
8795
</TCEforms>

Resources/Private/Language/de.locallang.xlf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@
293293
<source><![CDATA[Next Measure]]></source>
294294
<target><![CDATA[Nächster Takt]]></target>
295295
</trans-unit>
296+
<trans-unit id="navigation.documentBack" approved="yes">
297+
<source><![CDATA[Previous document]]></source>
298+
<target><![CDATA[Vorheriges Dokument]]></target>
299+
</trans-unit>
300+
<trans-unit id="navigation.documentForward" approved="yes">
301+
<source><![CDATA[Next document]]></source>
302+
<target><![CDATA[Nächstes Dokument]]></target>
303+
</trans-unit>
296304
<trans-unit id="search.dateFrom" approved="yes">
297305
<source><![CDATA[From]]></source>
298306
<target><![CDATA[Von]]></target>

Resources/Private/Language/de.locallang_be.xlf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@
309309
<source><![CDATA[One measureBack back]]></source>
310310
<target><![CDATA[Ein Takt zurück]]></target>
311311
</trans-unit>
312+
<trans-unit id="plugins.navigation.flexform.features.documentBack" approved="yes">
313+
<source><![CDATA[Show previous document]]></source>
314+
<target><![CDATA[Ein Dokument zurück]]></target>
315+
</trans-unit>
316+
<trans-unit id="plugins.navigation.flexform.features.documentForward" approved="yes">
317+
<source><![CDATA[Show next document]]></source>
318+
<target><![CDATA[Ein Dokument vor]]></target>
319+
</trans-unit>
312320
<trans-unit id="plugins.navigation.title" approved="yes">
313321
<source><![CDATA[Kitodo: Navigation]]></source>
314322
<target><![CDATA[Kitodo: Navigation]]></target>

0 commit comments

Comments
 (0)