[CLEANUP] Add class-imports in Extbase Persistence classes
[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 * Represensting sys_language_uid only valid for current context
90 *
91 * @var int
92 */
93 protected $languageUid = 0;
94
95 /**
96 * Flag whether the query should use a prepared statement
97 *
98 * @var bool
99 * @deprecated since TYPO3 v8, will be removed in TYPO3 9, this option is handled automatically now in the database abstraction
100 */
101 protected $usePreparedStatement = false;
102
103 /**
104 * Flag whether the query should be cached using the caching framework
105 *
106 * @var bool
107 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
108 */
109 protected $useQueryCache = true;
110
111 /**
112 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
113 * initializeObject is responsible for handling that.
114 */
115 public function initializeObject()
116 {
117 /** @var $objectManager ObjectManager */
118 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
119 /** @var $configurationManager ConfigurationManagerInterface */
120 $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
121 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
122 $this->setIgnoreEnableFields(true);
123 }
124
125 // TYPO3 CMS language defaults
126 $this->setLanguageUid(0);
127 $this->setLanguageMode(null);
128 $this->setLanguageOverlayMode(false);
129
130 // Set correct language uid for frontend handling
131 if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
132 $this->setLanguageUid((int)$GLOBALS['TSFE']->sys_language_content);
133 $this->setLanguageOverlayMode($GLOBALS['TSFE']->sys_language_contentOL ?: false);
134 $this->setLanguageMode($GLOBALS['TSFE']->sys_language_mode ?: null);
135 } elseif ((int)GeneralUtility::_GP('L')) {
136 // Set language from 'L' parameter
137 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
138 }
139 }
140
141 /**
142 * Sets the flag if the storage page should be respected for the query.
143 *
144 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
145 * @return QuerySettingsInterface
146 * @api
147 */
148 public function setRespectStoragePage($respectStoragePage)
149 {
150 $this->respectStoragePage = $respectStoragePage;
151 return $this;
152 }
153
154 /**
155 * Returns the state, if the storage page should be respected for the query.
156 *
157 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
158 */
159 public function getRespectStoragePage()
160 {
161 return $this->respectStoragePage;
162 }
163
164 /**
165 * Sets the pid(s) of the storage page(s) that should be respected for the query.
166 *
167 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
168 * @return QuerySettingsInterface
169 * @api
170 */
171 public function setStoragePageIds(array $storagePageIds)
172 {
173 $this->storagePageIds = $storagePageIds;
174 return $this;
175 }
176
177 /**
178 * Returns the pid(s) of the storage page(s) that should be respected for the query.
179 *
180 * @return array list of integers that each represent a storage page id
181 */
182 public function getStoragePageIds()
183 {
184 return $this->storagePageIds;
185 }
186
187 /**
188 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
189 * @return QuerySettingsInterface
190 * @api
191 */
192 public function setRespectSysLanguage($respectSysLanguage)
193 {
194 $this->respectSysLanguage = $respectSysLanguage;
195 return $this;
196 }
197
198 /**
199 * @return bool TRUE if TYPO3 language settings are to be applied
200 */
201 public function getRespectSysLanguage()
202 {
203 return $this->respectSysLanguage;
204 }
205
206 /**
207 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
208 * @return QuerySettingsInterface instance of $this to allow method chaining
209 * @api
210 */
211 public function setLanguageOverlayMode($languageOverlayMode = false)
212 {
213 $this->languageOverlayMode = $languageOverlayMode;
214 return $this;
215 }
216
217 /**
218 * @return mixed TRUE, FALSE or "hideNonTranslated"
219 */
220 public function getLanguageOverlayMode()
221 {
222 return $this->languageOverlayMode;
223 }
224
225 /**
226 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
227 * @return QuerySettingsInterface instance of $this to allow method chaining
228 * @api
229 */
230 public function setLanguageMode($languageMode = '')
231 {
232 $this->languageMode = $languageMode;
233 return $this;
234 }
235
236 /**
237 * @return string NULL, "content_fallback", "strict" or "ignore"
238 */
239 public function getLanguageMode()
240 {
241 return $this->languageMode;
242 }
243
244 /**
245 * @param int $languageUid
246 * @return QuerySettingsInterface instance of $this to allow method chaining
247 * @api
248 */
249 public function setLanguageUid($languageUid)
250 {
251 $this->languageUid = $languageUid;
252 return $this;
253 }
254
255 /**
256 * @return int
257 */
258 public function getLanguageUid()
259 {
260 return $this->languageUid;
261 }
262
263 /**
264 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
265 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
266 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
267 *
268 * @param bool $ignoreEnableFields
269 * @return QuerySettingsInterface
270 * @see setEnableFieldsToBeIgnored()
271 * @api
272 */
273 public function setIgnoreEnableFields($ignoreEnableFields)
274 {
275 $this->ignoreEnableFields = $ignoreEnableFields;
276 return $this;
277 }
278
279 /**
280 * The returned value indicates whether all or some enable fields should be ignored.
281 *
282 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
283 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
284 *
285 * @return bool
286 * @see getEnableFieldsToBeIgnored()
287 */
288 public function getIgnoreEnableFields()
289 {
290 return $this->ignoreEnableFields;
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. Adding a column name here effectively switches off filtering
296 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
297 *
298 * @param array $enableFieldsToBeIgnored
299 * @return QuerySettingsInterface
300 * @see setIgnoreEnableFields()
301 * @api
302 */
303 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored)
304 {
305 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
306 return $this;
307 }
308
309 /**
310 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
311 * to be ignored while building the query statement.
312 *
313 * @return array
314 * @see getIgnoreEnableFields()
315 */
316 public function getEnableFieldsToBeIgnored()
317 {
318 return $this->enableFieldsToBeIgnored;
319 }
320
321 /**
322 * Sets the flag if the query should return objects that are deleted.
323 *
324 * @param bool $includeDeleted
325 * @return QuerySettingsInterface
326 * @api
327 */
328 public function setIncludeDeleted($includeDeleted)
329 {
330 $this->includeDeleted = $includeDeleted;
331 return $this;
332 }
333
334 /**
335 * Returns if the query should return objects that are deleted.
336 *
337 * @return bool
338 */
339 public function getIncludeDeleted()
340 {
341 return $this->includeDeleted;
342 }
343
344 /**
345 * @param bool $usePreparedStatement
346 * @return QuerySettingsInterface
347 * @deprecated since TYPO3 v8, will be removed in TYPO3 9, this option is handled automatically now in the database abstraction
348 */
349 public function usePreparedStatement($usePreparedStatement)
350 {
351 GeneralUtility::logDeprecatedFunction();
352 $this->usePreparedStatement = $usePreparedStatement;
353 return $this;
354 }
355
356 /**
357 * @return bool
358 * @deprecated since TYPO3 v8, will be removed in TYPO3 9, this option is handled automatically now in the database abstraction
359 */
360 public function getUsePreparedStatement()
361 {
362 GeneralUtility::logDeprecatedFunction();
363 return (bool)$this->usePreparedStatement;
364 }
365
366 /**
367 * @param bool $useQueryCache
368 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
369 * @return QuerySettingsInterface
370 */
371 public function useQueryCache($useQueryCache)
372 {
373 GeneralUtility::logDeprecatedFunction();
374 $this->useQueryCache = (bool)$useQueryCache;
375 return $this;
376 }
377
378 /**
379 * @return bool
380 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
381 */
382 public function getUseQueryCache()
383 {
384 GeneralUtility::logDeprecatedFunction();
385 return $this->useQueryCache;
386 }
387 }