‪TYPO3CMS  10.4
DatabaseQueryProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
48 {
52  protected ‪$contentDataProcessor;
53 
57  public function ‪__construct()
58  {
59  $this->contentDataProcessor = GeneralUtility::makeInstance(ContentDataProcessor::class);
60  }
61 
72  public function ‪process(‪ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
73  {
74  if (isset($processorConfiguration['if.']) && !$cObj->‪checkIf($processorConfiguration['if.'])) {
75  return $processedData;
76  }
77 
78  // the table to query, if none given, exit
79  $tableName = $cObj->‪stdWrapValue('table', $processorConfiguration);
80  if (empty($tableName)) {
81  return $processedData;
82  }
83  if (isset($processorConfiguration['table.'])) {
84  unset($processorConfiguration['table.']);
85  }
86  if (isset($processorConfiguration['table'])) {
87  unset($processorConfiguration['table']);
88  }
89 
90  // The variable to be used within the result
91  $targetVariableName = $cObj->‪stdWrapValue('as', $processorConfiguration, 'records');
92 
93  // Execute a SQL statement to fetch the records
94  $records = $cObj->‪getRecords($tableName, $processorConfiguration);
95  $processedRecordVariables = [];
96  foreach ($records as $key => $record) {
98  $recordContentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
99  $recordContentObjectRenderer->start($record, $tableName);
100  $processedRecordVariables[$key] = ['data' => $record];
101  $processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]);
102  }
103 
104  $processedData[$targetVariableName] = $processedRecordVariables;
105 
106  return $processedData;
107  }
108 }
‪TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
Definition: ContentDataProcessor.php:25
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
Definition: DatabaseQueryProcessor.php:48
‪TYPO3\CMS\Frontend\DataProcessing
Definition: CommaSeparatedValueProcessor.php:16
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getRecords
‪array getRecords($tableName, array $queryConfiguration)
Definition: ContentObjectRenderer.php:6246
‪TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface
Definition: DataProcessorInterface.php:23
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrapValue
‪string stdWrapValue($key, array $config, $defaultValue='')
Definition: ContentObjectRenderer.php:1685
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\$contentDataProcessor
‪ContentDataProcessor $contentDataProcessor
Definition: DatabaseQueryProcessor.php:51
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\__construct
‪__construct()
Definition: DatabaseQueryProcessor.php:56
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\process
‪array process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
Definition: DatabaseQueryProcessor.php:71
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\checkIf
‪bool checkIf($conf)
Definition: ContentObjectRenderer.php:3074