Ejemplo n.º 1
0
 /**
  * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
  * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
  *
  * @param Qom\SourceInterface $source The source (selector od join)
  * @param array $rows
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @param null|int $workspaceUid
  * @return array
  */
 protected function doLanguageAndWorkspaceOverlay(Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = NULL)
 {
     if ($source instanceof Qom\SelectorInterface) {
         $tableName = $source->getSelectorName();
     } elseif ($source instanceof Qom\JoinInterface) {
         $tableName = $source->getRight()->getSelectorName();
     } else {
         // No proper source, so we do not have a table name here
         // we cannot do an overlay and return the original rows instead.
         return $rows;
     }
     $pageRepository = $this->getPageRepository();
     if (is_object($GLOBALS['TSFE'])) {
         if ($workspaceUid !== NULL) {
             $pageRepository->versioningWorkspaceId = $workspaceUid;
         }
     } else {
         if ($workspaceUid === NULL) {
             $workspaceUid = $GLOBALS['BE_USER']->workspace;
         }
         $pageRepository->versioningWorkspaceId = $workspaceUid;
     }
     // Fetches the move-placeholder in case it is supported
     // by the table and if there's only one row in the result set
     // (applying this to all rows does not work, since the sorting
     // order would be destroyed and possible limits not met anymore)
     if (!empty($pageRepository->versioningWorkspaceId) && !empty($GLOBALS['TCA'][$tableName]['ctrl']['versioningWS']) && $GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] >= 2 && count($rows) === 1) {
         $movePlaceholder = $this->databaseHandle->exec_SELECTgetSingleRow($tableName . '.*', $tableName, 't3ver_state=3 AND t3ver_wsid=' . $pageRepository->versioningWorkspaceId . ' AND t3ver_move_id=' . $rows[0]['uid']);
         if (!empty($movePlaceholder)) {
             $rows = array($movePlaceholder);
         }
     }
     $overlaidRows = array();
     foreach ($rows as $row) {
         // If current row is a translation select its parent
         if (isset($tableName) && isset($GLOBALS['TCA'][$tableName]) && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0) {
                 $row = $this->databaseHandle->exec_SELECTgetSingleRow($tableName . '.*', $tableName, $tableName . '.uid=' . (int) $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0');
             }
         }
         $pageRepository->versionOL($tableName, $row, TRUE);
         if ($tableName == 'pages') {
             $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
         } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
                 $overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : '';
                 $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
             }
         }
         if ($row !== NULL && is_array($row)) {
             $overlaidRows[] = $row;
         }
     }
     return $overlaidRows;
 }
Ejemplo n.º 2
0
 /**
  * Builds the language field statement
  *
  * @param string $tableName The database table name
  * @param array &$sql The query parts
  * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @return void
  */
 protected function addSysLanguageStatement($tableName, array &$sql, $querySettings)
 {
     if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
         if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
             // Select all entries for the current language
             $additionalWhereClause = $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . (int) $querySettings->getLanguageUid() . ',-1)';
             // If any language is set -> get those entries which are not translated yet
             // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode
             if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) && $querySettings->getLanguageUid() > 0) {
                 $mode = $querySettings->getLanguageMode();
                 if ($mode === 'strict') {
                     $additionalWhereClause = $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=-1' . ' OR (' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = ' . (int) $querySettings->getLanguageUid() . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '=0' . ') OR (' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . ' AND ' . $tableName . '.uid IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . ' FROM ' . $tableName . ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=' . (int) $querySettings->getLanguageUid();
                 } else {
                     $additionalWhereClause .= ' OR (' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . ' AND ' . $tableName . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . ' FROM ' . $tableName . ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0';
                 }
                 // Add delete clause to ensure all entries are loaded
                 if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) {
                     $additionalWhereClause .= ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0';
                 }
                 $additionalWhereClause .= '))';
             }
             $sql['additionalWhereClause'][] = '(' . $additionalWhereClause . ')';
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
  * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
  *
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source The source (selector od join)
  * @param array $rows
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @param null|integer $workspaceUid
  * @return array
  */
 protected function doLanguageAndWorkspaceOverlay(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = NULL)
 {
     if ($source instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
         $tableName = $source->getSelectorName();
     } elseif ($source instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\JoinInterface) {
         $tableName = $source->getRight()->getSelectorName();
     } else {
         // No proper source, so we do not have a table name here
         // we cannot do an overlay and return the original rows instead.
         return $rows;
     }
     $pageRepository = $this->getPageRepository();
     if (is_object($GLOBALS['TSFE'])) {
         if ($workspaceUid !== NULL) {
             $pageRepository->versioningWorkspaceId = $workspaceUid;
         }
     } else {
         if ($workspaceUid === NULL) {
             $workspaceUid = $GLOBALS['BE_USER']->workspace;
         }
         $pageRepository->versioningWorkspaceId = $workspaceUid;
     }
     $overlaidRows = array();
     foreach ($rows as $row) {
         // If current row is a translation select its parent
         if (isset($tableName) && isset($GLOBALS['TCA'][$tableName]) && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0) {
                 $row = $this->databaseHandle->exec_SELECTgetSingleRow($tableName . '.*', $tableName, $tableName . '.uid=' . (int) $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0');
             }
         }
         $pageRepository->versionOL($tableName, $row, TRUE);
         if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
             $row['uid'] = $row['_ORIG_uid'];
         }
         if ($tableName == 'pages') {
             $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
         } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
                 $overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : '';
                 $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
             }
         }
         if ($row !== NULL && is_array($row)) {
             $overlaidRows[] = $row;
         }
     }
     return $overlaidRows;
 }
Ejemplo n.º 4
0
 /**
  * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
  * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
  *
  * @param Qom\SourceInterface $source The source (selector od join)
  * @param array $rows
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @param null|int $workspaceUid
  * @return array
  */
 protected function doLanguageAndWorkspaceOverlay(Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = null)
 {
     if ($source instanceof Qom\SelectorInterface) {
         $tableName = $source->getSelectorName();
     } elseif ($source instanceof Qom\JoinInterface) {
         $tableName = $source->getRight()->getSelectorName();
     } else {
         // No proper source, so we do not have a table name here
         // we cannot do an overlay and return the original rows instead.
         return $rows;
     }
     $pageRepository = $this->getPageRepository();
     if (is_object($GLOBALS['TSFE'])) {
         if ($workspaceUid !== null) {
             $pageRepository->versioningWorkspaceId = $workspaceUid;
         }
     } else {
         if ($workspaceUid === null) {
             $workspaceUid = $GLOBALS['BE_USER']->workspace;
         }
         $pageRepository->versioningWorkspaceId = $workspaceUid;
     }
     // Fetches the move-placeholder in case it is supported
     // by the table and if there's only one row in the result set
     // (applying this to all rows does not work, since the sorting
     // order would be destroyed and possible limits not met anymore)
     if (!empty($pageRepository->versioningWorkspaceId) && BackendUtility::isTableWorkspaceEnabled($tableName) && count($rows) === 1) {
         $versionId = $pageRepository->versioningWorkspaceId;
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
         $queryBuilder->getRestrictions()->removeAll();
         $movePlaceholder = $queryBuilder->select($tableName . '.*')->from($tableName)->where($queryBuilder->expr()->eq('t3ver_state', $queryBuilder->createNamedParameter(3, \PDO::PARAM_INT)), $queryBuilder->expr()->eq('t3ver_wsid', $queryBuilder->createNamedParameter($versionId, \PDO::PARAM_INT)), $queryBuilder->expr()->eq('t3ver_move_id', $queryBuilder->createNamedParameter($rows[0]['uid'], \PDO::PARAM_INT)))->setMaxResults(1)->execute()->fetch();
         if (!empty($movePlaceholder)) {
             $rows = [$movePlaceholder];
         }
     }
     $overlaidRows = [];
     foreach ($rows as $row) {
         // If current row is a translation select its parent
         if (isset($tableName) && isset($GLOBALS['TCA'][$tableName]) && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) && $tableName !== 'pages_language_overlay') {
             if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0) {
                 $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
                 $queryBuilder->getRestrictions()->removeAll();
                 $row = $queryBuilder->select($tableName . '.*')->from($tableName)->where($queryBuilder->expr()->eq($tableName . '.uid', $queryBuilder->createNamedParameter($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']], \PDO::PARAM_INT)), $queryBuilder->expr()->eq($tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'], $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)))->setMaxResults(1)->execute()->fetch();
             }
         }
         $pageRepository->versionOL($tableName, $row, true);
         if ($tableName == 'pages') {
             $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
         } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' && $tableName !== 'pages_language_overlay') {
             if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], [-1, 0])) {
                 $overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : '';
                 $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
             }
         }
         if ($row !== null && is_array($row)) {
             $overlaidRows[] = $row;
         }
     }
     return $overlaidRows;
 }
Ejemplo n.º 5
0
 /**
  * Builds the language field statement
  *
  * @param string $tableName The database table name
  * @param string $tableAlias The table alias used in the query.
  * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @return string
  */
 protected function getSysLanguageStatement($tableName, $tableAlias, $querySettings)
 {
     if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
         if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) {
             // Select all entries for the current language
             // If any language is set -> get those entries which are not translated yet
             // They will be removed by \TYPO3\CMS\Frontend\Page\PageRepository::getRecordOverlay if not matching overlay mode
             $languageField = $GLOBALS['TCA'][$tableName]['ctrl']['languageField'];
             if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) && $querySettings->getLanguageUid() > 0) {
                 $mode = $querySettings->getLanguageMode();
                 if ($mode === 'strict') {
                     $queryBuilderForSubselect = $this->queryBuilder->getConnection()->createQueryBuilder();
                     $queryBuilderForSubselect->select($tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])->from($tableName)->where($queryBuilderForSubselect->expr()->andX($queryBuilderForSubselect->expr()->gt($tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'], 0), $queryBuilderForSubselect->expr()->eq($tableName . '.' . $languageField, (int) $querySettings->getLanguageUid())));
                     return $this->queryBuilder->expr()->orX($this->queryBuilder->expr()->eq($tableAlias . '.' . $languageField, -1), $this->queryBuilder->expr()->andX($this->queryBuilder->expr()->eq($tableAlias . '.' . $languageField, (int) $querySettings->getLanguageUid()), $this->queryBuilder->expr()->eq($tableAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'], 0)), $this->queryBuilder->expr()->andX($this->queryBuilder->expr()->eq($tableAlias . '.' . $languageField, 0), $this->queryBuilder->expr()->in($tableAlias . '.uid', $queryBuilderForSubselect->getSQL())));
                 } else {
                     $queryBuilderForSubselect = $this->queryBuilder->getConnection()->createQueryBuilder();
                     $queryBuilderForSubselect->select($tableAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])->from($tableName)->where($queryBuilderForSubselect->expr()->andX($queryBuilderForSubselect->expr()->gt($tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'], 0), $queryBuilderForSubselect->expr()->eq($tableName . '.' . $languageField, (int) $querySettings->getLanguageUid())));
                     return $this->queryBuilder->expr()->orX($this->queryBuilder->expr()->in($tableAlias . '.' . $languageField, [(int) $querySettings->getLanguageUid(), -1]), $this->queryBuilder->expr()->andX($this->queryBuilder->expr()->eq($tableAlias . '.' . $languageField, 0), $this->queryBuilder->expr()->notIn($tableAlias . '.uid', $queryBuilderForSubselect->getSQL())));
                 }
             } else {
                 return $this->queryBuilder->expr()->in($tableAlias . '.' . $languageField, [(int) $querySettings->getLanguageUid(), -1]);
             }
         }
     }
     return '';
 }