Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Seamless document browsing #1380

Open
wants to merge 5 commits into
base: 5.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Classes/Controller/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public function mainAction(): void
$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);

Expand Down
164 changes: 164 additions & 0 deletions Classes/Domain/Repository/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,168 @@ 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|null
*/
public function getPreviousDocumentUid($uid)
{
$currentDocument = $this->findOneByUid($uid);
$currentVolume = '';
$parentId = $currentDocument->getPartof();

if ($parentId) {

$currentVolume = (string) $currentDocument->getVolumeSorting();

$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->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', (int) $parentId),
'tx_dlf_documents.volume_sorting < \'' . $currentVolume . '\''
)
->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));
}

return null;
}

/**
* 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|null
*/
public function getNextDocumentUid($uid)
{
$currentDocument = $this->findOneByUid($uid);
$currentVolume = '';
$parentId = $currentDocument->getPartof();

if ($parentId) {

$currentVolume = (string) $currentDocument->getVolumeSorting();

$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->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', (int) $parentId),
'tx_dlf_documents.volume_sorting > \'' . $currentVolume . '\''
)
->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));
}

return null;
}

/**
* Find the uid of the first leaf node
*
* @access public
*
* @param int $uid
*
* @return int
*/
public function getFirstChild($uid)
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->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', (int) $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)
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->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', (int) $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']);
}
}
14 changes: 11 additions & 3 deletions Configuration/FlexForms/Navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,24 @@
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.rotation</numIndex>
<numIndex index="1">rotation</numIndex>
</numIndex>
<numIndex index="10">
<numIndex index="11">
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.measureForward</numIndex>
<numIndex index="1">measureForward</numIndex>
</numIndex>
<numIndex index="11">
<numIndex index="12">
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.measureBack</numIndex>
<numIndex index="1">measureBack</numIndex>
</numIndex>
<numIndex index="13">
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.documentBack</numIndex>
<numIndex index="1">documentBack</numIndex>
</numIndex>
<numIndex index="14">
<numIndex index="0">LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.navigation.flexform.features.documentForward</numIndex>
<numIndex index="1">documentForward</numIndex>
</numIndex>
</items>
<default>doublePage,pageFirst,pageBack,pageStepBack,pageSelect,pageForward,pageStepForward,pageLast,listView,zoom,rotation,measureForward,measureBack</default>
<default>doublePage,pageFirst,pageBack,pageStepBack,pageSelect,pageForward,pageStepForward,pageLast,listView,zoom,rotation,measureForward,measureBack,documentBack,documentForward</default>
<minitems>1</minitems>
</config>
</TCEforms>
Expand Down
8 changes: 8 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@
<source><![CDATA[Next Measure]]></source>
<target><![CDATA[Nächster Takt]]></target>
</trans-unit>
<trans-unit id="navigation.documentBack" approved="yes">
<source><![CDATA[Previous document]]></source>
<target><![CDATA[Vorheriges Dokument]]></target>
</trans-unit>
<trans-unit id="navigation.documentForward" approved="yes">
<source><![CDATA[Next document]]></source>
<target><![CDATA[Nächstes Dokument]]></target>
</trans-unit>
<trans-unit id="search.dateFrom" approved="yes">
<source><![CDATA[From]]></source>
<target><![CDATA[Von]]></target>
Expand Down
8 changes: 8 additions & 0 deletions Resources/Private/Language/de.locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@
<source><![CDATA[One measureBack back]]></source>
<target><![CDATA[Ein Takt zurück]]></target>
</trans-unit>
<trans-unit id="plugins.navigation.flexform.features.documentBack" approved="yes">
<source><![CDATA[Show previous document]]></source>
<target><![CDATA[Ein Dokument zurück]]></target>
</trans-unit>
<trans-unit id="plugins.navigation.flexform.features.documentForward" approved="yes">
<source><![CDATA[Show next document]]></source>
<target><![CDATA[Ein Dokument vor]]></target>
</trans-unit>
<trans-unit id="plugins.navigation.title" approved="yes">
<source><![CDATA[Kitodo: Navigation]]></source>
<target><![CDATA[Kitodo: Navigation]]></target>
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
<trans-unit id="nextMeasure">
<source><![CDATA[Next Measure]]></source>
</trans-unit>
<trans-unit id="navigation.documentBack">
<source><![CDATA[Previous document]]></source>
</trans-unit>
<trans-unit id="navigation.documentForward">
<source><![CDATA[Next document]]></source>
</trans-unit>
<trans-unit id="selectPage">
<source><![CDATA[Page]]></source>
</trans-unit>
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@
<trans-unit id="plugins.navigation.flexform.features.measureBack">
<source><![CDATA[One measureBack back]]></source>
</trans-unit>
<trans-unit id="plugins.navigation.flexform.features.documentBack">
<source><![CDATA[Show previous document]]></source>
</trans-unit>
<trans-unit id="plugins.navigation.flexform.features.documentForward">
<source><![CDATA[Show next document]]></source>
</trans-unit>
<trans-unit id="plugins.navigation.title">
<source><![CDATA[Kitodo: Navigation]]></source>
</trans-unit>
Expand Down
34 changes: 34 additions & 0 deletions Resources/Private/Templates/Navigation/Main.html
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,38 @@
</f:if>
</f:section>

<f:section name="render.documentBack">
<div class="tx-dlf-navigation-documentBack">
<f:if condition="{documentBack}">
<f:then>
<f:link.action addQueryString="1" addQueryStringMethod="GET" additionalParams="{'tx_dlf[page]':'1', 'tx_dlf[id]': '{documentBack}'}" title="{f:translate(key: 'navigation.documentBack')}">
<f:translate key="navigation.documentBack"/>
</f:link.action>
</f:then>
<f:else>
<span title="{f:translate(key: 'navigation.documentBack')}">
<f:translate key="navigation.documentBack"/>
</span>
</f:else>
</f:if>
</div>
</f:section>

<f:section name="render.documentForward">
<div class="tx-dlf-navigation-documentForward">
<f:if condition="{documentForward}">
<f:then>
<f:link.action addQueryString="1" addQueryStringMethod="GET" additionalParams="{'tx_dlf[page]':'1', 'tx_dlf[id]': '{documentForward}'}" title="{f:translate(key: 'navigation.documentForward')}">
<f:translate key="navigation.documentForward"/>
</f:link.action>
</f:then>
<f:else>
<span title="{f:translate(key: 'navigation.documentForward')}">
<f:translate key="navigation.documentForward"/>
</span>
</f:else>
</f:if>
</div>
</f:section>

</html>
Loading