TYPO3 API  SVNRelease
class.tslib_content_records.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
00006  *  (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
00007  *  All rights reserved
00008  *
00009  *  This script is part of the TYPO3 project. The TYPO3 project is
00010  *  free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  The GNU General Public License can be found at
00016  *  http://www.gnu.org/copyleft/gpl.html.
00017  *  A copy is found in the textfile GPL.txt and important notices to the license
00018  *  from the author is found in LICENSE.txt distributed with these scripts.
00019  *
00020  *
00021  *  This script is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  This copyright notice MUST APPEAR in all copies of the script!
00027  ***************************************************************/
00028 
00029 /**
00030  * Contains RECORDS class object.
00031  *
00032  * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
00033  * @author Xavier Perseguers <typo3@perseguers.ch>
00034  * @author Steffen Kamper <steffen@typo3.org>
00035  */
00036 class tslib_content_Records extends tslib_content_Abstract {
00037 
00038     /**
00039      * Rendering the cObject, RECORDS
00040      *
00041      * @param   array       Array of TypoScript properties
00042      * @return  string      Output
00043      */
00044     public function render($conf = array()) {
00045         $theValue = '';
00046 
00047         $originalRec = $GLOBALS['TSFE']->currentRecord;
00048         if ($originalRec) { // If the currentRecord is set, we register, that this record has invoked this function. It's should not be allowed to do this again then!!
00049             $GLOBALS['TSFE']->recordRegister[$originalRec]++;
00050         }
00051 
00052         $tables = isset($conf['tables.'])
00053             ? $this->cObj->stdWrap($conf['tables'], $conf['tables.'])
00054             : $conf['tables'];
00055         $source = isset($conf['source.'])
00056             ? $this->cObj->stdWrap($conf['source'], $conf['source.'])
00057             : $conf['source'];
00058         if ($tables && $source) {
00059             $allowedTables = $tables;
00060             if (is_array($conf['conf.'])) {
00061                 foreach ($conf['conf.'] as $k => $v) {
00062                     if (substr($k, -1) != '.')
00063                         $allowedTables .= ',' . $k;
00064                 }
00065             }
00066 
00067             $loadDB = t3lib_div::makeInstance('FE_loadDBGroup');
00068             $loadDB->start($source, $allowedTables);
00069             foreach ($loadDB->tableArray as $table => $v) {
00070                 if (is_array($GLOBALS['TCA'][$table])) {
00071                     $loadDB->additionalWhere[$table] = $this->cObj->enableFields($table);
00072                 }
00073             }
00074             $loadDB->getFromDB();
00075 
00076             reset($loadDB->itemArray);
00077             $data = $loadDB->results;
00078 
00079             $cObj = t3lib_div::makeInstance('tslib_cObj');
00080             $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
00081             $this->cObj->currentRecordNumber = 0;
00082             $this->cObj->currentRecordTotal = count($loadDB->itemArray);
00083             foreach ($loadDB->itemArray as $val) {
00084                 $row = $data[$val['table']][$val['id']];
00085 
00086                     // Versioning preview:
00087                 $GLOBALS['TSFE']->sys_page->versionOL($val['table'], $row);
00088 
00089                     // Language overlay:
00090                 if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
00091                     $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay(
00092                         $val['table'],
00093                         $row,
00094                         $GLOBALS['TSFE']->sys_language_content,
00095                         $GLOBALS['TSFE']->sys_language_contentOL
00096                     );
00097                 }
00098 
00099                 if (is_array($row)) { // Might be unset in the content overlay things...
00100                     $dontCheckPid = isset($conf['dontCheckPid.'])
00101                         ? $this->cObj->stdWrap($conf['dontCheckPid'], $conf['dontCheckPid.'])
00102                         : $conf['dontCheckPid'];
00103                     if (!$dontCheckPid) {
00104                         $row = $this->cObj->checkPid($row['pid'])
00105                             ? $row
00106                             : '';
00107                     }
00108                     if ($row && !$GLOBALS['TSFE']->recordRegister[$val['table'] . ':' . $val['id']]) {
00109                         $renderObjName = $conf['conf.'][$val['table']]
00110                             ? $conf['conf.'][$val['table']]
00111                             : '<' . $val['table'];
00112                         $renderObjKey = $conf['conf.'][$val['table']]
00113                             ? 'conf.' . $val['table']
00114                             : '';
00115                         $renderObjConf = $conf['conf.'][$val['table'] . '.'];
00116                         $this->cObj->currentRecordNumber++;
00117                         $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
00118                         $GLOBALS['TSFE']->currentRecord = $val['table'] . ':' . $val['id'];
00119                         $this->cObj->lastChanged($row['tstamp']);
00120                         $cObj->start($row, $val['table']);
00121                         $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
00122                         $theValue .= $tmpValue;
00123                     }
00124                 }
00125             }
00126         }
00127 
00128         $wrap = isset($conf['wrap.'])
00129             ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.'])
00130             : $conf['wrap'];
00131         if ($wrap) {
00132             $theValue = $this->cObj->wrap($theValue, $wrap);
00133         }
00134 
00135         if (isset($conf['stdWrap.'])) {
00136             $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
00137         }
00138 
00139         $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
00140 
00141         return $theValue;
00142     }
00143 
00144 }
00145 
00146 
00147 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_records.php'])) {
00148     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_records.php']);
00149 }
00150 
00151 ?>