5443119c479c0e695293b93bcb2c8118d1472962
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Typo3QuerySettings.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Query settings. This class is NOT part of the FLOW3 API.
34 * It reflects the settings unique to TYPO3 CMS.
35 *
36 * @api
37 */
38 class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface {
39
40 /**
41 * Flag if the storage page should be respected for the query.
42 *
43 * @var bool
44 */
45 protected $respectStoragePage = TRUE;
46
47 /**
48 * the pid(s) of the storage page(s) that should be respected for the query.
49 *
50 * @var array
51 */
52 protected $storagePageIds = array();
53
54 /**
55 * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
56 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
57 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
58 *
59 * @var bool
60 */
61 protected $ignoreEnableFields = FALSE;
62
63 /**
64 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
65 * to be ignored while building the query statement
66 *
67 * @var array
68 */
69 protected $enableFieldsToBeIgnored = array();
70
71 /**
72 * Flag whether deleted records should be included in the result set.
73 *
74 * @var bool
75 */
76 protected $includeDeleted = FALSE;
77
78 /**
79 * Flag if the sys_language_uid should be respected (default is TRUE).
80 *
81 * @var bool
82 */
83 protected $respectSysLanguage = TRUE;
84
85 /**
86 * Representing sys_language_overlay only valid for current context
87 *
88 * @var mixed
89 */
90 protected $languageOverlayMode = TRUE;
91
92 /**
93 * Representing sys_language_mode only valid for current context
94 *
95 * @var string
96 */
97 protected $languageMode = NULL;
98
99 /**
100 * Represensting sys_language_uid only valid for current context
101 *
102 * @var int
103 */
104 protected $languageUid = 0;
105
106 /**
107 * Flag if the the query result should be returned as raw QueryResult.
108 *
109 * @var bool
110 * @deprecated since Extbase 6.2, will be removed two versions later
111 */
112 protected $returnRawQueryResult = FALSE;
113
114 /**
115 * Flag whether the query should use a prepared statement
116 *
117 * @var bool
118 */
119 protected $usePreparedStatement = FALSE;
120
121 /**
122 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
123 * initializeObject is responsible for handling that.
124 */
125 public function initializeObject() {
126 /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
127 $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
128 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */
129 $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
130 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
131 $this->setIgnoreEnableFields(TRUE);
132 }
133
134 // TYPO3 CMS language defaults
135 $this->setLanguageUid(0);
136 $this->setLanguageMode(NULL);
137 $this->setLanguageOverlayMode(FALSE);
138
139 // Set correct language uid for frontend handling
140 if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
141 $this->setLanguageUid((int)$GLOBALS['TSFE']->sys_language_content);
142 $this->setLanguageOverlayMode($GLOBALS['TSFE']->sys_language_contentOL ?: FALSE);
143 $this->setLanguageMode($GLOBALS['TSFE']->sys_language_mode ?: NULL);
144 } elseif ((int)GeneralUtility::_GP('L')) {
145 // Set language from 'L' parameter
146 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
147 }
148 }
149
150 /**
151 * Sets the flag if the storage page should be respected for the query.
152 *
153 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
154 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
155 * @api
156 */
157 public function setRespectStoragePage($respectStoragePage) {
158 $this->respectStoragePage = $respectStoragePage;
159 return $this;
160 }
161
162 /**
163 * Returns the state, if the storage page should be respected for the query.
164 *
165 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
166 */
167 public function getRespectStoragePage() {
168 return $this->respectStoragePage;
169 }
170
171 /**
172 * Sets the pid(s) of the storage page(s) that should be respected for the query.
173 *
174 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
175 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
176 * @api
177 */
178 public function setStoragePageIds(array $storagePageIds) {
179 $this->storagePageIds = $storagePageIds;
180 return $this;
181 }
182
183 /**
184 * Returns the pid(s) of the storage page(s) that should be respected for the query.
185 *
186 * @return array list of integers that each represent a storage page id
187 */
188 public function getStoragePageIds() {
189 return $this->storagePageIds;
190 }
191
192 /**
193 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
194 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
195 * @api
196 */
197 public function setRespectSysLanguage($respectSysLanguage) {
198 $this->respectSysLanguage = $respectSysLanguage;
199 return $this;
200 }
201
202 /**
203 * @return bool TRUE if TYPO3 language settings are to be applied
204 */
205 public function getRespectSysLanguage() {
206 return $this->respectSysLanguage;
207 }
208
209 /**
210 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
211 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
212 * @api
213 */
214 public function setLanguageOverlayMode($languageOverlayMode = FALSE) {
215 $this->languageOverlayMode = $languageOverlayMode;
216 return $this;
217 }
218
219 /**
220 * @return mixed TRUE, FALSE or "hideNonTranslated"
221 */
222 public function getLanguageOverlayMode() {
223 return $this->languageOverlayMode;
224 }
225
226 /**
227 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
228 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
229 * @api
230 */
231 public function setLanguageMode($languageMode = '') {
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 return $this->languageMode;
241 }
242
243 /**
244 * @param int $languageUid
245 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
246 * @api
247 */
248 public function setLanguageUid($languageUid) {
249 $this->languageUid = $languageUid;
250 return $this;
251 }
252
253 /**
254 * @return int
255 */
256 public function getLanguageUid() {
257 return $this->languageUid;
258 }
259
260 /**
261 * Sets the language uid for the language overlay.
262 *
263 * @param int $sysLanguageUid language uid for the language overlay
264 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
265 * @deprecated since Extbase 6.2, will be removed two versions later. Use setLanguageUid() instead.
266 */
267 public function setSysLanguageUid($sysLanguageUid) {
268 GeneralUtility::logDeprecatedFunction();
269 return $this->setLanguageUid($sysLanguageUid);
270 }
271
272 /**
273 * Returns the language uid for the language overlay
274 *
275 * @return int language uid for the language overlay
276 * @deprecated since Extbase 6.2, will be removed two versions later. Use getLanguageUid() instead.
277 */
278 public function getSysLanguageUid() {
279 GeneralUtility::logDeprecatedFunction();
280 return $this->getLanguageUid();
281 }
282
283 /**
284 * Sets the flag if the visibility in the frontend should be respected.
285 *
286 * @param bool $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.
287 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
288 * @deprecated since Extbase 6.0, will be removed two versions later. Use setIgnoreEnableFields() and setEnableFieldsToBeIgnored() instead.
289 * @see setIgnoreEnableFields()
290 * @see setEnableFieldsToBeIgnored()
291 * @api
292 */
293 public function setRespectEnableFields($respectEnableFields) {
294 GeneralUtility::logDeprecatedFunction();
295 $this->setIgnoreEnableFields(!$respectEnableFields);
296 $this->setIncludeDeleted(!$respectEnableFields);
297 return $this;
298 }
299
300 /**
301 * Returns the state, if the visibility settings for the frontend should be respected for the query.
302 *
303 * @return bool TRUE, if the visibility settings for the frontend should should be respected; otherwise FALSE.
304 * @deprecated since Extbase 6.0, will be removed two versions later. Use getIgnoreEnableFields() and getEnableFieldsToBeIgnored() instead.
305 * @see getIgnoreEnableFields()
306 * @see getEnableFieldsToBeIgnored()
307 */
308 public function getRespectEnableFields() {
309 GeneralUtility::logDeprecatedFunction();
310 return !($this->getIgnoreEnableFields() && $this->getIncludeDeleted());
311 }
312
313 /**
314 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
315 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
316 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
317 *
318 * @param bool $ignoreEnableFields
319 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
320 * @see setEnableFieldsToBeIgnored()
321 * @api
322 */
323 public function setIgnoreEnableFields($ignoreEnableFields) {
324 $this->ignoreEnableFields = $ignoreEnableFields;
325 return $this;
326 }
327
328 /**
329 * The returned value indicates whether all or some enable fields should be ignored.
330 *
331 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
332 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
333 *
334 * @return bool
335 * @see getEnableFieldsToBeIgnored()
336 */
337 public function getIgnoreEnableFields() {
338 return $this->ignoreEnableFields;
339 }
340
341 /**
342 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
343 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
344 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
345 *
346 * @param array $enableFieldsToBeIgnored
347 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
348 * @see setIgnoreEnableFields()
349 * @api
350 */
351 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored) {
352 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
353 return $this;
354 }
355
356 /**
357 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
358 * to be ignored while building the query statement.
359 *
360 * @return array
361 * @see getIgnoreEnableFields()
362 */
363 public function getEnableFieldsToBeIgnored() {
364 return $this->enableFieldsToBeIgnored;
365 }
366
367 /**
368 * Sets the flag if the query should return objects that are deleted.
369 *
370 * @param bool $includeDeleted
371 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
372 * @api
373 */
374 public function setIncludeDeleted($includeDeleted) {
375 $this->includeDeleted = $includeDeleted;
376 return $this;
377 }
378
379 /**
380 * Returns if the query should return objects that are deleted.
381 *
382 * @return bool
383 */
384 public function getIncludeDeleted() {
385 return $this->includeDeleted;
386 }
387
388 /**
389 * Sets the state, if the QueryResult should be returned unmapped.
390 *
391 * @param bool $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
392 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
393 * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
394 */
395 public function setReturnRawQueryResult($returnRawQueryResult) {
396 GeneralUtility::logDeprecatedFunction();
397 $this->returnRawQueryResult = $returnRawQueryResult;
398 return $this;
399 }
400
401 /**
402 * Returns the state, if the QueryResult should be returned unmapped.
403 *
404 * @return bool TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
405 * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
406 */
407 public function getReturnRawQueryResult() {
408 // We do not log this call intentionally, otherwise the deprecation log would be filled up
409 return $this->returnRawQueryResult;
410 }
411
412 /**
413 * @param bool $usePreparedStatement
414 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
415 */
416 public function usePreparedStatement($usePreparedStatement) {
417 $this->usePreparedStatement = $usePreparedStatement;
418 return $this;
419 }
420
421 /**
422 * @return bool
423 */
424 public function getUsePreparedStatement() {
425 return (bool)$this->usePreparedStatement;
426 }
427 }