[BUGFIX] Deprecation log is spammed with getReturnRawQueryResult()
[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 textfile 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 boolean
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 boolean
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 boolean
75 */
76 protected $includeDeleted = FALSE;
77
78 /**
79 * Flag if the sys_language_uid should be respected (default is TRUE).
80 *
81 * @var boolean
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 integer
103 */
104 protected $languageUid = 0;
105
106 /**
107 * Flag if the the query result should be returned as raw QueryResult.
108 *
109 * @var boolean
110 * @deprecated since Extbase 6.2, will be removed two versions later
111 */
112 protected $returnRawQueryResult = FALSE;
113
114 /**
115 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
116 * initializeObject is responsible for handling that.
117 */
118 public function initializeObject() {
119 /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
120 $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
121 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */
122 $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
123 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
124 $this->setIgnoreEnableFields(TRUE);
125 }
126
127 // TYPO3 CMS language defaults
128 $this->setLanguageUid(0);
129 $this->setLanguageMode(NULL);
130 $this->setLanguageOverlayMode(FALSE);
131
132 // Set correct language uid for frontend handling
133 if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
134 $this->setLanguageUid(intval($GLOBALS['TSFE']->sys_language_content));
135 $this->setLanguageOverlayMode($GLOBALS['TSFE']->sys_language_contentOL ?: FALSE);
136 $this->setLanguageMode($GLOBALS['TSFE']->sys_language_mode ?: NULL);
137 } elseif (intval(GeneralUtility::_GP('L'))) {
138 // Set language from 'L' parameter
139 $this->setLanguageUid(intval(GeneralUtility::_GP('L')));
140 }
141 }
142
143 /**
144 * Sets the flag if the storage page should be respected for the query.
145 *
146 * @param boolean $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
147 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
148 * @api
149 */
150 public function setRespectStoragePage($respectStoragePage) {
151 $this->respectStoragePage = $respectStoragePage;
152 return $this;
153 }
154
155 /**
156 * Returns the state, if the storage page should be respected for the query.
157 *
158 * @return boolean TRUE, if the storage page should be respected; otherwise FALSE.
159 */
160 public function getRespectStoragePage() {
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 \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
169 * @api
170 */
171 public function setStoragePageIds(array $storagePageIds) {
172 $this->storagePageIds = $storagePageIds;
173 return $this;
174 }
175
176 /**
177 * Returns the pid(s) of the storage page(s) that should be respected for the query.
178 *
179 * @return array list of integers that each represent a storage page id
180 */
181 public function getStoragePageIds() {
182 return $this->storagePageIds;
183 }
184
185 /**
186 * @param boolean $respectSysLanguage TRUE if TYPO3 language settings are to be applied
187 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
188 * @api
189 */
190 public function setRespectSysLanguage($respectSysLanguage) {
191 $this->respectSysLanguage = $respectSysLanguage;
192 return $this;
193 }
194
195 /**
196 * @return boolean TRUE if TYPO3 language settings are to be applied
197 */
198 public function getRespectSysLanguage() {
199 return $this->respectSysLanguage;
200 }
201
202 /**
203 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
204 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
205 * @api
206 */
207 public function setLanguageOverlayMode($languageOverlayMode = FALSE) {
208 $this->languageOverlayMode = $languageOverlayMode;
209 return $this;
210 }
211
212 /**
213 * @return mixed TRUE, FALSE or "hideNonTranslated"
214 */
215 public function getLanguageOverlayMode() {
216 return $this->languageOverlayMode;
217 }
218
219 /**
220 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
221 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
222 * @api
223 */
224 public function setLanguageMode($languageMode = '') {
225 $this->languageMode = $languageMode;
226 return $this;
227 }
228
229 /**
230 * @return string NULL, "content_fallback", "strict" or "ignore"
231 */
232 public function getLanguageMode() {
233 return $this->languageMode;
234 }
235
236 /**
237 * @param integer $languageUid
238 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
239 * @api
240 */
241 public function setLanguageUid($languageUid) {
242 $this->languageUid = $languageUid;
243 return $this;
244 }
245
246 /**
247 * @return integer
248 */
249 public function getLanguageUid() {
250 return $this->languageUid;
251 }
252
253 /**
254 * Sets the language uid for the language overlay.
255 *
256 * @param integer $sysLanguageUid language uid for the language overlay
257 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
258 * @deprecated since Extbase 6.2, will be removed two versions later. Use setLanguageUid() instead.
259 */
260 public function setSysLanguageUid($sysLanguageUid) {
261 GeneralUtility::logDeprecatedFunction();
262 return $this->setLanguageUid($sysLanguageUid);
263 }
264
265 /**
266 * Returns the language uid for the language overlay
267 *
268 * @return integer language uid for the language overlay
269 * @deprecated since Extbase 6.2, will be removed two versions later. Use getLanguageUid() instead.
270 */
271 public function getSysLanguageUid() {
272 GeneralUtility::logDeprecatedFunction();
273 return $this->getLanguageUid();
274 }
275
276 /**
277 * Sets the flag if the visibility in the frontend should be respected.
278 *
279 * @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.
280 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
281 * @deprecated since Extbase 6.0, will be removed two versions later. Use setIgnoreEnableFields() and setEnableFieldsToBeIgnored() instead.
282 * @see setIgnoreEnableFields()
283 * @see setEnableFieldsToBeIgnored()
284 * @api
285 */
286 public function setRespectEnableFields($respectEnableFields) {
287 GeneralUtility::logDeprecatedFunction();
288 $this->setIgnoreEnableFields(!$respectEnableFields);
289 $this->setIncludeDeleted(!$respectEnableFields);
290 return $this;
291 }
292
293 /**
294 * Returns the state, if the visibility settings for the frontend should be respected for the query.
295 *
296 * @return boolean TRUE, if the visibility settings for the frontend should should be respected; otherwise FALSE.
297 * @deprecated since Extbase 6.0, will be removed two versions later. Use getIgnoreEnableFields() and getEnableFieldsToBeIgnored() instead.
298 * @see getIgnoreEnableFields()
299 * @see getEnableFieldsToBeIgnored()
300 */
301 public function getRespectEnableFields() {
302 GeneralUtility::logDeprecatedFunction();
303 return !($this->getIgnoreEnableFields() && $this->getIncludeDeleted());
304 }
305
306 /**
307 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
308 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
309 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
310 *
311 * @param boolean $ignoreEnableFields
312 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
313 * @see setEnableFieldsToBeIgnored()
314 * @api
315 */
316 public function setIgnoreEnableFields($ignoreEnableFields) {
317 $this->ignoreEnableFields = $ignoreEnableFields;
318 return $this;
319 }
320
321 /**
322 * The returned value indicates whether all or some enable fields should be ignored.
323 *
324 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
325 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
326 *
327 * @return boolean
328 * @see getEnableFieldsToBeIgnored()
329 */
330 public function getIgnoreEnableFields() {
331 return $this->ignoreEnableFields;
332 }
333
334 /**
335 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
336 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
337 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
338 *
339 * @param array $enableFieldsToBeIgnored
340 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
341 * @see setIgnoreEnableFields()
342 * @api
343 */
344 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored) {
345 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
346 return $this;
347 }
348
349 /**
350 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
351 * to be ignored while building the query statement.
352 *
353 * @return array
354 * @see getIgnoreEnableFields()
355 */
356 public function getEnableFieldsToBeIgnored() {
357 return $this->enableFieldsToBeIgnored;
358 }
359
360 /**
361 * Sets the flag if the query should return objects that are deleted.
362 *
363 * @param boolean $includeDeleted
364 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
365 * @api
366 */
367 public function setIncludeDeleted($includeDeleted) {
368 $this->includeDeleted = $includeDeleted;
369 return $this;
370 }
371
372 /**
373 * Returns if the query should return objects that are deleted.
374 *
375 * @return boolean
376 */
377 public function getIncludeDeleted() {
378 return $this->includeDeleted;
379 }
380
381 /**
382 * Sets the state, if the QueryResult should be returned unmapped.
383 *
384 * @param boolean $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
385 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
386 * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
387 */
388 public function setReturnRawQueryResult($returnRawQueryResult) {
389 GeneralUtility::logDeprecatedFunction();
390 $this->returnRawQueryResult = $returnRawQueryResult;
391 return $this;
392 }
393
394 /**
395 * Returns the state, if the QueryResult should be returned unmapped.
396 *
397 * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
398 * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
399 */
400 public function getReturnRawQueryResult() {
401 // We do not log this call intentionally, otherwise the deprecation log would be filled up
402 return $this->returnRawQueryResult;
403 }
404 }