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 #1381

Open
wants to merge 2 commits into
base: master
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 @@ -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);

Expand Down
156 changes: 156 additions & 0 deletions Classes/Domain/Repository/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,160 @@
$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
*

Check notice on line 656 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L656

Whitespace found at end of line
* @return int
*/
public function getPreviousDocumentUid($uid)

Check notice on line 659 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L659

Avoid assigning values to variables in if clauses and the like (line '662', column '13').
{
$currentDocument = $this->findOneByUid($uid);
if ($parentId = $currentDocument->getPartof()) {

$currentVolume['volume_sorting'] = $currentDocument->getVolumeSorting();

Check notice on line 664 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L664

Avoid using undefined variables such as '$currentVolume' which will lead to PHP notices.

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_documents');

// Grab previous volume
$prevDocument = $queryBuilder
->select(

Check notice on line 671 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L671

Object operator not indented correctly; expected 16 spaces but found 12
'tx_dlf_documents.uid AS uid'
)
->from('tx_dlf_documents')

Check notice on line 674 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L674

Object operator not indented correctly; expected 16 spaces but found 12
->where(

Check notice on line 675 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L675

Object operator not indented correctly; expected 16 spaces but found 12
$queryBuilder->expr()->eq('tx_dlf_documents.partof', intval($parentId)),

Check warning on line 676 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L676

The use of function intval() is discouraged; use (int) construction instead.
'tx_dlf_documents.volume_sorting < \'' . strval($currentVolume['volume_sorting']) . '\''

Check notice on line 677 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L677

Avoid using undefined variables such as '$currentVolume' which will lead to PHP notices.

Check warning on line 677 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L677

The use of function strval() is discouraged; use (string) construction instead.
)
->add('orderBy', 'volume_sorting desc')

Check notice on line 679 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L679

Object operator not indented correctly; expected 16 spaces but found 12
->addOrderBy('tx_dlf_documents.volume_sorting')

Check notice on line 680 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L680

Object operator not indented correctly; expected 16 spaces but found 12
->execute()
->fetch();

if (!empty($prevDocument))

Check notice on line 684 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L684

Expected "if (...) {\n"; found "if (...)\n {\n"

Check notice on line 684 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L684

Expected 1 space after closing parenthesis; found newline
{
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)

Check notice on line 703 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L703

Avoid assigning values to variables in if clauses and the like (line '706', column '13').
{
$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']) . '\''

Check notice on line 721 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L721

Avoid using undefined variables such as '$currentVolume' which will lead to PHP notices.

Check warning on line 721 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L721

The use of function strval() is discouraged; use (string) construction instead.
)
->add('orderBy', 'volume_sorting asc')
->addOrderBy('tx_dlf_documents.volume_sorting')
->execute()
->fetch();

if (!empty($nextDocument))

Check notice on line 728 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L728

Expected "if (...) {\n"; found "if (...)\n {\n"

Check notice on line 728 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L728

Expected 1 space after closing parenthesis; found newline
{
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) {

Check notice on line 746 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L746

Opening brace should be on a new line

Check notice on line 746 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L746

Opening brace should be on a new line
$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))

Check warning on line 756 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L756

The use of function intval() is discouraged; use (int) construction instead.
)
->add('orderBy', 'volume_sorting asc')
->addOrderBy('tx_dlf_documents.volume_sorting')
->execute()
->fetch();

if(empty($child['uid']))

Check notice on line 763 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L763

Expected "if (...) {\n"; found "if(...)\n {\n"

Check notice on line 763 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L763

Expected 1 space after IF keyword; 0 found
{
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) {

Check notice on line 780 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L780

Opening brace should be on a new line

Check notice on line 780 in Classes/Domain/Repository/DocumentRepository.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Domain/Repository/DocumentRepository.php#L780

Opening brace should be on a new line
$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']);
}
}
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