Skip to content

Commit

Permalink
[TASK] add pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
smeviuscps committed Jun 14, 2023
1 parent 42cdce3 commit b013cc3
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 14 deletions.
37 changes: 37 additions & 0 deletions Classes/Controller/Backend/CourseBackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
use DWenzel\T3events\Controller\TranslateTrait;
use DWenzel\T3events\Controller\VenueRepositoryTrait;
use DWenzel\T3events\Domain\Model\Dto\ButtonDemand;
use DWenzel\T3events\Pagination\NumberedPagination;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;

/**
Expand Down Expand Up @@ -113,7 +117,22 @@ public function listAction($overwriteDemand = null)
$configuration = $this->configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
);

// pagination
$paginationConfiguration = $this->settings['event']['list']['paginate'] ?? [];
$itemsPerPage = (int)(($paginationConfiguration['itemsPerPage'] ?? '') ?: 10);
$maximumNumberOfLinks = (int)($paginationConfiguration['maximumNumberOfLinks'] ?? 0);

$currentPage = max(1, $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1);
#$paginator = new ArrayPaginator($contacts->toArray(), $currentPage, $itemsPerPage);
$paginator = GeneralUtility::makeInstance(QueryResultPaginator::class, $courses, $currentPage, $itemsPerPage, (int)($this->settings['limit'] ?? 0), (int)($this->settings['offset'] ?? 0));
$paginationClass = $paginationConfiguration['class'] ?? NumberedPagination::class;
#$pagination = new SimplePagination($paginator);
$pagination = $this->getPagination($paginationClass, $maximumNumberOfLinks, $paginator);

$templateVariables = [
'paginator' => $paginator,
'pagination' => $pagination,
'courses' => $courses,
'demand' => $demand,
'overwriteDemand' => $overwriteDemand,
Expand Down Expand Up @@ -141,4 +160,22 @@ public function getConfigurationManager()
{
return $this->configurationManager;
}

/**
* @param $paginationClass
* @param int $maximumNumberOfLinks
* @param $paginator
* @return \#o#Э#A#M#C\GeorgRinger\News\Controller\NewsController.getPagination.0|NumberedPagination|mixed|\Psr\Log\LoggerAwareInterface|string|SimplePagination|\TYPO3\CMS\Core\SingletonInterface
*/
protected function getPagination($paginationClass, int $maximumNumberOfLinks, $paginator)
{
if (class_exists(NumberedPagination::class) && $paginationClass === NumberedPagination::class && $maximumNumberOfLinks) {
$pagination = GeneralUtility::makeInstance(NumberedPagination::class, $paginator, $maximumNumberOfLinks);
} elseif (class_exists($paginationClass)) {
$pagination = GeneralUtility::makeInstance($paginationClass, $paginator);
} else {
$pagination = GeneralUtility::makeInstance(SimplePagination::class, $paginator);
}
return $pagination;
}
}
42 changes: 42 additions & 0 deletions Classes/Controller/Backend/ScheduleBackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use DWenzel\T3events\Controller\ModuleDataTrait;
use DWenzel\T3events\Controller\PerformanceController;
use DWenzel\T3events\Controller\SettingsUtilityTrait;
use DWenzel\T3events\Pagination\NumberedPagination;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;

/**
* Class ScheduleBackendController
Expand Down Expand Up @@ -70,7 +74,25 @@ public function listAction(array $overwriteDemand = null)

$this->overwriteDemandObject($demand, $overwriteDemand);

$performances = $this->performanceRepository->findDemanded($demand);

// pagination
$paginationConfiguration = $this->settings['event']['list']['paginate'] ?? [];
$itemsPerPage = (int)(($paginationConfiguration['itemsPerPage'] ?? '') ?: 10);
$maximumNumberOfLinks = (int)($paginationConfiguration['maximumNumberOfLinks'] ?? 0);

$currentPage = max(1, $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1);
#$paginator = new ArrayPaginator($contacts->toArray(), $currentPage, $itemsPerPage);
$paginator = GeneralUtility::makeInstance(QueryResultPaginator::class, $performances, $currentPage, $itemsPerPage, (int)($this->settings['limit'] ?? 0), (int)($this->settings['offset'] ?? 0));
$paginationClass = $paginationConfiguration['class'] ?? NumberedPagination::class;
#$pagination = new SimplePagination($paginator);
$pagination = $this->getPagination($paginationClass, $maximumNumberOfLinks, $paginator);



$templateVariables = [
'paginator' => $paginator,
'pagination' => $pagination,
'performances' => $this->performanceRepository->findDemanded($demand),
'overwriteDemand' => $overwriteDemand,
'demand' => $demand,
Expand All @@ -90,4 +112,24 @@ public function getConfigurationManager()
return $this->configurationManager;
}



/**
* @param $paginationClass
* @param int $maximumNumberOfLinks
* @param $paginator
* @return \#o#Э#A#M#C\GeorgRinger\News\Controller\NewsController.getPagination.0|NumberedPagination|mixed|\Psr\Log\LoggerAwareInterface|string|SimplePagination|\TYPO3\CMS\Core\SingletonInterface
*/
protected function getPagination($paginationClass, int $maximumNumberOfLinks, $paginator)
{
if (class_exists(NumberedPagination::class) && $paginationClass === NumberedPagination::class && $maximumNumberOfLinks) {
$pagination = GeneralUtility::makeInstance(NumberedPagination::class, $paginator, $maximumNumberOfLinks);
} elseif (class_exists($paginationClass)) {
$pagination = GeneralUtility::makeInstance($paginationClass, $paginator);
} else {
$pagination = GeneralUtility::makeInstance(SimplePagination::class, $paginator);
}
return $pagination;
}

}
15 changes: 8 additions & 7 deletions Resources/Private/Templates/Backend/CourseBackend/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ <h1>{f:translate(key: 'header.courses')}</h1>
<f:comment>Paginated list</f:comment>
<f:if condition="{courses}">
<f:then>
<f:be.widget.paginate
objects="{courses}"
as="paginatedCourses"
configuration="{settings.paginate}"
>
<f:if condition="{settings.event.list.paginate.insertAbove}">
<f:render partial="Backend/Pagination" arguments="{pagination: pagination, paginator: pagination.paginator}" />
</f:if>
<div class="panel panel-space panel-default recordlist">
<table class="table table-striped table-hover typo3-dblist">
<thead>
Expand All @@ -37,7 +35,7 @@ <h1>{f:translate(key: 'header.courses')}</h1>
<th>{f:translate(key: 'label.audience', default: 'Audience')}</th>
</tr>
</thead>
<f:for each="{paginatedCourses}" as="course">
<f:for each="{paginator.paginatedItems}" as="course">
<tr class="db_list_normal">
<td nowrap="nowrap">{course.uid}</td>
<td nowrap="nowrap">
Expand Down Expand Up @@ -67,7 +65,10 @@ <h1>{f:translate(key: 'header.courses')}</h1>
</f:for>
</table>
</div>
</f:be.widget.paginate>

<f:if condition="{settings.event.list.paginate.insertBelow}">
<f:render partial="Backend/Pagination" arguments="{pagination: pagination, paginator: pagination.paginator}" />
</f:if>
</f:then>
</f:if>
</f:section>
Expand Down
80 changes: 80 additions & 0 deletions Resources/Private/Templates/Backend/Pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<f:if condition="{paginator.numberOfPages} > 1">
<div class="b-pagination">
<nav class="c-pagination" aria-label="{f:translate(key: 'pagination')}">
<ol class="pagination">
<f:if condition="{pagination.previousPageNumber} && {pagination.previousPageNumber} >= {pagination.firstPageNumber}">
<li class="previous">
<a class=""
href="{f:uri.action(action: actionName, arguments: {currentPage: pagination.previousPageNumber}, addQueryString: 1)}"
>
<f:translate key="tx_t3events.previous" extensionName="t3events"/>
</a>
</li>
</f:if>
<f:if condition="{pagination.displayRangeStart} > 1">
<li class="first">
<a class=""
href="{f:uri.page()}"
>
1
</a>
</li>
</f:if>
<f:if condition="{pagination.hasLessPages}">
<li><span>...</span></li>
</f:if>
<f:for each="{pagination.allPageNumbers}" as="page">
<f:if condition="{page} == {paginator.currentPageNumber}">
<f:then>
<li class="current">
{page}
</a>
</li>
</f:then>
<f:else>
<li class="">
<f:if condition="{page} > 1">
<f:then>
<a class=""
href="{f:uri.action(action: actionName, arguments: {currentPage: page}, addQueryString: 1)}"
>
{page}
</a>
</f:then>
<f:else>
<a class=""
href="{f:uri.page()}"
>
{page}
</a>
</f:else>
</f:if>
</li>
</f:else>
</f:if>
</f:for>
<f:if condition="{pagination.hasMorePages}">
<li><span>...</span></li>
</f:if>
<f:if condition="{pagination.displayRangeEnd} < {pagination.lastPageNumber}">
<li class="last">
<a class=""
href="{f:uri.action(action: actionName, arguments: {currentPage: pagination.lastPageNumber}, addQueryString: 1)}"
>
{paginator.numberOfPages}
</a>
</li>
</f:if>
<f:if condition="{pagination.nextPageNumber} && {pagination.nextPageNumber} <= {pagination.lastPageNumber}">
<li class="next">
<a class=""
href="{f:uri.action(action: actionName, arguments:{currentPage: pagination.nextPageNumber}, addQueryString: 1)}"
>
<f:translate key="tx_t3events.next" extensionName="t3events"/>
</a>
</li>
</f:if>
</ol>
</nav>
</div>
</f:if>
14 changes: 7 additions & 7 deletions Resources/Private/Templates/Backend/ScheduleBackend/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ <h1>{f:translate(key: 'header.schedules')}</h1>
<f:comment>Paginated list</f:comment>
<f:if condition="{performances}">
<f:then>
<f:be.widget.paginate
objects="{performances}"
as="paginatedPerformances"
configuration="{settings.paginate}"
>
<f:if condition="{settings.event.list.paginate.insertAbove}">
<f:render partial="Backend/Pagination" arguments="{pagination: pagination, paginator: pagination.paginator}" />
</f:if>
<div class="panel panel-space panel-default recordlist">
<table class="table table-striped table-hover typo3-dblist ">
<thead>
Expand All @@ -37,7 +35,7 @@ <h1>{f:translate(key: 'header.schedules')}</h1>
<th class="col-control"></th>
</tr>
</thead>
<f:for each="{paginatedPerformances}" as="lesson">
<f:for each="{paginator.paginatedItems}" as="lesson">
<tr class="db_list_normal">
<td nowrap="nowrap">{lesson.uid}</td>
<td nowrap="nowrap">
Expand All @@ -62,7 +60,9 @@ <h1>{f:translate(key: 'header.schedules')}</h1>
</f:for>
</table>
</div>
</f:be.widget.paginate>
<f:if condition="{settings.event.list.paginate.insertBelow}">
<f:render partial="Backend/Pagination" arguments="{pagination: pagination, paginator: pagination.paginator}" />
</f:if>
</f:then>
</f:if>
</f:section>
Expand Down

0 comments on commit b013cc3

Please sign in to comment.