TYPO3 CMS  TYPO3_7-6
DeletedRecordsController.php
Go to the documentation of this file.
1 <?php
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 
23 
28 {
32  protected $runtimeCache = null;
33 
37  protected $tce;
38 
39  public function __construct()
40  {
41  $this->runtimeCache = $this->getMemoryCache();
42  $this->tce = GeneralUtility::makeInstance(DataHandler::class);
43  }
44 
52  public function transform($deletedRowsArray, $totalDeleted)
53  {
54  $total = 0;
55  $jsonArray = [
56  'rows' => []
57  ];
58 
59  if (is_array($deletedRowsArray)) {
60  $lang = $this->getLanguageService();
61  $backendUser = $this->getBackendUser();
62  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
63 
64  foreach ($deletedRowsArray as $table => $rows) {
65  $total += count($deletedRowsArray[$table]);
66  foreach ($rows as $row) {
67  $pageTitle = $this->getPageTitle((int)$row['pid']);
68  $backendUser = BackendUtility::getRecord('be_users', $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'username', '', false);
69  $jsonArray['rows'][] = [
70  'uid' => $row['uid'],
71  'pid' => $row['pid'],
72  'icon' => $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render(),
73  'pageTitle' => RecyclerUtility::getUtf8String($pageTitle),
74  'table' => $table,
75  'crdate' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['crdate']]),
76  'tstamp' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['tstamp']]),
77  'owner' => htmlspecialchars($backendUser['username']),
78  'owner_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']],
79  'tableTitle' => RecyclerUtility::getUtf8String($lang->sL($GLOBALS['TCA'][$table]['ctrl']['title'])),
80  'title' => htmlspecialchars(RecyclerUtility::getUtf8String(BackendUtility::getRecordTitle($table, $row))),
81  'path' => RecyclerUtility::getRecordPath($row['pid'])
82  ];
83  }
84  }
85  }
86  $jsonArray['total'] = $totalDeleted;
87  return $jsonArray;
88  }
89 
96  protected function getPageTitle($pageId)
97  {
98  $cacheId = 'recycler-pagetitle-' . $pageId;
99  if ($this->runtimeCache->has($cacheId)) {
100  $pageTitle = $this->runtimeCache->get($cacheId);
101  } else {
102  if ($pageId === 0) {
103  $pageTitle = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
104  } else {
105  $recordInfo = $this->tce->recordInfo('pages', $pageId, 'title');
106  $pageTitle = $recordInfo['title'];
107  }
108  $this->runtimeCache->set($cacheId, $pageTitle);
109  }
110  return $pageTitle;
111  }
112 
118  protected function getLanguageService()
119  {
120  return $GLOBALS['LANG'];
121  }
122 
128  protected function getBackendUser()
129  {
130  return $GLOBALS['BE_USER'];
131  }
132 
138  protected function getCacheManager()
139  {
140  return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
141  }
142 
148  protected function getMemoryCache()
149  {
150  return $this->getCacheManager()->getCache('cache_runtime');
151  }
152 }
static getRecordPath($uid, $clause='', $titleLimit=1000, $fullTitleLimit=0)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']