‪TYPO3CMS  9.5
DatabaseQueryProcessor.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 
21 
47 {
51  protected ‪$contentDataProcessor;
52 
56  public function ‪__construct()
57  {
58  $this->contentDataProcessor = GeneralUtility::makeInstance(ContentDataProcessor::class);
59  }
60 
71  public function ‪process(‪ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
72  {
73  if (isset($processorConfiguration['if.']) && !$cObj->‪checkIf($processorConfiguration['if.'])) {
74  return $processedData;
75  }
76 
77  // the table to query, if none given, exit
78  $tableName = $cObj->‪stdWrapValue('table', $processorConfiguration);
79  if (empty($tableName)) {
80  return $processedData;
81  }
82  if (isset($processorConfiguration['table.'])) {
83  unset($processorConfiguration['table.']);
84  }
85  if (isset($processorConfiguration['table'])) {
86  unset($processorConfiguration['table']);
87  }
88 
89  // The variable to be used within the result
90  $targetVariableName = $cObj->‪stdWrapValue('as', $processorConfiguration, 'records');
91 
92  // Execute a SQL statement to fetch the records
93  $records = $cObj->‪getRecords($tableName, $processorConfiguration);
94  $processedRecordVariables = [];
95  foreach ($records as $key => $record) {
97  $recordContentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
98  $recordContentObjectRenderer->start($record, $tableName);
99  $processedRecordVariables[$key] = ['data' => $record];
100  $processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]);
101  }
102 
103  $processedData[$targetVariableName] = $processedRecordVariables;
104 
105  return $processedData;
106  }
107 }
‪TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
Definition: ContentDataProcessor.php:24
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
Definition: DatabaseQueryProcessor.php:47
‪TYPO3\CMS\Frontend\DataProcessing
Definition: CommaSeparatedValueProcessor.php:2
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getRecords
‪array getRecords($tableName, array $queryConfiguration)
Definition: ContentObjectRenderer.php:6561
‪TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface
Definition: DataProcessorInterface.php:22
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrapValue
‪string stdWrapValue($key, array $config, $defaultValue='')
Definition: ContentObjectRenderer.php:1637
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\$contentDataProcessor
‪ContentDataProcessor $contentDataProcessor
Definition: DatabaseQueryProcessor.php:50
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\__construct
‪__construct()
Definition: DatabaseQueryProcessor.php:55
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\process
‪array process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
Definition: DatabaseQueryProcessor.php:70
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\checkIf
‪bool checkIf($conf)
Definition: ContentObjectRenderer.php:3059