[TASK] Streamline phpdoc annotations in EXT:extbase
[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\Context\Context;
18 use TYPO3\CMS\Core\Context\LanguageAspect;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
21 use TYPO3\CMS\Extbase\Object\ObjectManager;
22 use TYPO3\CMS\Extbase\Service\EnvironmentService;
23
24 /**
25 * Query settings, reflects the settings unique to TYPO3 CMS.
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 * Language Mode is NOT used when consistentTranslationOverlayHandling is enabled
83 *
84 * Representing sys_language_mode only valid for current context
85 *
86 * @var string
87 */
88 protected $languageMode;
89
90 /**
91 * Representing sys_language_uid only valid for current context
92 *
93 * @var int
94 */
95 protected $languageUid = 0;
96
97 /**
98 * @var EnvironmentService
99 */
100 protected $environmentService;
101
102 /**
103 * @param EnvironmentService $environmentService
104 */
105 public function injectEnvironmentService(EnvironmentService $environmentService)
106 {
107 $this->environmentService = $environmentService;
108 }
109
110 /**
111 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
112 * initializeObject is responsible for handling that.
113 */
114 public function initializeObject()
115 {
116 /** @var ObjectManager $objectManager */
117 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
118 /** @var ConfigurationManagerInterface $configurationManager */
119 $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
120 if ($this->environmentService->isEnvironmentInBackendMode() && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
121 $this->setIgnoreEnableFields(true);
122 }
123 /** @var LanguageAspect $languageAspect */
124 $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
125 $this->setLanguageUid($languageAspect->getContentId());
126 $this->setLanguageOverlayMode(false);
127
128 if ($this->environmentService->isEnvironmentInFrontendMode()) {
129 $overlayMode = $languageAspect->getLegacyOverlayType() === 'hideNonTranslated' ? 'hideNonTranslated' : (bool)$languageAspect->getLegacyOverlayType();
130 $this->setLanguageOverlayMode($overlayMode);
131 $this->setLanguageMode($languageAspect->getLegacyLanguageMode() ?: null);
132 } elseif ((int)GeneralUtility::_GP('L')) {
133 // Set language from 'L' parameter
134 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
135 }
136 }
137
138 /**
139 * Sets the flag if the storage page should be respected for the query.
140 *
141 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
142 * @return QuerySettingsInterface
143 */
144 public function setRespectStoragePage($respectStoragePage)
145 {
146 $this->respectStoragePage = $respectStoragePage;
147 return $this;
148 }
149
150 /**
151 * Returns the state, if the storage page should be respected for the query.
152 *
153 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
154 */
155 public function getRespectStoragePage()
156 {
157 return $this->respectStoragePage;
158 }
159
160 /**
161 * Sets the pid(s) of the storage page(s) that should be respected for the query.
162 *
163 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
164 * @return QuerySettingsInterface
165 */
166 public function setStoragePageIds(array $storagePageIds)
167 {
168 $this->storagePageIds = $storagePageIds;
169 return $this;
170 }
171
172 /**
173 * Returns the pid(s) of the storage page(s) that should be respected for the query.
174 *
175 * @return array list of integers that each represent a storage page id
176 */
177 public function getStoragePageIds()
178 {
179 return $this->storagePageIds;
180 }
181
182 /**
183 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
184 * @return QuerySettingsInterface
185 */
186 public function setRespectSysLanguage($respectSysLanguage)
187 {
188 $this->respectSysLanguage = $respectSysLanguage;
189 return $this;
190 }
191
192 /**
193 * @return bool TRUE if TYPO3 language settings are to be applied
194 */
195 public function getRespectSysLanguage()
196 {
197 return $this->respectSysLanguage;
198 }
199
200 /**
201 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
202 * @return QuerySettingsInterface instance of $this to allow method chaining
203 */
204 public function setLanguageOverlayMode($languageOverlayMode = false)
205 {
206 $this->languageOverlayMode = $languageOverlayMode;
207 return $this;
208 }
209
210 /**
211 * @return mixed TRUE, FALSE or "hideNonTranslated"
212 */
213 public function getLanguageOverlayMode()
214 {
215 return $this->languageOverlayMode;
216 }
217
218 /**
219 * Language Mode is NOT used when consistentTranslationOverlayHandling is enabled
220 *
221 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
222 * @return QuerySettingsInterface instance of $this to allow method chaining
223 */
224 public function setLanguageMode($languageMode = '')
225 {
226 $this->languageMode = $languageMode;
227 return $this;
228 }
229
230 /**
231 * Language Mode is NOT used when consistentTranslationOverlayHandling is enabled
232 *
233 * @return string NULL, "content_fallback", "strict" or "ignore"
234 */
235 public function getLanguageMode()
236 {
237 return $this->languageMode;
238 }
239
240 /**
241 * @param int $languageUid
242 * @return QuerySettingsInterface instance of $this to allow method chaining
243 */
244 public function setLanguageUid($languageUid)
245 {
246 $this->languageUid = $languageUid;
247 return $this;
248 }
249
250 /**
251 * @return int
252 */
253 public function getLanguageUid()
254 {
255 return $this->languageUid;
256 }
257
258 /**
259 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
260 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
261 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
262 *
263 * @param bool $ignoreEnableFields
264 * @return QuerySettingsInterface
265 * @see setEnableFieldsToBeIgnored()
266 */
267 public function setIgnoreEnableFields($ignoreEnableFields)
268 {
269 $this->ignoreEnableFields = $ignoreEnableFields;
270 return $this;
271 }
272
273 /**
274 * The returned value indicates whether all or some enable fields should be ignored.
275 *
276 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
277 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
278 *
279 * @return bool
280 * @see getEnableFieldsToBeIgnored()
281 */
282 public function getIgnoreEnableFields()
283 {
284 return $this->ignoreEnableFields;
285 }
286
287 /**
288 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
289 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
290 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
291 *
292 * @param array $enableFieldsToBeIgnored
293 * @return QuerySettingsInterface
294 * @see setIgnoreEnableFields()
295 */
296 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored)
297 {
298 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
299 return $this;
300 }
301
302 /**
303 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
304 * to be ignored while building the query statement.
305 *
306 * @return array
307 * @see getIgnoreEnableFields()
308 */
309 public function getEnableFieldsToBeIgnored()
310 {
311 return $this->enableFieldsToBeIgnored;
312 }
313
314 /**
315 * Sets the flag if the query should return objects that are deleted.
316 *
317 * @param bool $includeDeleted
318 * @return QuerySettingsInterface
319 */
320 public function setIncludeDeleted($includeDeleted)
321 {
322 $this->includeDeleted = $includeDeleted;
323 return $this;
324 }
325
326 /**
327 * Returns if the query should return objects that are deleted.
328 *
329 * @return bool
330 */
331 public function getIncludeDeleted()
332 {
333 return $this->includeDeleted;
334 }
335 }