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