‪TYPO3CMS  9.5
ManagementController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
34 use TYPO3Fluid\Fluid\View\ViewInterface;
35 
41 {
47  protected ‪$moduleTemplate;
48 
52  protected ‪$view;
53 
57  protected ‪$request;
58 
62  protected ‪$iconFactory;
63 
67  public function ‪__construct()
68  {
69  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
70  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
71  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
72  $this->‪getLanguageService()->‪includeLLFile('EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf');
73  }
74 
81  public function ‪handleRequest(ServerRequestInterface ‪$request): ResponseInterface
82  {
83  $this->request = ‪$request;
84  $this->‪initializeView('overview');
85 
86  $this->‪overviewAction($request);
87  $this->moduleTemplate->setContent($this->view->render());
88  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
89  }
90 
95  protected function ‪overviewAction(ServerRequestInterface ‪$request)
96  {
97  $this->‪getButtons();
99  $redirectRepository = GeneralUtility::makeInstance(RedirectRepository::class, $demand);
100  $count = $redirectRepository->countRedirectsByByDemand();
101 
102  $this->view->assignMultiple([
103  'redirects' => $redirectRepository->findRedirectsByDemand(),
104  'hosts' => $redirectRepository->findHostsOfRedirects(),
105  'statusCodes' => $redirectRepository->findStatusCodesOfRedirects(),
106  'demand' => $demand,
107  'defaultUrl' => GeneralUtility::makeInstance(UrlService::class)->getDefaultUrl(),
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:25
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Redirects\Repository\Demand\getLimit
‪int getLimit()
Definition: Demand.php:114
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Redirects\Controller\ManagementController\preparePagination
‪array preparePagination(Demand $demand, int $count)
Definition: ManagementController.php:116
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:35
‪TYPO3\CMS\Redirects\Service\UrlService
Definition: UrlService.php:28
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:31
‪TYPO3\CMS\Redirects\Controller\ManagementController\$request
‪ServerRequestInterface $request
Definition: ManagementController.php:54
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Redirects\Controller\ManagementController\getButtons
‪getButtons()
Definition: ManagementController.php:156
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Redirects\Controller\ManagementController\initializeView
‪initializeView(string $templateName)
Definition: ManagementController.php:144
‪TYPO3\CMS\Redirects\Repository\Demand\getPage
‪int getPage()
Definition: Demand.php:174
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\mayMakeShortcut
‪bool mayMakeShortcut()
Definition: BackendUserAuthentication.php:939
‪TYPO3\CMS\Redirects\Controller\ManagementController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: ManagementController.php:46
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Redirects\Controller\ManagementController\getLanguageService
‪LanguageService getLanguageService()
Definition: ManagementController.php:199
‪TYPO3\CMS\Redirects\Repository\Demand\getOffset
‪int getOffset()
Definition: Demand.php:184
‪TYPO3\CMS\Core\Configuration\Features
Definition: Features.php:54
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Redirects\Repository\RedirectRepository
Definition: RedirectRepository.php:28
‪TYPO3\CMS\Redirects\Controller\ManagementController\handleRequest
‪ResponseInterface handleRequest(ServerRequestInterface $request)
Definition: ManagementController.php:77
‪TYPO3\CMS\Redirects\Controller\ManagementController\$iconFactory
‪IconFactory $iconFactory
Definition: ManagementController.php:58
‪TYPO3\CMS\Redirects\Controller\ManagementController\overviewAction
‪overviewAction(ServerRequestInterface $request)
Definition: ManagementController.php:91
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Redirects\Controller\ManagementController\__construct
‪__construct()
Definition: ManagementController.php:63
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Redirects\Controller\ManagementController\$view
‪ViewInterface $view
Definition: ManagementController.php:50
‪TYPO3\CMS\Redirects\Controller\ManagementController\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: ManagementController.php:207
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Redirects\Controller\ManagementController
Definition: ManagementController.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Redirects\Controller
Definition: ManagementController.php:3
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:40
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Redirects\Repository\Demand\createFromRequest
‪static Demand createFromRequest(ServerRequestInterface $request)
Definition: Demand.php:73