[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Typo3QuerySettings.php
index 5a94e3b..48c95e1 100644 (file)
@@ -1,43 +1,32 @@
 <?php
 namespace TYPO3\CMS\Extbase\Persistence\Generic;
 
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
- *  All rights reserved
- *
- *  This class is a backport of the corresponding class of FLOW3.
- *  All credits go to the v5 team.
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+/**
+ * This file is part of the TYPO3 CMS project.
  *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
  *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Query settings. This class is NOT part of the FLOW3 API.
- * It reflects the settings unique to TYPO3 4.x.
+ * It reflects the settings unique to TYPO3 CMS.
  *
  * @api
  */
-class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface {
+class Typo3QuerySettings implements QuerySettingsInterface {
 
        /**
         * Flag if the storage page should be respected for the query.
         *
-        * @var boolean
+        * @var bool
         */
        protected $respectStoragePage = TRUE;
 
@@ -53,7 +42,7 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
         * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
         *
-        * @var boolean
+        * @var bool
         */
        protected $ignoreEnableFields = FALSE;
 
@@ -68,58 +57,94 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        /**
         * Flag whether deleted records should be included in the result set.
         *
-        * @var boolean
+        * @var bool
         */
        protected $includeDeleted = FALSE;
 
        /**
         * Flag if the sys_language_uid should be respected (default is TRUE).
         *
-        * @var boolean
+        * @var bool
         */
        protected $respectSysLanguage = TRUE;
 
        /**
-        * The language uid for the language overlay.
+        * Representing sys_language_overlay only valid for current context
         *
-        * @var integer
+        * @var mixed
         */
-       protected $sysLanguageUid = 0;
+       protected $languageOverlayMode = TRUE;
+
+       /**
+        * Representing sys_language_mode only valid for current context
+        *
+        * @var string
+        */
+       protected $languageMode = NULL;
+
+       /**
+        * Represensting sys_language_uid only valid for current context
+        *
+        * @var int
+        */
+       protected $languageUid = 0;
 
        /**
         * Flag if the the query result should be returned as raw QueryResult.
         *
-        * @var boolean
+        * @var bool
+        * @deprecated since Extbase 6.2, will be removed two versions later
         */
        protected $returnRawQueryResult = FALSE;
 
        /**
+        * Flag whether the query should use a prepared statement
+        *
+        * @var bool
+        */
+       protected $usePreparedStatement = FALSE;
+
+       /**
+        * Flag whether the query should be cached using the caching framework
+        *
+        * @var bool
+        */
+       protected $useQueryCache = TRUE;
+
+       /**
         * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
         * initializeObject is responsible for handling that.
         */
        public function initializeObject() {
                /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
-               $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
                /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */
                $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
                if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
                        $this->setIgnoreEnableFields(TRUE);
                }
 
+               // TYPO3 CMS language defaults
+               $this->setLanguageUid(0);
+               $this->setLanguageMode(NULL);
+               $this->setLanguageOverlayMode(FALSE);
+
                // Set correct language uid for frontend handling
                if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
-                       $this->setSysLanguageUid($GLOBALS['TSFE']->sys_language_content);
-               } elseif (intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('L'))) {
+                       $this->setLanguageUid((int)$GLOBALS['TSFE']->sys_language_content);
+                       $this->setLanguageOverlayMode($GLOBALS['TSFE']->sys_language_contentOL ?: FALSE);
+                       $this->setLanguageMode($GLOBALS['TSFE']->sys_language_mode ?: NULL);
+               } elseif ((int)GeneralUtility::_GP('L')) {
                        // Set language from 'L' parameter
-                       $this->setSysLanguageUid(intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('L')));
+                       $this->setLanguageUid((int)GeneralUtility::_GP('L'));
                }
        }
 
        /**
         * Sets the flag if the storage page should be respected for the query.
         *
-        * @param boolean $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
+        * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
+        * @return QuerySettingsInterface
         * @api
         */
        public function setRespectStoragePage($respectStoragePage) {
@@ -130,7 +155,7 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        /**
         * Returns the state, if the storage page should be respected for the query.
         *
-        * @return boolean TRUE, if the storage page should be respected; otherwise FALSE.
+        * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
         */
        public function getRespectStoragePage() {
                return $this->respectStoragePage;
@@ -139,12 +164,13 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        /**
         * Sets the pid(s) of the storage page(s) that should be respected for the query.
         *
-        * @param array $storagePageIds If TRUE the storage page ID will be determined and the statement will be extended accordingly.
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
+        * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
+        * @return QuerySettingsInterface
         * @api
         */
        public function setStoragePageIds(array $storagePageIds) {
                $this->storagePageIds = $storagePageIds;
+               return $this;
        }
 
        /**
@@ -157,10 +183,8 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        }
 
        /**
-        * Sets the flag if a  and language overlay should be performed.
-        *
-        * @param boolean $respectSysLanguage TRUE if a  and language overlay should be performed.
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
+        * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
+        * @return QuerySettingsInterface
         * @api
         */
        public function setRespectSysLanguage($respectSysLanguage) {
@@ -169,62 +193,84 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        }
 
        /**
-        * Returns the state, if a  and language overlay should be performed.
-        *
-        * @return boolean TRUE, if a  and language overlay should be performed; otherwise FALSE.
+        * @return bool TRUE if TYPO3 language settings are to be applied
         */
        public function getRespectSysLanguage() {
                return $this->respectSysLanguage;
        }
 
        /**
-        * Sets the language uid for the language overlay.
-        *
-        * @param integer $sysLanguageUid language uid for the language overlay
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
+        * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
+        * @return QuerySettingsInterface instance of $this to allow method chaining
         * @api
         */
-       public function setSysLanguageUid($sysLanguageUid) {
-               $this->sysLanguageUid = $sysLanguageUid;
+       public function setLanguageOverlayMode($languageOverlayMode = FALSE) {
+               $this->languageOverlayMode = $languageOverlayMode;
+               return $this;
        }
 
        /**
-        * Returns the language uid for the language overlay
-        *
-        * @return integer language uid for the language overlay
+        * @return mixed TRUE, FALSE or "hideNonTranslated"
         */
-       public function getSysLanguageUid() {
-               return $this->sysLanguageUid;
+       public function getLanguageOverlayMode() {
+               return $this->languageOverlayMode;
        }
 
        /**
-        * Sets the flag if the visibility in the frontend should be respected.
-        *
-        * @param boolean $respectEnableFields TRUE if the visibility in the frontend should be respected. If TRUE, the "enable fields" of TYPO3 will be added to the query statement.
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
-        * @deprecated since Extbase 6.0, will be removed in Extbase 6.2. Use setIgnoreEnableFields() and setEnableFieldsToBeIgnored() instead.
-        * @see setIgnoreEnableFields()
-        * @see setEnableFieldsToBeIgnored()
+        * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
+        * @return QuerySettingsInterface instance of $this to allow method chaining
+        * @api
+        */
+       public function setLanguageMode($languageMode = '') {
+               $this->languageMode = $languageMode;
+               return $this;
+       }
+
+       /**
+        * @return string NULL, "content_fallback", "strict" or "ignore"
+        */
+       public function getLanguageMode() {
+               return $this->languageMode;
+       }
+
+       /**
+        * @param int $languageUid
+        * @return QuerySettingsInterface instance of $this to allow method chaining
         * @api
         */
-       public function setRespectEnableFields($respectEnableFields) {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
-               $this->setIgnoreEnableFields(!$respectEnableFields);
-               $this->setIncludeDeleted(!$respectEnableFields);
+       public function setLanguageUid($languageUid) {
+               $this->languageUid = $languageUid;
                return $this;
        }
 
        /**
-        * Returns the state, if the visibility settings for the frontend should be respected for the query.
+        * @return int
+        */
+       public function getLanguageUid() {
+               return $this->languageUid;
+       }
+
+       /**
+        * Sets the language uid for the language overlay.
         *
-        * @return boolean TRUE, if the visibility settings for the frontend should should be respected; otherwise FALSE.
-        * @deprecated since Extbase 6.0, will be removed in Extbase 6.2. Use getIgnoreEnableFields() and getEnableFieldsToBeIgnored() instead.
-        * @see getIgnoreEnableFields()
-        * @see getEnableFieldsToBeIgnored()
+        * @param int $sysLanguageUid language uid for the language overlay
+        * @return QuerySettingsInterface instance of $this to allow method chaining
+        * @deprecated since Extbase 6.2, will be removed two versions later. Use setLanguageUid() instead.
+        */
+       public function setSysLanguageUid($sysLanguageUid) {
+               GeneralUtility::logDeprecatedFunction();
+               return $this->setLanguageUid($sysLanguageUid);
+       }
+
+       /**
+        * Returns the language uid for the language overlay
+        *
+        * @return int language uid for the language overlay
+        * @deprecated since Extbase 6.2, will be removed two versions later. Use getLanguageUid() instead.
         */
-       public function getRespectEnableFields() {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
-               return !($this->getIgnoreEnableFields() && $this->getIncludeDeleted());
+       public function getSysLanguageUid() {
+               GeneralUtility::logDeprecatedFunction();
+               return $this->getLanguageUid();
        }
 
        /**
@@ -232,12 +278,14 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
         * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
         *
-        * @param boolean $ignoreEnableFields
+        * @param bool $ignoreEnableFields
+        * @return QuerySettingsInterface
         * @see setEnableFieldsToBeIgnored()
         * @api
         */
        public function setIgnoreEnableFields($ignoreEnableFields) {
                $this->ignoreEnableFields = $ignoreEnableFields;
+               return $this;
        }
 
        /**
@@ -246,7 +294,7 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
         * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
         *
-        * @return boolean
+        * @return bool
         * @see getEnableFieldsToBeIgnored()
         */
        public function getIgnoreEnableFields() {
@@ -259,12 +307,13 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
         *
         * @param array $enableFieldsToBeIgnored
-        * @return void
+        * @return QuerySettingsInterface
         * @see setIgnoreEnableFields()
         * @api
         */
        public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored) {
                $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
+               return $this;
        }
 
        /**
@@ -281,18 +330,19 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        /**
         * Sets the flag if the query should return objects that are deleted.
         *
-        * @param boolean $includeDeleted
-        * @return void
+        * @param bool $includeDeleted
+        * @return QuerySettingsInterface
         * @api
         */
        public function setIncludeDeleted($includeDeleted) {
                $this->includeDeleted = $includeDeleted;
+               return $this;
        }
 
        /**
         * Returns if the query should return objects that are deleted.
         *
-        * @return boolean
+        * @return bool
         */
        public function getIncludeDeleted() {
                return $this->includeDeleted;
@@ -301,23 +351,56 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        /**
         * Sets the state, if the QueryResult should be returned unmapped.
         *
-        * @param boolean $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
-        * @return void
+        * @param bool $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
+        * @return QuerySettingsInterface
+        * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
         */
        public function setReturnRawQueryResult($returnRawQueryResult) {
+               GeneralUtility::logDeprecatedFunction();
                $this->returnRawQueryResult = $returnRawQueryResult;
+               return $this;
        }
 
        /**
         * Returns the state, if the QueryResult should be returned unmapped.
         *
-        * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
+        * @return bool TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
+        * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
         */
        public function getReturnRawQueryResult() {
+               // We do not log this call intentionally, otherwise the deprecation log would be filled up
                return $this->returnRawQueryResult;
        }
 
-}
+       /**
+        * @param bool $usePreparedStatement
+        * @return QuerySettingsInterface
+        */
+       public function usePreparedStatement($usePreparedStatement) {
+               $this->usePreparedStatement = $usePreparedStatement;
+               return $this;
+       }
+
+       /**
+        * @return bool
+        */
+       public function getUsePreparedStatement() {
+               return (bool)$this->usePreparedStatement;
+       }
 
+       /**
+        * @param bool $useQueryCache
+        * @return QuerySettingsInterface
+        */
+       public function useQueryCache($useQueryCache) {
+               $this->useQueryCache = (bool)$useQueryCache;
+               return $this;
+       }
 
-?>
\ No newline at end of file
+       /**
+        * @return bool
+        */
+       public function getUseQueryCache() {
+               return $this->useQueryCache;
+       }
+}