/**
  * @test
  * @dataProvider conteRowsOfDifferentTypesDataProvider
  */
 public function migrationOfLegacyFieldsIsOnlyDoneWhenRelationFieldIsVisibleInType($dbRow, $expectedCaption, $fileProperties)
 {
     $fileReference = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileReference', array(), array(), '', FALSE);
     $fileReference->expects($this->once())->method('getProperties')->will($this->returnValue($fileProperties));
     $fileReference->expects($this->any())->method('getOriginalFile')->will($this->returnValue($this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE)));
     $fileReference->expects($this->any())->method('getPublicUrl')->will($this->returnValue('path/to/file'));
     $this->pageRepositoryMock->expects($this->any())->method('getFileReferences')->will($this->returnValue(array($fileReference)));
     \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($dbRow, 'tt_content');
     $this->assertSame($expectedCaption, $dbRow['imagecaption']);
 }
 /**
  * Class constructor.
  * Well, it has to be called manually since it is not a real constructor function.
  * So after making an instance of the class, call this function and pass to it a database record and the tablename from where the record is from. That will then become the "current" record loaded into memory and accessed by the .fields property found in eg. stdWrap.
  *
  * @param array $data The record data that is rendered.
  * @param string $table The table that the data record is from.
  * @return void
  * @todo Define visibility
  */
 public function start($data, $table = '')
 {
     global $TYPO3_CONF_VARS;
     if ($TYPO3_CONF_VARS['FE']['activateContentAdapter'] && is_array($data) && !empty($data) && !empty($table)) {
         \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($data, $table);
     }
     $this->data = $data;
     $this->table = $table;
     $this->currentRecord = $table ? $table . ':' . $this->data['uid'] : '';
     $this->parameters = array();
     if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'])) {
         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'] as $classArr) {
             $this->cObjHookObjectsRegistry[$classArr[0]] = $classArr[1];
         }
     }
     $this->stdWrapHookObjects = array();
     if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'])) {
         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'] as $classData) {
             $hookObject = GeneralUtility::getUserObj($classData);
             if (!$hookObject instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectStdWrapHookInterface) {
                 throw new \UnexpectedValueException($classData . ' must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectStdWrapHookInterface', 1195043965);
             }
             $this->stdWrapHookObjects[] = $hookObject;
         }
     }
     if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['postInit'])) {
         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['postInit'] as $classData) {
             $postInitializationProcessor = GeneralUtility::getUserObj($classData);
             if (!$postInitializationProcessor instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectPostInitHookInterface) {
                 throw new \UnexpectedValueException($classData . ' must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectPostInitHookInterface', 1274563549);
             }
             $postInitializationProcessor->postProcessContentObjectInitialization($this);
         }
     }
 }
Beispiel #3
0
    /**
     * fetches all available children for a certain grid container
     *
     * @param   int  $element    : The uid of the grid container
     * @param string $csvColumns : A list of available column IDs
     *
     * @return  array   $children: The child elements of this grid container
     */
    public function getChildren($element = 0, $csvColumns = '')
    {
        if ($element && $csvColumns !== '') {
            $where = '(tx_gridelements_container = ' . $element . $this->cObj->enableFields('tt_content') . ' AND colPos != -2
				AND pid > 0
				AND tx_gridelements_columns IN (' . $csvColumns . ')
				AND sys_language_uid IN (-1,0)
			)';
            if ($GLOBALS['TSFE']->sys_language_uid > 0) {
                if ($GLOBALS['TSFE']->sys_language_contentOL) {
                    if (isset($this->cObj->data['_LOCALIZED_UID']) && $this->cObj->data['_LOCALIZED_UID'] !== 0) {
                        $element = (int) $this->cObj->data['_LOCALIZED_UID'];
                    }
                    if ($element) {
                        $where .= '  OR (
						tx_gridelements_container = ' . $element . $this->cObj->enableFields('tt_content') . ' AND sys_language_uid IN (-1,' . $GLOBALS['TSFE']->sys_language_uid . ')
							AND l18n_parent = 0
					)';
                    }
                } else {
                    if ($element) {
                        $where .= '  OR (
						tx_gridelements_container = ' . $element . $this->cObj->enableFields('tt_content') . ' AND sys_language_uid IN (-1,' . $GLOBALS['TSFE']->sys_language_uid . ')
					)';
                    }
                }
            }
            $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_content', $where, '', 'sorting ASC');
            if (!$GLOBALS['TYPO3_DB']->sql_error()) {
                $this->cObj->data['tx_gridelements_view_children'] = array();
                while ($child = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                    // Versioning preview:
                    $sorting = $child['sorting'];
                    $GLOBALS['TSFE']->sys_page->versionOL('tt_content', $child, TRUE);
                    // Language overlay:
                    if (is_array($child)) {
                        $child['sorting'] = $sorting;
                        if ($GLOBALS['TSFE']->sys_language_contentOL) {
                            $child = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tt_content', $child, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
                        }
                        if ($child !== FALSE) {
                            if ($GLOBALS['TYPO3_CONF_VARS']['FE']['activateContentAdapter']) {
                                FrontendContentAdapterService::modifyDBRow($child, 'tt_content');
                            }
                            $this->cObj->data['tx_gridelements_view_children'][] = $child;
                            unset($child);
                        }
                    }
                }
                $compareFunction = function ($child_a, $child_b) {
                    if ($child_a['sorting'] > $child_b['sorting']) {
                        return 1;
                    } elseif ($child_a['sorting'] === $child_b['sorting']) {
                        return 0;
                    } else {
                        return -1;
                    }
                };
                usort($this->cObj->data['tx_gridelements_view_children'], $compareFunction);
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
            }
        }
    }
 /**
  * Rendering the cObject, CONTENT
  *
  * @param array $conf Array of TypoScript properties
  * @return string Output
  */
 public function render($conf = array())
 {
     $theValue = '';
     $originalRec = $GLOBALS['TSFE']->currentRecord;
     // 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!!
     if ($originalRec) {
         $GLOBALS['TSFE']->recordRegister[$originalRec]++;
     }
     $conf['table'] = isset($conf['table.']) ? trim($this->cObj->stdWrap($conf['table'], $conf['table.'])) : trim($conf['table']);
     $tablePrefix = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('_', $conf['table'], TRUE);
     if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('pages,tt,fe,tx,ttx,user,static', $tablePrefix[0])) {
         $renderObjName = $conf['renderObj'] ? $conf['renderObj'] : '<' . $conf['table'];
         $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
         $renderObjConf = $conf['renderObj.'];
         $slide = isset($conf['slide.']) ? intval($this->cObj->stdWrap($conf['slide'], $conf['slide.'])) : intval($conf['slide']);
         if (!$slide) {
             $slide = 0;
         }
         $slideCollect = isset($conf['slide.']['collect.']) ? intval($this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.'])) : intval($conf['slide.']['collect']);
         if (!$slideCollect) {
             $slideCollect = 0;
         }
         $slideCollectReverse = isset($conf['slide.']['collectReverse.']) ? intval($this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.'])) : intval($conf['slide.']['collectReverse']);
         $slideCollectReverse = $slideCollectReverse ? TRUE : FALSE;
         $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.']) ? intval($this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.'])) : intval($conf['slide.']['collectFuzzy']);
         if ($slideCollectFuzzy) {
             $slideCollectFuzzy = TRUE;
         } else {
             $slideCollectFuzzy = FALSE;
         }
         if (!$slideCollect) {
             $slideCollectFuzzy = TRUE;
         }
         $again = FALSE;
         do {
             $res = $this->cObj->exec_getQuery($conf['table'], $conf['select.']);
             if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
                 $GLOBALS['TT']->setTSlogMessage($error, 3);
             } else {
                 $this->cObj->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
                 $GLOBALS['TT']->setTSlogMessage('NUMROWS: ' . $GLOBALS['TYPO3_DB']->sql_num_rows($res));
                 /** @var $cObj \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
                 $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
                 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
                 $this->cObj->currentRecordNumber = 0;
                 $cobjValue = '';
                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                     // Versioning preview:
                     $GLOBALS['TSFE']->sys_page->versionOL($conf['table'], $row, TRUE);
                     // Language overlay:
                     if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
                         if ($conf['table'] == 'pages') {
                             $row = $GLOBALS['TSFE']->sys_page->getPageOverlay($row);
                         } else {
                             $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'], $row, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
                         }
                     }
                     // Might be unset in the sys_language_contentOL
                     if (is_array($row)) {
                         // Call hook for possible manipulation of database row for cObj->data
                         if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'])) {
                             foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] as $_classRef) {
                                 $_procObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
                                 $_procObj->modifyDBRow($row, $conf['table']);
                             }
                         }
                         \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($row, $conf['table']);
                         if (!$GLOBALS['TSFE']->recordRegister[$conf['table'] . ':' . $row['uid']]) {
                             $this->cObj->currentRecordNumber++;
                             $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
                             $GLOBALS['TSFE']->currentRecord = $conf['table'] . ':' . $row['uid'];
                             $this->cObj->lastChanged($row['tstamp']);
                             $cObj->start($row, $conf['table']);
                             $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
                             $cobjValue .= $tmpValue;
                         }
                     }
                 }
                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
             }
             if ($slideCollectReverse) {
                 $theValue = $cobjValue . $theValue;
             } else {
                 $theValue .= $cobjValue;
             }
             if ($slideCollect > 0) {
                 $slideCollect--;
             }
             if ($slide) {
                 if ($slide > 0) {
                     $slide--;
                 }
                 $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
                 if (isset($conf['select.']['pidInList.'])) {
                     unset($conf['select.']['pidInList.']);
                 }
                 $again = strlen($conf['select.']['pidInList']) ? TRUE : FALSE;
             }
         } while ($again && ($slide && !strlen($tmpValue) && $slideCollectFuzzy || $slide && $slideCollect));
     }
     $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
     if ($wrap) {
         $theValue = $this->cObj->wrap($theValue, $wrap);
     }
     if (isset($conf['stdWrap.'])) {
         $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
     }
     // Restore
     $GLOBALS['TSFE']->currentRecord = $originalRec;
     return $theValue;
 }