‪TYPO3CMS  10.4
ManagementController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
35 use TYPO3Fluid\Fluid\View\ViewInterface;
36 
42 {
48  protected ‪$moduleTemplate;
49 
53  protected ‪$view;
54 
58  protected ‪$request;
59 
63  protected ‪$iconFactory;
64 
68  public function ‪__construct()
69  {
70  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
71  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
72  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Redirects/RedirectsModule');
73  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
74  $this->‪getLanguageService()->‪includeLLFile('EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf');
75  }
76 
83  public function ‪handleRequest(ServerRequestInterface ‪$request): ResponseInterface
84  {
85  $this->request = ‪$request;
86  $this->‪initializeView('overview');
87  $this->‪overviewAction($request);
88  $this->moduleTemplate->setContent($this->view->render());
89  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
90  }
91 
96  protected function ‪overviewAction(ServerRequestInterface ‪$request)
97  {
98  $this->‪getButtons();
100  $redirectRepository = GeneralUtility::makeInstance(RedirectRepository::class, $demand);
101  $count = $redirectRepository->countRedirectsByByDemand();
102 
103  $this->view->assignMultiple([
104  'redirects' => $redirectRepository->findRedirectsByDemand(),
105  'hosts' => $redirectRepository->findHostsOfRedirects(),
106  'statusCodes' => $redirectRepository->findStatusCodesOfRedirects(),
107  'demand' => $demand,
108  'showHitCounter' => GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('redirects.hitCount'),
109  'pagination' => $this->preparePagination($demand, $count),
110  ]);
111  }
112 
120  protected function ‪preparePagination(Demand $demand, int $count): array
121  {
122  $numberOfPages = ceil($count / $demand->getLimit());
123  $endRecord = $demand->getOffset() + $demand->getLimit();
124  if ($endRecord > $count) {
125  $endRecord = $count;
126  }
127 
128  $pagination = [
129  'current' => $demand->getPage(),
130  'numberOfPages' => $numberOfPages,
131  'hasLessPages' => $demand->getPage() > 1,
132  'hasMorePages' => $demand->getPage() < $numberOfPages,
133  'startRecord' => $demand->getOffset() + 1,
134  'endRecord' => $endRecord
135  ];
136  if ($pagination['current'] < $pagination['numberOfPages']) {
137  $pagination['nextPage'] = $pagination['current'] + 1;
138  }
139  if ($pagination['current'] > 1) {
140  $pagination['previousPage'] = $pagination['current'] - 1;
141  }
142  return $pagination;
143  }
144 
148  protected function ‪initializeView(string $templateName)
149  {
150  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
151  $this->view->setTemplate($templateName);
152  $this->view->setTemplateRootPaths(['EXT:redirects/Resources/Private/Templates/Management']);
153  $this->view->setPartialRootPaths(['EXT:redirects/Resources/Private/Partials']);
154  $this->view->setLayoutRootPaths(['EXT:redirects/Resources/Private/Layouts']);
155  }
156 
160  protected function ‪getButtons()
161  {
163  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
164 
165  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
166 
167  // Create new
168  $newRecordButton = $buttonBar->makeLinkButton()
169  ->setHref((string)$uriBuilder->buildUriFromRoute(
170  'record_edit',
171  [
172  'edit' => ['sys_redirect' => ['new'],
173  ],
174  'returnUrl' => (string)$uriBuilder->buildUriFromRoute('site_redirects'),
175  ]
176  ))
177  ->setTitle($this->‪getLanguageService()->getLL('redirect_add_text'))
178  ->setIcon($this->iconFactory->getIcon('actions-add', ‪Icon::SIZE_SMALL));
179  $buttonBar->addButton($newRecordButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 10);
180 
181  // Reload
182  $reloadButton = $buttonBar->makeLinkButton()
183  ->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
184  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
185  ->setIcon($this->iconFactory->getIcon('actions-refresh', ‪Icon::SIZE_SMALL));
186  $buttonBar->addButton($reloadButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
187 
188  // Shortcut
189  $mayMakeShortcut = $this->‪getBackendUserAuthentication()->‪mayMakeShortcut();
190  if ($mayMakeShortcut) {
191  $getVars = ['id', 'route'];
192 
193  $shortcutButton = $buttonBar->makeShortcutButton()
194  ->setModuleName('site_redirects')
195  ->setGetVariables($getVars);
196  $buttonBar->addButton($shortcutButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
197  }
198  }
199 
203  protected function ‪getLanguageService(): ‪LanguageService
204  {
205  return ‪$GLOBALS['LANG'];
206  }
207 
212  {
213  return ‪$GLOBALS['BE_USER'];
214  }
215 }
‪TYPO3\CMS\Redirects\Repository\Demand
Definition: Demand.php:27
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Redirects\Repository\Demand\getLimit
‪int getLimit()
Definition: Demand.php:116
‪TYPO3\CMS\Redirects\Controller\ManagementController\preparePagination
‪array preparePagination(Demand $demand, int $count)
Definition: ManagementController.php:116
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef, $setGlobal=null, $mergeLocalOntoDefault=null)
Definition: LanguageService.php:297
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:36
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Redirects\Controller\ManagementController\$request
‪ServerRequestInterface $request
Definition: ManagementController.php:55
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Redirects\Controller\ManagementController\getButtons
‪getButtons()
Definition: ManagementController.php:156
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Redirects\Controller\ManagementController\initializeView
‪initializeView(string $templateName)
Definition: ManagementController.php:144
‪TYPO3\CMS\Redirects\Repository\Demand\getPage
‪int getPage()
Definition: Demand.php:176
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\mayMakeShortcut
‪bool mayMakeShortcut()
Definition: BackendUserAuthentication.php:877
‪TYPO3\CMS\Redirects\Controller\ManagementController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: ManagementController.php:47
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Redirects\Controller\ManagementController\getLanguageService
‪LanguageService getLanguageService()
Definition: ManagementController.php:199
‪TYPO3\CMS\Redirects\Repository\Demand\getOffset
‪int getOffset()
Definition: Demand.php:186
‪TYPO3\CMS\Core\Configuration\Features
Definition: Features.php:56
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Redirects\Repository\RedirectRepository
Definition: RedirectRepository.php:30
‪TYPO3\CMS\Redirects\Controller\ManagementController\handleRequest
‪ResponseInterface handleRequest(ServerRequestInterface $request)
Definition: ManagementController.php:79
‪TYPO3\CMS\Redirects\Controller\ManagementController\$iconFactory
‪IconFactory $iconFactory
Definition: ManagementController.php:59
‪TYPO3\CMS\Redirects\Controller\ManagementController\overviewAction
‪overviewAction(ServerRequestInterface $request)
Definition: ManagementController.php:92
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Redirects\Controller\ManagementController\__construct
‪__construct()
Definition: ManagementController.php:64
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Redirects\Controller\ManagementController\$view
‪ViewInterface $view
Definition: ManagementController.php:51
‪TYPO3\CMS\Redirects\Controller\ManagementController\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: ManagementController.php:207
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Redirects\Controller\ManagementController
Definition: ManagementController.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Redirects\Controller
Definition: ManagementController.php:18
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:41
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Redirects\Repository\Demand\createFromRequest
‪static Demand createFromRequest(ServerRequestInterface $request)
Definition: Demand.php:75