[TASK] Introduce Enum constants for t3ver_state
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / RecordsContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Xavier Perseguers <typo3@perseguers.ch>
8 * (c) 2010-2013 Steffen Kamper <steffen@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Contains RECORDS class object.
32 *
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 * @author Steffen Kamper <steffen@typo3.org>
35 */
36 class RecordsContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
37
38 /**
39 * Rendering the cObject, RECORDS
40 *
41 * @param array $conf Array of TypoScript properties
42 * @return string Output
43 */
44 public function render($conf = array()) {
45 $theValue = '';
46 $originalRec = $GLOBALS['TSFE']->currentRecord;
47 // If the currentRecord is set, we register, that this record has invoked this function.
48 // It's should not be allowed to do this again then!!
49 if ($originalRec) {
50 $GLOBALS['TSFE']->recordRegister[$originalRec]++;
51 }
52 $tables = isset($conf['tables.']) ? $this->cObj->stdWrap($conf['tables'], $conf['tables.']) : $conf['tables'];
53 $source = isset($conf['source.']) ? $this->cObj->stdWrap($conf['source'], $conf['source.']) : $conf['source'];
54 if ($tables && $source) {
55 $allowedTables = $tables;
56 if (is_array($conf['conf.'])) {
57 foreach ($conf['conf.'] as $k => $v) {
58 if (substr($k, -1) != '.') {
59 $allowedTables .= ',' . $k;
60 }
61 }
62 }
63 /** @var \TYPO3\CMS\Core\Database\RelationHandler $loadDB*/
64 $loadDB = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler');
65 $loadDB->setFetchAllFields(TRUE);
66 $loadDB->start($source, $allowedTables);
67 foreach ($loadDB->tableArray as $table => $v) {
68 if (is_array($GLOBALS['TCA'][$table])) {
69 $loadDB->additionalWhere[$table] = $this->cObj->enableFields($table);
70 }
71 }
72 $loadDB->getFromDB();
73 reset($loadDB->itemArray);
74 $data = $loadDB->results;
75 $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
76 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
77 $this->cObj->currentRecordNumber = 0;
78 $this->cObj->currentRecordTotal = count($loadDB->itemArray);
79 foreach ($loadDB->itemArray as $val) {
80 $row = $data[$val['table']][$val['id']];
81 // Versioning preview:
82 $GLOBALS['TSFE']->sys_page->versionOL($val['table'], $row);
83 // Language overlay:
84 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
85 if ($val['table'] === 'pages') {
86 $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
87 } else {
88 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($val['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
89 }
90 }
91 // Might be unset in the content overlay things...
92 if (is_array($row)) {
93 $dontCheckPid = isset($conf['dontCheckPid.']) ? $this->cObj->stdWrap($conf['dontCheckPid'], $conf['dontCheckPid.']) : $conf['dontCheckPid'];
94 if (!$dontCheckPid) {
95 $row = $this->cObj->checkPid($row['pid']) ? $row : '';
96 }
97 if ($row && !$GLOBALS['TSFE']->recordRegister[($val['table'] . ':' . $val['id'])]) {
98 $renderObjName = $conf['conf.'][$val['table']] ? $conf['conf.'][$val['table']] : '<' . $val['table'];
99 $renderObjKey = $conf['conf.'][$val['table']] ? 'conf.' . $val['table'] : '';
100 $renderObjConf = $conf['conf.'][$val['table'] . '.'];
101 $this->cObj->currentRecordNumber++;
102 $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
103 $GLOBALS['TSFE']->currentRecord = $val['table'] . ':' . $val['id'];
104 $this->cObj->lastChanged($row['tstamp']);
105 $cObj->start($row, $val['table']);
106 $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
107 $theValue .= $tmpValue;
108 }
109 }
110 }
111 }
112 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
113 if ($wrap) {
114 $theValue = $this->cObj->wrap($theValue, $wrap);
115 }
116 if (isset($conf['stdWrap.'])) {
117 $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
118 }
119 // Restore
120 $GLOBALS['TSFE']->currentRecord = $originalRec;
121 return $theValue;
122 }
123
124 }