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

[BUGFIX] Replace paginate widget with custom Kitodo pagination #84

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
78 changes: 27 additions & 51 deletions Classes/Controller/SingleCollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,55 @@
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;

use Kitodo\Dlf\Common\Document;
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
use Kitodo\Dlf\Common\SolrPaginator;
use Kitodo\Dlf\Controller\AbstractController;
use Kitodo\Dlf\Domain\Repository\StructureRepository;
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
use TYPO3\CMS\Core\Pagination\SimplePagination;

class SingleCollectionController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
class SingleCollectionController extends AbstractController
{
/**
* DocumentRepository
*
* @var \Kitodo\Dlf\Domain\Repository\DocumentRepository
*/
protected $documentRepository;

/**
* StructureRepository
*
* @var \Kitodo\Dlf\Domain\Repository\StructureRepository
* @var StructureRepository
*/
protected $structureRepository;

/**
* CollectionRepository
*
* @var \Kitodo\Dlf\Domain\Repository\CollectionRepository
* @var CollectionRepository
*/
protected $collectionRepository;

/**
* MetadataRepository
*
* @var \Kitodo\Dlf\Domain\Repository\MetadataRepository
* @var MetadataRepository
*/
protected $metadataRepository;

/**
* @param \Kitodo\Dlf\Domain\Repository\DocumentRepository $documentRepository
*/
public function injectDocumentRepository(DocumentRepository $documentRepository)
{
$this->documentRepository = $documentRepository;
}

/**
* @param \Kitodo\Dlf\Domain\Repository\StructureRepository $structureRepository
* @param StructureRepository $structureRepository
*/
public function injectStructureRepository(StructureRepository $structureRepository)
{
$this->structureRepository = $structureRepository;
}

/**
* @param \Kitodo\Dlf\Domain\Repository\CollectionRepository $collectionRepository
* @param CollectionRepository $collectionRepository
*/
public function injectCollectionRepository(CollectionRepository $collectionRepository)
{
$this->collectionRepository = $collectionRepository;
}

/**
* @param \Kitodo\Dlf\Domain\Repository\MetadataRepository $metadataRepository
* @param MetadataRepository $metadataRepository
*/
public function injectMetadataRepository(MetadataRepository $metadataRepository)
{
Expand Down Expand Up @@ -133,46 +120,35 @@ public function showAction()
$searchParams['order'] = 'asc';
}

// Get current page from request data because the parameter is shared between plugins
$currentPage = $this->requestData['page'] ?? 1;

$collections = $this->collectionRepository->findAllByUids(GeneralUtility::intExplode(',', $this->settings['collections'], true));

// get all metadata records to be shown in results
$listedMetadata = $this->metadataRepository->findByIsListed(true);

// find all documents from Solr
$solrSearch = $this->documentRepository->findSolrByCollections($collections, $this->settings, $searchParams, $listedMetadata);
$solrResults = $this->documentRepository->findSolrByCollections($collections, $this->settings, $searchParams, $listedMetadata);

$itemsPerPage = $this->settings['list']['paginate']['itemsPerPage'];
if (empty($itemsPerPage)) {
$itemsPerPage = 25;
}
$solrPaginator = new SolrPaginator($solrResults, $currentPage, $itemsPerPage);
$simplePagination = new SimplePagination($solrPaginator);

$pagination = $this->buildSimplePagination($simplePagination, $solrPaginator);
$this->view->assignMultiple([ 'pagination' => $pagination, 'paginator' => $solrPaginator ]);

// get all sortable Metadata from Kitodo.Presentation
$metadata = $this->metadataRepository->findByIsSortable(true);

// Pagination of Results
// pass the currentPage to the fluid template to calculate current index of search result
$widgetPage = $this->getParametersSafely('@widget_0');
if (empty($widgetPage)) {
$widgetPage = ['currentPage' => 1];
}

$this->view->assign('documents', $solrSearch);
$this->view->assign('documents', $solrResults);
$this->view->assign('metadata', $metadata);
$this->view->assign('widgetPage', $widgetPage);
$this->view->assign('page', $currentPage);
$this->view->assign('lastSearch', $searchParams);
$this->view->assign('rawResults', $solrSearch->getSolrResults());
$this->view->assign('rawResults', $solrResults->getSolrResults());

}

/**
* Safely gets Parameters from request
* if they exist
*
* @param string $parameterName
*
* @return null|string|array
*/
protected function getParametersSafely($parameterName)
{
if ($this->request->hasArgument($parameterName)) {
return $this->request->getArgument($parameterName);
}
return null;
}

}
5 changes: 4 additions & 1 deletion Resources/Private/Less/Modules/Listresults.less
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
padding: 0 5px;
}
}
ul.f3-widget-paginator {
ul.pagination {
margin: 20px 0;
font-family: @font-sans-bold;
font-weight: bold;
Expand Down Expand Up @@ -87,6 +87,9 @@
font-weight: bold;
}
}
li.disabled {
visibility: hidden;
}
}
@media screen and (min-width: @phoneLandscapeViewportWidth) {
h2 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<ul class="pagination">
<f:if condition="{pagination.previousPageNumberG} && {pagination.previousPageNumberG} >= {pagination.firstPageNumber}">
<f:then>
<li class="first">
<f:link.action action="{action}" addQueryString="true" argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[page]'}" additionalParams="{'tx_dlf[page]': 1}" arguments="{searchParameter: lastSearch}" title="1">1</f:link.action>
</li>
<li class="previous">
<f:link.action action="{action}" addQueryString="true" argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[page]'}" additionalParams="{'tx_dlf[page]': pagination.previousPageNumber}" arguments="{searchParameter: lastSearch}" title="{f:translate(key: 'pagination.previous')}">{f:translate(key: 'prevPage')}</f:link.action>
</li>
</f:then>
<f:else>
<li class="first disabled">
<span>1</span>
</li>
<li class="previous disabled">
<span>{f:translate(key: 'prevPage')}</span>
</li>
</f:else>
</f:if>
<f:comment>add pages between first and last page, with dots if there are more than 5 pages (before or after) the respective page</f:comment>
<f:for each="{pagination.pagesR}" as="page">
<f:switch expression="{page.label}">
<f:comment>If page 1 is not to be output twice, please remove the comment</f:comment>
<f:comment>
<f:case value="1">
<f:comment>don't add first page a second time</f:comment>
</f:case>
</f:comment>
<f:comment>If last page is not to be output twice, please remove the comment</f:comment>
<f:comment>
<f:case value="{pagination.lastPageNumber}">
<f:comment>don't add last page a second time</f:comment>
</f:case>
</f:comment>
<f:defaultCase>
<f:switch expression="{page.label}">
<f:comment>add the dots</f:comment>
<f:case value="...">
<li class="dots">
<span class="dots">...</span>
</li>
</f:case>
<f:defaultCase>
<li class="{f:if(condition: '{page.label} == {paginator.currentPageNumber}', then:'current')}">
<f:link.action action="{action}" addQueryString="true" argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[page]'}" additionalParams="{'tx_dlf[page]': page.startRecordNumber}" arguments="{searchParameter: lastSearch}">{page.label}</f:link.action>
</li>
</f:defaultCase>
</f:switch>
</f:defaultCase>
</f:switch>
</f:for>
<f:if condition="{pagination.nextPageNumberG} && {pagination.nextPageNumberG} <= {pagination.lastPageNumber}">
<f:then>
<li class="last">
<f:link.action action="{action}" addQueryString="true" argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[page]'}" additionalParams="{'tx_dlf[page]': pagination.lastPageNumberG}" arguments="{searchParameter: lastSearch}" title="{pagination.lastPageNumber}">{pagination.lastPageNumber}</f:link.action>
</li>
<li class="next">
<f:link.action action="{action}" addQueryString="true" argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[page]'}" additionalParams="{'tx_dlf[page]': pagination.nextPageNumber}" arguments="{searchParameter: lastSearch}" title="{f:translate(key: 'nextPage')}">{f:translate(key: 'nextPage')}</f:link.action>
</li>
</f:then>
<f:else>
<li class="last disabled">
<span>{pagination.lastPageNumber}</span>
</li>
<li class="next disabled">
<span>{f:translate(key: 'nextPage')}</span>
</li>
</f:else>
</f:if>
</ul>

</html>
Loading