TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
RecyclerAjaxController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Recycler\Controller;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
25 
30 {
36  protected $conf = [];
37 
41  public function __construct()
42  {
43  // Configuration, variable assignment
44  $this->conf['action'] = GeneralUtility::_GP('action');
45  $this->conf['table'] = GeneralUtility::_GP('table') ? GeneralUtility::_GP('table') : '';
46  if (isset($modTS['properties']['recordsPageLimit']) && (int)$modTS['properties']['recordsPageLimit'] > 0) {
47  $this->conf['limit'] = (int)$modTS['properties']['recordsPageLimit'];
48  } else {
49  $this->conf['limit'] = 25;
50  }
51  $this->conf['start'] = GeneralUtility::_GP('start') ? (int)GeneralUtility::_GP('start') : 0;
52  $this->conf['filterTxt'] = GeneralUtility::_GP('filterTxt') ? GeneralUtility::_GP('filterTxt') : '';
53  $this->conf['startUid'] = GeneralUtility::_GP('startUid') ? (int)GeneralUtility::_GP('startUid') : 0;
54  $this->conf['depth'] = GeneralUtility::_GP('depth') ? (int)GeneralUtility::_GP('depth') : 0;
55  $this->conf['records'] = GeneralUtility::_GP('records') ? GeneralUtility::_GP('records') : null;
56  $this->conf['recursive'] = GeneralUtility::_GP('recursive') ? (bool)GeneralUtility::_GP('recursive') : false;
57  }
58 
66  public function dispatch(ServerRequestInterface $request, ResponseInterface $response)
67  {
68  $extPath = ExtensionManagementUtility::extPath('recycler');
69  /* @var $view StandaloneView */
70  $view = GeneralUtility::makeInstance(StandaloneView::class);
71  $view->setPartialRootPaths(['default' => $extPath . 'Resources/Private/Partials']);
72 
73  $content = '';
74  // Determine the scripts to execute
75  switch ($this->conf['action']) {
76  case 'getTables':
77  $this->setDataInSession('depthSelection', $this->conf['depth']);
78 
79  /* @var $model Tables */
80  $model = GeneralUtility::makeInstance(Tables::class);
81  $content = $model->getTables($this->conf['startUid'], $this->conf['depth']);
82  break;
83  case 'getDeletedRecords':
84  $this->setDataInSession('tableSelection', $this->conf['table']);
85  $this->setDataInSession('depthSelection', $this->conf['depth']);
86  $this->setDataInSession('resultLimit', $this->conf['limit']);
87 
88  /* @var $model DeletedRecords */
89  $model = GeneralUtility::makeInstance(DeletedRecords::class);
90  $model->loadData($this->conf['startUid'], $this->conf['table'], $this->conf['depth'], $this->conf['start'] . ',' . $this->conf['limit'], $this->conf['filterTxt']);
91  $deletedRowsArray = $model->getDeletedRows();
92 
93  $model = GeneralUtility::makeInstance(DeletedRecords::class);
94  $totalDeleted = $model->getTotalCount($this->conf['startUid'], $this->conf['table'], $this->conf['depth'], $this->conf['filterTxt']);
95 
96  /* @var $controller DeletedRecordsController */
97  $controller = GeneralUtility::makeInstance(DeletedRecordsController::class);
98  $recordsArray = $controller->transform($deletedRowsArray, $totalDeleted);
99 
100  $modTS = $this->getBackendUser()->getTSConfig('mod.recycler');
101  $allowDelete = $this->getBackendUser()->isAdmin() ? true : (bool)$modTS['properties']['allowDelete'];
102 
103  $view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/Ajax/RecordsTable.html');
104  $view->assign('records', $recordsArray['rows']);
105  $view->assign('allowDelete', $allowDelete);
106  $view->assign('total', $recordsArray['total']);
107  $content = [
108  'rows' => $view->render(),
109  'totalItems' => $recordsArray['total']
110  ];
111  break;
112  case 'undoRecords':
113  if (empty($this->conf['records']) || !is_array($this->conf['records'])) {
114  $content = [
115  'success' => false,
116  'message' => LocalizationUtility::translate('flashmessage.delete.norecordsselected', 'recycler')
117  ];
118  break;
119  }
120 
121  /* @var $model DeletedRecords */
122  $model = GeneralUtility::makeInstance(DeletedRecords::class);
123  $affectedRecords = $model->undeleteData($this->conf['records'], $this->conf['recursive']);
124  $messageKey = 'flashmessage.undo.' . ($affectedRecords !== false ? 'success' : 'failure') . '.' . ((int)$affectedRecords === 1 ? 'singular' : 'plural');
125  $content = [
126  'success' => true,
127  'message' => sprintf(LocalizationUtility::translate($messageKey, 'recycler'), $affectedRecords)
128  ];
129  break;
130  case 'deleteRecords':
131  if (empty($this->conf['records']) || !is_array($this->conf['records'])) {
132  $content = [
133  'success' => false,
134  'message' => LocalizationUtility::translate('flashmessage.delete.norecordsselected', 'recycler')
135  ];
136  break;
137  }
138 
139  /* @var $model DeletedRecords */
140  $model = GeneralUtility::makeInstance(DeletedRecords::class);
141  $success = $model->deleteData($this->conf['records']);
142  $affectedRecords = count($this->conf['records']);
143  $messageKey = 'flashmessage.delete.' . ($success ? 'success' : 'failure') . '.' . ($affectedRecords === 1 ? 'singular' : 'plural');
144  $content = [
145  'success' => true,
146  'message' => sprintf(LocalizationUtility::translate($messageKey, 'recycler'), $affectedRecords)
147  ];
148  break;
149  }
150  $response->getBody()->write(json_encode($content));
151  return $response;
152  }
153 
161  protected function setDataInSession($identifier, $data)
162  {
163  $beUser = $this->getBackendUser();
164  $beUser->uc['tx_recycler'][$identifier] = $data;
165  $beUser->writeUC();
166  }
167 
173  protected function getBackendUser()
174  {
175  return $GLOBALS['BE_USER'];
176  }
177 
181  protected function getLanguageService()
182  {
183  return $GLOBALS['LANG'];
184  }
185 }
static translate($key, $extensionName, $arguments=null)
dispatch(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)