TYPO3 CMS  TYPO3_6-2
RecordsContentObject.php
Go to the documentation of this file.
1 <?php
3 
18 
26 
32  protected $itemArray = array();
33 
39  protected $data = array();
40 
47  public function render($conf = array()) {
48  // Reset items and data
49  $this->itemArray = array();
50  $this->data = array();
51 
52  $theValue = '';
53  $originalRec = $GLOBALS['TSFE']->currentRecord;
54  // If the currentRecord is set, we register, that this record has invoked this function.
55  // It's should not be allowed to do this again then!!
56  if ($originalRec) {
57  ++$GLOBALS['TSFE']->recordRegister[$originalRec];
58  }
59  $tables = isset($conf['tables.']) ? $this->cObj->stdWrap($conf['tables'], $conf['tables.']) : $conf['tables'];
60  $source = isset($conf['source.']) ? $this->cObj->stdWrap($conf['source'], $conf['source.']) : $conf['source'];
61  $categories = isset($conf['categories.']) ? $this->cObj->stdWrap($conf['categories'], $conf['categories.']) : $conf['categories'];
62 
63  $tablesArray = array_unique(GeneralUtility::trimExplode(',', $tables, TRUE));
64  if ($tables) {
65  // Add tables which have a configuration (note that this may create duplicate entries)
66  if (is_array($conf['conf.'])) {
67  foreach ($conf['conf.'] as $key => $value) {
68  if (substr($key, -1) != '.' && !in_array($key, $tablesArray)) {
69  $tablesArray[] = $key;
70  }
71  }
72  }
73 
74  // Get the data, depending on collection method.
75  // Property "source" is considered more precise and thus takes precedence over "categories"
76  if ($source) {
77  $this->collectRecordsFromSource($source, $tablesArray);
78  } elseif ($categories) {
79  $relationField = isset($conf['categories.']['relation.']) ? $this->cObj->stdWrap($conf['categories.']['relation'], $conf['categories.']['relation.']) : $conf['categories.']['relation'];
80  $this->collectRecordsFromCategories($categories, $tablesArray, $relationField);
81  }
82 
83  if (count($this->itemArray) > 0) {
85  $cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
86  $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
87  $this->cObj->currentRecordNumber = 0;
88  $this->cObj->currentRecordTotal = count($this->itemArray);
89  foreach ($this->itemArray as $val) {
90  $row = $this->data[$val['table']][$val['id']];
91  // Perform overlays if necessary (records coming from category collections are already overlaid)
92  if ($source) {
93  // Versioning preview
94  $GLOBALS['TSFE']->sys_page->versionOL($val['table'], $row);
95  // Language overlay
96  if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
97  if ($val['table'] === 'pages') {
98  $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
99  } else {
100  $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($val['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
101  }
102  }
103  }
104  // Might be unset during the overlay process
105  if (is_array($row)) {
106  $dontCheckPid = isset($conf['dontCheckPid.']) ? $this->cObj->stdWrap($conf['dontCheckPid'], $conf['dontCheckPid.']) : $conf['dontCheckPid'];
107  if (!$dontCheckPid) {
108  $row = $this->cObj->checkPid($row['pid']) ? $row : '';
109  }
110  if ($row && !$GLOBALS['TSFE']->recordRegister[($val['table'] . ':' . $val['id'])]) {
111  $renderObjName = $conf['conf.'][$val['table']] ?: '<' . $val['table'];
112  $renderObjKey = $conf['conf.'][$val['table']] ? 'conf.' . $val['table'] : '';
113  $renderObjConf = $conf['conf.'][$val['table'] . '.'];
114  $this->cObj->currentRecordNumber++;
115  $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
116  $GLOBALS['TSFE']->currentRecord = $val['table'] . ':' . $val['id'];
117  $this->cObj->lastChanged($row['tstamp']);
118  $cObj->start($row, $val['table']);
119  $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
120  $theValue .= $tmpValue;
121  }
122  }
123  }
124  }
125  }
126  $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
127  if ($wrap) {
128  $theValue = $this->cObj->wrap($theValue, $wrap);
129  }
130  if (isset($conf['stdWrap.'])) {
131  $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
132  }
133  // Restore
134  $GLOBALS['TSFE']->currentRecord = $originalRec;
135  if ($originalRec) {
136  --$GLOBALS['TSFE']->recordRegister[$originalRec];
137  }
138  return $theValue;
139  }
140 
148  protected function collectRecordsFromSource($source, array $tables) {
150  $loadDB = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler');
151  $loadDB->setFetchAllFields(TRUE);
152  $loadDB->start($source, implode(',', $tables));
153  foreach ($loadDB->tableArray as $table => $v) {
154  if (isset($GLOBALS['TCA'][$table])) {
155  $loadDB->additionalWhere[$table] = $this->cObj->enableFields($table);
156  }
157  }
158  $this->data = $loadDB->getFromDB();
159  reset($loadDB->itemArray);
160  $this->itemArray = $loadDB->itemArray;
161  }
162 
171  protected function collectRecordsFromCategories($selectedCategories, array $tables, $relationField) {
172  $selectedCategories = array_unique(GeneralUtility::intExplode(',', $selectedCategories, TRUE));
173 
174  // Loop on all selected tables
175  foreach ($tables as $table) {
176 
177  // Get the records for each selected category
178  $tableRecords = array();
179  $categoriesPerRecord = array();
180  foreach ($selectedCategories as $aCategory) {
181  try {
183  $aCategory,
184  TRUE,
185  $table,
186  $relationField
187  );
188  if ($collection->count() > 0) {
189  // Add items to the collection of records for the current table
190  foreach ($collection as $item) {
191  $tableRecords[$item['uid']] = $item;
192  // Keep track of all categories a given item belongs to
193  if (!isset($categoriesPerRecord[$item['uid']])) {
194  $categoriesPerRecord[$item['uid']] = array();
195  }
196  $categoriesPerRecord[$item['uid']][] = $aCategory;
197  }
198  }
199  } catch (\Exception $e) {
200  $message = sprintf(
201  'Could not get records for category id %d. Error: %s (%d)',
202  $aCategory,
203  $e->getMessage(),
204  $e->getCode()
205  );
206  $this->getTimeTracker()->setTSlogMessage($message, 2);
207  }
208  }
209  // Store the resulting records into the itemArray and data results array
210  if (count($tableRecords) > 0) {
211  $this->data[$table] = array();
212  foreach ($tableRecords as $record) {
213  $this->itemArray[] = array(
214  'id' => $record['uid'],
215  'table' => $table
216  );
217  // Add to the record the categories it belongs to
218  $record['_categories'] = implode(',', $categoriesPerRecord[$record['uid']]);
219  $this->data[$table][$record['uid']] = $record;
220  }
221  }
222  }
223  }
224 
230  protected function getTimeTracker() {
231  return $GLOBALS['TT'];
232  }
233 }
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
collectRecordsFromCategories($selectedCategories, array $tables, $relationField)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static load($id, $fillItems=FALSE, $tableName='', $fieldName='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]