|
|
@@ -0,0 +1,204 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Meramo\Pagemanager\Controller;
|
|
|
+
|
|
|
+use Meramo\Pagemanager\Domain\Model\ActivePage;
|
|
|
+use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
|
|
+use Meramo\Pagemanager\Domain\Repository\ActivePageRepository;
|
|
|
+//use TYPO3\CMS\Backend\View\BackendTemplateView;
|
|
|
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
|
|
+use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
+use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
|
|
|
+use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
|
|
+use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
|
|
+use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
|
|
|
+use TYPO3\CMS\Core\Pagination\ArrayPaginator;
|
|
|
+use TYPO3\CMS\Core\Pagination\SimplePagination;
|
|
|
+
|
|
|
+class BackendController extends ActionController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * BackendTemplateContainer
|
|
|
+ *
|
|
|
+ * @var \TYPO3\CMS\Backend\View\BackendTemplateView
|
|
|
+ */
|
|
|
+ protected $view;
|
|
|
+ /**
|
|
|
+ * Backend Template Container
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected $defaultViewObjectName = \TYPO3\CMS\Backend\View\BackendTemplateView::class;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var activePageRepository
|
|
|
+ */
|
|
|
+ protected $activePageRepository;
|
|
|
+
|
|
|
+ public function __construct(ActivePageRepository $activePageRepository)
|
|
|
+ {
|
|
|
+ $this->activePageRepository = $activePageRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function translate($key, $arguments): string
|
|
|
+ {
|
|
|
+ return LocalizationUtility::translate(
|
|
|
+ $key,
|
|
|
+ 'pagemanager',
|
|
|
+ $arguments
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return ViewInterface
|
|
|
+ */
|
|
|
+ protected function resolveView(): \TYPO3\CMS\Backend\View\BackendTemplateView
|
|
|
+ {
|
|
|
+ $view = parent::resolveView();
|
|
|
+
|
|
|
+ $view->assignMultiple([
|
|
|
+ 'extensionName' => $this->request->getControllerExtensionName(),
|
|
|
+ 'controllerName' => $this->request->getControllerName(),
|
|
|
+ 'actionName' => $this->request->getControllerActionName()
|
|
|
+ ]);
|
|
|
+ // var_dump($view);
|
|
|
+ return $view;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ protected function generateMenu()
|
|
|
+ {
|
|
|
+ $menuItems = [
|
|
|
+ 'activePage' => [
|
|
|
+ 'controller' => 'Backend',
|
|
|
+ 'action' => 'index',
|
|
|
+ 'label' => 'Heute oder demnächst auslaufende Beiträge'
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ // Generate Backend Active select Box
|
|
|
+ $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
|
|
|
+ $menu->setIdentifier('PageManagerModuleMenu');
|
|
|
+
|
|
|
+ // $menu = GeneralUtility::makeInstance(Menu::class);
|
|
|
+ // $menu->setIdentifier('PageManagerModuleMenu');
|
|
|
+
|
|
|
+ foreach ($menuItems as $menuItemConfig) {
|
|
|
+ $isActive = false;
|
|
|
+ if ($this->request->getControllerName() === $menuItemConfig['controller']) {
|
|
|
+ if ($this->request->getControllerActionName() === $menuItemConfig['action']) {
|
|
|
+ $isActive = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $menuItem = $menu->makeMenuItem()
|
|
|
+ ->setTitle($menuItemConfig['label'])
|
|
|
+ ->setHref($this->getHref($menuItemConfig['controller'], $menuItemConfig['action']))
|
|
|
+ ->setActive($isActive);
|
|
|
+ $menu->addMenuItem($menuItem);
|
|
|
+ }
|
|
|
+ $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getHref($controller, $action, $parameters = [])
|
|
|
+ {
|
|
|
+ $uriBuilder = $this->objectManager->get(UriBuilder::class);
|
|
|
+ $uriBuilder->setRequest($this->request);
|
|
|
+ return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initialize view
|
|
|
+ *
|
|
|
+ * @param ViewInterface $view
|
|
|
+ */
|
|
|
+ protected function initializeView(ViewInterface $view)
|
|
|
+ {
|
|
|
+ if ($view instanceof \TYPO3\CMS\Backend\View\BackendTemplateView) {
|
|
|
+ /** @var \TYPO3\CMS\Backend\View\BackendTemplateView $view */
|
|
|
+ parent::initializeView($view);
|
|
|
+ //$this->generateMenu();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function createCategoryFromSlug($slug)
|
|
|
+ {
|
|
|
+ if (substr($slug, 0, 1) === '/') {
|
|
|
+ $value = ltrim($slug, '/');
|
|
|
+
|
|
|
+ if (substr($slug, 0, 1) === '_') {
|
|
|
+ $value = ltrim($slug, '_');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = explode('/', $slug);
|
|
|
+ }
|
|
|
+ return $data[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function indexAction()
|
|
|
+ {
|
|
|
+ $activePages = $this->activePageRepository->findActivePagesAndPageCreatetors();
|
|
|
+
|
|
|
+ $pageObjectArray = [];
|
|
|
+
|
|
|
+ //DebuggerUtility::var_dump($activePages);
|
|
|
+ foreach ($activePages as $activePage) {
|
|
|
+ $pageObj = new ActivePage();
|
|
|
+ $pageObj->setUid($activePage['uid']);
|
|
|
+ $pageObj->setStarttime($activePage['starttime']);
|
|
|
+ $pageObj->setEndtime($activePage['endtime']);
|
|
|
+ $pageObj->setTitle($activePage['title']);
|
|
|
+ $pageObj->setRoof($activePage['roof']);
|
|
|
+ $pageObj->setCategory($this->activePageRepository->createCategoryFromSlug($activePage['slug']));
|
|
|
+ $pageObj->setCreator($activePage['username']);
|
|
|
+ $pageObj->setFullName($activePage['realName']);
|
|
|
+
|
|
|
+ array_push($pageObjectArray, $pageObj);
|
|
|
+ }
|
|
|
+ $currentPage = $this->request->hasArgument('currentPage') ? $this->request->getArgument('currentPage') : 1;
|
|
|
+ $itemsPerPage = $this->settings['itemsPerPage'];
|
|
|
+ // if (count($pageObjectArray) > $numberPerPage) {
|
|
|
+ // $itemsPerPage = $numberPerPage;
|
|
|
+ // } else {
|
|
|
+ // $itemsPerPage = 25;
|
|
|
+ // }
|
|
|
+ $this->buildPagination($pageObjectArray, $currentPage, $itemsPerPage);
|
|
|
+
|
|
|
+
|
|
|
+ // $this->view->assign('activePages', $pageObjectArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function lastthirdtydays()
|
|
|
+ {
|
|
|
+ $activePagesExpiredInlast30days = $this->activePageRepository->findExpiredRecordsInTheLast30Days();
|
|
|
+
|
|
|
+ $this->view->assign('last30days', $activePagesExpiredInlast30days);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array $activePages
|
|
|
+ * @param int $currentPage
|
|
|
+ * @param int $itemsperpage
|
|
|
+ *
|
|
|
+ */
|
|
|
+ protected function buildPagination(array $activePages, int $currentPage = 1, int $itemsperpage)
|
|
|
+ {
|
|
|
+ $arrayPaginator = new ArrayPaginator($activePages, $currentPage, $itemsperpage);
|
|
|
+ $paging = new SimplePagination($arrayPaginator);
|
|
|
+ $totalNumberOfRecords = count($activePages);
|
|
|
+
|
|
|
+ $cPage = $arrayPaginator->getCurrentPageNumber();
|
|
|
+
|
|
|
+ $this->view->assignMultiple(
|
|
|
+ [
|
|
|
+ 'cpage' => $cPage,
|
|
|
+ 'totalRecords' => $totalNumberOfRecords,
|
|
|
+ 'activepages' => $activePages,
|
|
|
+ 'paginator' => $arrayPaginator,
|
|
|
+ 'paging' => $paging,
|
|
|
+ 'pages' => range(1, $paging->getLastPageNumber()),
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|