From b23b2067921750bb0fc45550d010f4d84806b341 Mon Sep 17 00:00:00 2001 From: Michael Kubina Date: Thu, 21 Nov 2024 11:37:32 +0100 Subject: [PATCH 1/2] add next/prev document functions and backtracking --- .../Domain/Repository/DocumentRepository.php | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/Classes/Domain/Repository/DocumentRepository.php b/Classes/Domain/Repository/DocumentRepository.php index e77a040aa..3b6031ece 100644 --- a/Classes/Domain/Repository/DocumentRepository.php +++ b/Classes/Domain/Repository/DocumentRepository.php @@ -645,4 +645,160 @@ private function findSolr($collections, $settings, $searchParams, $listedMetadat $search->prepare(); return $search; } + + /** + * Find the uid of the previous document relative to the current document uid. + * Otherwise backtrack the closest previous leaf node. + * + * @access public + * + * @param int $uid + * + * @return int + */ + public function getPreviousDocumentUid($uid) + { + $currentDocument = $this->findOneByUid($uid); + if ($parentId = $currentDocument->getPartof()) { + + $currentVolume['volume_sorting'] = $currentDocument->getVolumeSorting(); + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('tx_dlf_documents'); + + // Grab previous volume + $prevDocument = $queryBuilder + ->select( + 'tx_dlf_documents.uid AS uid' + ) + ->from('tx_dlf_documents') + ->where( + $queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($parentId)), + 'tx_dlf_documents.volume_sorting < \'' . strval($currentVolume['volume_sorting']) . '\'' + ) + ->add('orderBy', 'volume_sorting desc') + ->addOrderBy('tx_dlf_documents.volume_sorting') + ->execute() + ->fetch(); + + if (!empty($prevDocument)) + { + return $prevDocument['uid']; + } + + return $this->getLastChild($this->getPreviousDocumentUid($parentId)); + } + } + + /** + * Find the uid of the next document relative to the current document uid. + * Otherwise backtrack the closest next leaf node. + * + * @access public + * + * @param int $uid + * + * @return int + */ + public function getNextDocumentUid($uid) + { + $currentDocument = $this->findOneByUid($uid); + if ($parentId = $currentDocument->getPartof()) { + + $currentVolume['volume_sorting'] = $currentDocument->getVolumeSorting(); + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('tx_dlf_documents'); + + // Grab next volume + $nextDocument = $queryBuilder + ->select( + 'tx_dlf_documents.uid AS uid' + ) + ->from('tx_dlf_documents') + ->where( + $queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($parentId)), + 'tx_dlf_documents.volume_sorting > \'' . strval($currentVolume['volume_sorting']) . '\'' + ) + ->add('orderBy', 'volume_sorting asc') + ->addOrderBy('tx_dlf_documents.volume_sorting') + ->execute() + ->fetch(); + + if (!empty($nextDocument)) + { + return $nextDocument['uid']; + } + + return $this->getFirstChild($this->getNextDocumentUid($parentId)); + } + } + + /** + * Find the uid of the first leaf node + * + * @access public + * + * @param int $uid + * + * @return int + */ + public function getFirstChild($uid) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('tx_dlf_documents'); + + $child = $queryBuilder + ->select( + 'tx_dlf_documents.uid AS uid' + ) + ->from('tx_dlf_documents') + ->where( + $queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($uid)) + ) + ->add('orderBy', 'volume_sorting asc') + ->addOrderBy('tx_dlf_documents.volume_sorting') + ->execute() + ->fetch(); + + if(empty($child['uid'])) + { + return $uid; + } + + return $this->getFirstChild($child['uid']); + } + + /** + * Find the uid of the last leaf node + * + * @access public + * + * @param int $uid + * + * @return int + */ + public function getLastChild($uid) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('tx_dlf_documents'); + + $child = $queryBuilder + ->select( + 'tx_dlf_documents.uid AS uid' + ) + ->from('tx_dlf_documents') + ->where( + $queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($uid)) + ) + ->add('orderBy', 'volume_sorting desc') + ->addOrderBy('tx_dlf_documents.volume_sorting') + ->execute() + ->fetch(); + + if(empty($child['uid'])) + { + return $uid; + } + + return $this->getFirstChild($child['uid']); + } } From e1b7d379599603f1416e7d59c44b5f45da290698 Mon Sep 17 00:00:00 2001 From: Michael Kubina Date: Thu, 21 Nov 2024 11:44:05 +0100 Subject: [PATCH 2/2] add navigation feature and translations --- Classes/Controller/NavigationController.php | 8 +++++ Configuration/FlexForms/Navigation.xml | 14 ++++++-- Resources/Private/Language/de.locallang.xlf | 8 +++++ .../Private/Language/de.locallang_be.xlf | 8 +++++ Resources/Private/Language/locallang.xlf | 6 ++++ Resources/Private/Language/locallang_be.xlf | 6 ++++ .../Private/Templates/Navigation/Main.html | 34 +++++++++++++++++++ 7 files changed, 81 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/NavigationController.php b/Classes/Controller/NavigationController.php index 9d288eade..558121dea 100644 --- a/Classes/Controller/NavigationController.php +++ b/Classes/Controller/NavigationController.php @@ -81,6 +81,14 @@ public function mainAction(): ResponseInterface $this->viewData['requestData'] = $this->requestData; } + // get the closest previous sibling or leaf node + $prevDocumentUid = $this->documentRepository->getPreviousDocumentUid($this->document->getUid()); + $this->view->assign('documentBack', $prevDocumentUid); + + // get the closest next sibling or leaf node + $nextDocumentUid = $this->documentRepository->getNextDocumentUid($this->document->getUid()); + $this->view->assign('documentForward', $nextDocumentUid); + // Steps for X pages backward / forward. Double page view uses double steps. $pageSteps = $this->settings['pageStep'] * ($this->requestData['double'] + 1); diff --git a/Configuration/FlexForms/Navigation.xml b/Configuration/FlexForms/Navigation.xml index 3f98c73c0..72142da70 100644 --- a/Configuration/FlexForms/Navigation.xml +++ b/Configuration/FlexForms/Navigation.xml @@ -72,16 +72,24 @@ LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.rotation rotation - + LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.measureForward measureForward - + LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.measureBack measureBack + + LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.documentBack + documentBack + + + LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.documentForward + documentForward + - doublePage,pageFirst,pageBack,pageStepBack,pageSelect,pageForward,pageStepForward,pageLast,listView,zoom,rotation,measureForward,measureBack + doublePage,pageFirst,pageBack,pageStepBack,pageSelect,pageForward,pageStepForward,pageLast,listView,zoom,rotation,measureForward,measureBack,documentBack,documentForward 1 diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index d1b7392a9..5dba64ef9 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -293,6 +293,14 @@ + + + + + + + + diff --git a/Resources/Private/Language/de.locallang_be.xlf b/Resources/Private/Language/de.locallang_be.xlf index 779d0d3f4..3899aa245 100644 --- a/Resources/Private/Language/de.locallang_be.xlf +++ b/Resources/Private/Language/de.locallang_be.xlf @@ -309,6 +309,14 @@ + + + + + + + + diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index d1901621e..c355c9681 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -185,6 +185,12 @@ + + + + + + diff --git a/Resources/Private/Language/locallang_be.xlf b/Resources/Private/Language/locallang_be.xlf index 7b215dcf1..8c9b9c4c4 100644 --- a/Resources/Private/Language/locallang_be.xlf +++ b/Resources/Private/Language/locallang_be.xlf @@ -212,6 +212,12 @@ + + + + + + diff --git a/Resources/Private/Templates/Navigation/Main.html b/Resources/Private/Templates/Navigation/Main.html index 109c95812..f6a28f630 100644 --- a/Resources/Private/Templates/Navigation/Main.html +++ b/Resources/Private/Templates/Navigation/Main.html @@ -302,4 +302,38 @@ + +
+ + + + + + + + + + + + +
+
+ + +
+ + + + + + + + + + + + +
+
+