[TASK] Correct QuerySettingsInterface RespectSysLanguage comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Typo3QuerySettings.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
19 use TYPO3\CMS\Extbase\Object\ObjectManager;
20
21 /**
22 * Query settings. This class is NOT part of the TYPO3.Flow API.
23 * It reflects the settings unique to TYPO3 CMS.
24 *
25 * @api
26 */
27 class Typo3QuerySettings implements QuerySettingsInterface
28 {
29 /**
30 * Flag if the storage page should be respected for the query.
31 *
32 * @var bool
33 */
34 protected $respectStoragePage = true;
35
36 /**
37 * the pid(s) of the storage page(s) that should be respected for the query.
38 *
39 * @var array
40 */
41 protected $storagePageIds = [];
42
43 /**
44 * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
45 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
46 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
47 *
48 * @var bool
49 */
50 protected $ignoreEnableFields = false;
51
52 /**
53 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
54 * to be ignored while building the query statement
55 *
56 * @var array
57 */
58 protected $enableFieldsToBeIgnored = [];
59
60 /**
61 * Flag whether deleted records should be included in the result set.
62 *
63 * @var bool
64 */
65 protected $includeDeleted = false;
66
67 /**
68 * Flag if the sys_language_uid should be respected (default is TRUE).
69 *
70 * @var bool
71 */
72 protected $respectSysLanguage = true;
73
74 /**
75 * Representing sys_language_overlay only valid for current context
76 *
77 * @var mixed
78 */
79 protected $languageOverlayMode = true;
80
81 /**
82 * Representing sys_language_mode only valid for current context
83 *
84 * @var string
85 */
86 protected $languageMode = null;
87
88 /**
89 * Representing sys_language_uid only valid for current context
90 *
91 * @var int
92 */
93 protected $languageUid = 0;
94
95 /**
96 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
97 * initializeObject is responsible for handling that.
98 */
99 public function initializeObject()
100 {
101 /** @var $objectManager ObjectManager */
102 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
103 /** @var $configurationManager ConfigurationManagerInterface */
104 $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
105 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
106 $this->setIgnoreEnableFields(true);
107 }
108
109 // TYPO3 CMS language defaults
110 $this->setLanguageUid(0);
111 $this->setLanguageMode(null);
112 $this->setLanguageOverlayMode(false);
113
114 // Set correct language uid for frontend handling
115 if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
116 $this->setLanguageUid((int)$GLOBALS['TSFE']->sys_language_content);
117 $this->setLanguageOverlayMode($GLOBALS['TSFE']->sys_language_contentOL ?: false);
118 $this->setLanguageMode($GLOBALS['TSFE']->sys_language_mode ?: null);
119 } elseif ((int)GeneralUtility::_GP('L')) {
120 // Set language from 'L' parameter
121 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
122 }
123 }
124
125 /**
126 * Sets the flag if the storage page should be respected for the query.
127 *
128 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
129 * @return QuerySettingsInterface
130 * @api
131 */
132 public function setRespectStoragePage($respectStoragePage)
133 {
134 $this->respectStoragePage = $respectStoragePage;
135 return $this;
136 }
137
138 /**
139 * Returns the state, if the storage page should be respected for the query.
140 *
141 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
142 */
143 public function getRespectStoragePage()
144 {
145 return $this->respectStoragePage;
146 }
147
148 /**
149 * Sets the pid(s) of the storage page(s) that should be respected for the query.
150 *
151 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
152 * @return QuerySettingsInterface
153 * @api
154 */
155 public function setStoragePageIds(array $storagePageIds)
156 {
157 $this->storagePageIds = $storagePageIds;
158 return $this;
159 }
160
161 /**
162 * Returns the pid(s) of the storage page(s) that should be respected for the query.
163 *
164 * @return array list of integers that each represent a storage page id
165 */
166 public function getStoragePageIds()
167 {
168 return $this->storagePageIds;
169 }
170
171 /**
172 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
173 * @return QuerySettingsInterface
174 * @api
175 */
176 public function setRespectSysLanguage($respectSysLanguage)
177 {
178 $this->respectSysLanguage = $respectSysLanguage;
179 return $this;
180 }
181
182 /**
183 * @return bool TRUE if TYPO3 language settings are to be applied
184 */
185 public function getRespectSysLanguage()
186 {
187 return $this->respectSysLanguage;
188 }
189
190 /**
191 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
192 * @return QuerySettingsInterface instance of $this to allow method chaining
193 * @api
194 */
195 public function setLanguageOverlayMode($languageOverlayMode = false)
196 {
197 $this->languageOverlayMode = $languageOverlayMode;
198 return $this;
199 }
200
201 /**
202 * @return mixed TRUE, FALSE or "hideNonTranslated"
203 */
204 public function getLanguageOverlayMode()
205 {
206 return $this->languageOverlayMode;
207 }
208
209 /**
210 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
211 * @return QuerySettingsInterface instance of $this to allow method chaining
212 * @api
213 */
214 public function setLanguageMode($languageMode = '')
215 {
216 $this->languageMode = $languageMode;
217 return $this;
218 }
219
220 /**
221 * @return string NULL, "content_fallback", "strict" or "ignore"
222 */
223 public function getLanguageMode()
224 {
225 return $this->languageMode;
226 }
227
228 /**
229 * @param int $languageUid
230 * @return QuerySettingsInterface instance of $this to allow method chaining
231 * @api
232 */
233 public function setLanguageUid($languageUid)
234 {
235 $this->languageUid = $languageUid;
236 return $this;
237 }
238
239 /**
240 * @return int
241 */
242 public function getLanguageUid()
243 {
244 return $this->languageUid;
245 }
246
247 /**
248 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
249 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
250 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
251 *
252 * @param bool $ignoreEnableFields
253 * @return QuerySettingsInterface
254 * @see setEnableFieldsToBeIgnored()
255 * @api
256 */
257 public function setIgnoreEnableFields($ignoreEnableFields)
258 {
259 $this->ignoreEnableFields = $ignoreEnableFields;
260 return $this;
261 }
262
263 /**
264 * The returned value indicates whether all or some enable fields should be ignored.
265 *
266 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
267 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
268 *
269 * @return bool
270 * @see getEnableFieldsToBeIgnored()
271 */
272 public function getIgnoreEnableFields()
273 {
274 return $this->ignoreEnableFields;
275 }
276
277 /**
278 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
279 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
280 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
281 *
282 * @param array $enableFieldsToBeIgnored
283 * @return QuerySettingsInterface
284 * @see setIgnoreEnableFields()
285 * @api
286 */
287 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored)
288 {
289 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
290 return $this;
291 }
292
293 /**
294 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
295 * to be ignored while building the query statement.
296 *
297 * @return array
298 * @see getIgnoreEnableFields()
299 */
300 public function getEnableFieldsToBeIgnored()
301 {
302 return $this->enableFieldsToBeIgnored;
303 }
304
305 /**
306 * Sets the flag if the query should return objects that are deleted.
307 *
308 * @param bool $includeDeleted
309 * @return QuerySettingsInterface
310 * @api
311 */
312 public function setIncludeDeleted($includeDeleted)
313 {
314 $this->includeDeleted = $includeDeleted;
315 return $this;
316 }
317
318 /**
319 * Returns if the query should return objects that are deleted.
320 *
321 * @return bool
322 */
323 public function getIncludeDeleted()
324 {
325 return $this->includeDeleted;
326 }
327 }