TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DatabaseQueryProcessor.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\DataProcessing;
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 {
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 }
static makeInstance($className,...$constructorArguments)
process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)