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