‪TYPO3CMS  ‪main
DownloadRecordList.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 
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 
35 {
38 
40  {
41  $this->recordList = ‪$recordList;
42  $this->translationConfigurationProvider = ‪$translationConfigurationProvider;
43  }
44 
51  public function ‪getHeaderRow(array $columnsToRender): array
52  {
53  $columnsToRender = array_combine($columnsToRender, $columnsToRender);
54  $hooks = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvHeader'] ?? [];
55  if (!empty($hooks)) {
56  $hookParameters = [
57  'fields' => &$columnsToRender,
58  ];
59  foreach ($hooks as $hookFunction) {
60  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this->recordList);
61  }
62  }
63  return $columnsToRender;
64  }
65 
76  public function ‪getRecords(
77  string $table,
78  array $columnsToRender,
79  ‪BackendUserAuthentication $backendUser,
80  bool $hideTranslations = false,
81  bool $rawValues = false
82  ): array {
83  // Creating the list of fields to include in the SQL query
84  $selectFields = $this->recordList->getFieldsToSelect($table, $columnsToRender);
85  $queryResult = $this->recordList->getQueryBuilder($table, $selectFields)->executeQuery();
86  $l10nEnabled = BackendUtility::isTableLocalizable($table);
87  $result = [];
88  // Render items
89  while ($row = $queryResult->fetchAssociative()) {
90  // In offline workspace, look for alternative record
91  BackendUtility::workspaceOL($table, $row, $backendUser->workspace, true);
92  if (!is_array($row)) {
93  continue;
94  }
95  $result[] = $this->‪prepareRow($table, $row, $columnsToRender, $this->recordList->id, $rawValues);
96  if (!$l10nEnabled) {
97  continue;
98  }
99  if ($hideTranslations) {
100  continue;
101  }
102  // Guard clause so we can quickly return if a record is localized to "all languages"
103  // It should only be possible to localize a record off default (uid 0)
104  if ((int)$row[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']] === -1) {
105  continue;
106  }
107  $translationsRaw = $this->translationConfigurationProvider->translationInfo($table, $row['uid'], 0, $row, $selectFields);
108  foreach ($translationsRaw['translations'] ?? [] as $languageId => $translationRow) {
109  // In offline workspace, look for alternative record
110  BackendUtility::workspaceOL($table, $translationRow, $backendUser->workspace, true);
111  if (is_array($translationRow) && $backendUser->‪checkLanguageAccess($languageId)) {
112  $result[] = $this->‪prepareRow($table, $translationRow, $columnsToRender, $this->recordList->id, $rawValues);
113  }
114  }
115  }
116  return $result;
117  }
118 
130  protected function ‪prepareRow(string $table, array $row, array $columnsToRender, int $pageId, bool $rawValues): array
131  {
132  foreach ($columnsToRender as $columnName) {
133  if (!$rawValues) {
134  if ($columnName === ‪$GLOBALS['TCA'][$table]['ctrl']['label']) {
135  $row[$columnName] = BackendUtility::getRecordTitle($table, $row);
136  } elseif ($columnName !== 'pid') {
137  $row[$columnName] = BackendUtility::getProcessedValueExtra($table, $columnName, $row[$columnName], 0, $row['uid']);
138  }
139  }
140  }
141  $hooks = ‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvRow'] ?? [];
142  if (!empty($hooks)) {
143  $hookParameters = [
144  'databaseRow' => &$row,
145  'tableName' => $table,
146  'pageId' => $pageId,
147  ];
148  foreach ($hooks as $hookFunction) {
149  GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this->recordList);
150  }
151  }
152  return array_intersect_key($row, array_flip($columnsToRender));
153  }
154 }
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\getHeaderRow
‪array getHeaderRow(array $columnsToRender)
Definition: DownloadRecordList.php:51
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\prepareRow
‪array prepareRow(string $table, array $row, array $columnsToRender, int $pageId, bool $rawValues)
Definition: DownloadRecordList.php:130
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList
Definition: DownloadRecordList.php:35
‪TYPO3\CMS\Backend\RecordList\DatabaseRecordList
Definition: DatabaseRecordList.php:68
‪TYPO3\CMS\Backend\RecordList
Definition: DatabaseRecordList.php:18
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\$recordList
‪DatabaseRecordList $recordList
Definition: DownloadRecordList.php:36
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\__construct
‪__construct(DatabaseRecordList $recordList, TranslationConfigurationProvider $translationConfigurationProvider)
Definition: DownloadRecordList.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:559
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:61
‪TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
Definition: TranslationConfigurationProvider.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\$translationConfigurationProvider
‪TranslationConfigurationProvider $translationConfigurationProvider
Definition: DownloadRecordList.php:37
‪TYPO3\CMS\Backend\RecordList\DownloadRecordList\getRecords
‪array[] getRecords(string $table, array $columnsToRender, BackendUserAuthentication $backendUser, bool $hideTranslations=false, bool $rawValues=false)
Definition: DownloadRecordList.php:76