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