DashboardController.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Meramo\Mrmbepages\Controller;
  3. use Meramo\Mrmbepages\Domain\Repository\ActivepageRepository;
  4. use Meramo\Mrmbepages\Controller\AbstractBackendController;
  5. use TYPO3\CMS\Backend\View\BackendTemplateView;
  6. use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
  7. use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
  8. use TYPO3\CMS\Core\Utility\GeneralUtility;
  9. /**
  10. * Dashboard controller class
  11. */
  12. class DashboardController extends AbstractBackendController
  13. {
  14. /**
  15. * Activepage repository
  16. *
  17. * @var Meramo\Mrmbepages\Domain\Repository\ActivepageRepository activepageRepository;
  18. */
  19. protected $activepageRepository;
  20. /**
  21. * Import Active repository by dependency injection
  22. *
  23. * @param ActivepageRepository $activepageRepository
  24. */
  25. public function injectBlogRepository(\Meramo\Mrmbepages\Domain\Repository\ActivepageRepository $activepageRepository): void
  26. {
  27. $this->activepageRepository = $activepageRepository;
  28. }
  29. /**
  30. * Initialize view
  31. *
  32. * @param ViewInterface
  33. */
  34. protected function initializeView(ViewInterface $view): void
  35. {
  36. if ($view instanceof BackendTemplateView) {
  37. /** @var BackendTemplateView $view */
  38. parent::initializeView($view);
  39. $this->generateMenu();
  40. }
  41. }
  42. /**
  43. * Initialize action
  44. */
  45. public function initializeAction(): void
  46. {
  47. $querySettings = $this->objectManager->get(Typo3QuerySettings::class);
  48. $querySettings->setRespectStoragePage(false);
  49. $querySettings->setIgnoreEnableFields(true);
  50. $this->activepageRepository->setDefaultQuerySettings($querySettings);
  51. }
  52. /**
  53. * Index action
  54. */
  55. public function indexAction()
  56. {
  57. $allActivepages = $this->activepageRepository->findActivePages();
  58. if(!$this->request->hasArgument('currentPage')) {
  59. $currentPage = 1;
  60. } else {
  61. $currentPage = $this->request->getArgument('currentPage');
  62. }
  63. $itemsPerPage = GeneralUtility::_GP('itemsPerPage') ?? 50;
  64. $paginations = $this->buildPagination($allActivepages, $itemsPerPage, $currentPage);
  65. //DebuggerUtility::var_dump($paginations);
  66. $pagination = [
  67. 'pages' => $paginations['paginatedData'],
  68. 'totalRecords' => $paginations['totalRecords'],
  69. 'totalPages' => $paginations['totalPages'],
  70. 'currentPage' => $paginations['currentPage'],
  71. 'previousPage' => $paginations['previousPage'],
  72. 'nextPage' => $paginations['nextPage'],
  73. 'firstPage' => $paginations['firstPage'],
  74. 'lastPage' => $paginations['lastPage'],
  75. 'pageRange' => range($paginations['firstPage'], $paginations['lastPage']),
  76. 'isFirstPage' => $paginations['isFirstPage'],
  77. 'isLastPage' => $paginations['isLastPage'],
  78. ];
  79. $this->view->assign('pagination', $pagination);
  80. }
  81. }