[FEATURE] Enable chaining of set* funtions
[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 4.x.
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 * The language uid for the language overlay.
87 *
88 * @var integer
89 */
90 protected $sysLanguageUid = 0;
91
92 /**
93 * Flag if the the query result should be returned as raw QueryResult.
94 *
95 * @var boolean
96 */
97 protected $returnRawQueryResult = FALSE;
98
99 /**
100 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
101 * initializeObject is responsible for handling that.
102 */
103 public function initializeObject() {
104 /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
105 $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
106 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */
107 $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
108 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
109 $this->setIgnoreEnableFields(TRUE);
110 }
111
112 // Set correct language uid for frontend handling
113 if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
114 $this->setSysLanguageUid($GLOBALS['TSFE']->sys_language_content);
115 } elseif (intval(GeneralUtility::_GP('L'))) {
116 // Set language from 'L' parameter
117 $this->setSysLanguageUid(intval(GeneralUtility::_GP('L')));
118 }
119 }
120
121 /**
122 * Sets the flag if the storage page should be respected for the query.
123 *
124 * @param boolean $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
125 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
126 * @api
127 */
128 public function setRespectStoragePage($respectStoragePage) {
129 $this->respectStoragePage = $respectStoragePage;
130 return $this;
131 }
132
133 /**
134 * Returns the state, if the storage page should be respected for the query.
135 *
136 * @return boolean TRUE, if the storage page should be respected; otherwise FALSE.
137 */
138 public function getRespectStoragePage() {
139 return $this->respectStoragePage;
140 }
141
142 /**
143 * Sets the pid(s) of the storage page(s) that should be respected for the query.
144 *
145 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
146 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
147 * @api
148 */
149 public function setStoragePageIds(array $storagePageIds) {
150 $this->storagePageIds = $storagePageIds;
151 return $this;
152 }
153
154 /**
155 * Returns the pid(s) of the storage page(s) that should be respected for the query.
156 *
157 * @return array list of integers that each represent a storage page id
158 */
159 public function getStoragePageIds() {
160 return $this->storagePageIds;
161 }
162
163 /**
164 * Sets the flag if a and language overlay should be performed.
165 *
166 * @param boolean $respectSysLanguage TRUE if a and language overlay should be performed.
167 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
168 * @api
169 */
170 public function setRespectSysLanguage($respectSysLanguage) {
171 $this->respectSysLanguage = $respectSysLanguage;
172 return $this;
173 }
174
175 /**
176 * Returns the state, if a and language overlay should be performed.
177 *
178 * @return boolean TRUE, if a and language overlay should be performed; otherwise FALSE.
179 */
180 public function getRespectSysLanguage() {
181 return $this->respectSysLanguage;
182 }
183
184 /**
185 * Sets the language uid for the language overlay.
186 *
187 * @param integer $sysLanguageUid language uid for the language overlay
188 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
189 * @api
190 */
191 public function setSysLanguageUid($sysLanguageUid) {
192 $this->sysLanguageUid = $sysLanguageUid;
193 return $this;
194 }
195
196 /**
197 * Returns the language uid for the language overlay
198 *
199 * @return integer language uid for the language overlay
200 */
201 public function getSysLanguageUid() {
202 return $this->sysLanguageUid;
203 }
204
205 /**
206 * Sets the flag if the visibility in the frontend should be respected.
207 *
208 * @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.
209 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
210 * @deprecated since Extbase 6.0, will be removed two versions later. Use setIgnoreEnableFields() and setEnableFieldsToBeIgnored() instead.
211 * @see setIgnoreEnableFields()
212 * @see setEnableFieldsToBeIgnored()
213 * @api
214 */
215 public function setRespectEnableFields($respectEnableFields) {
216 GeneralUtility::logDeprecatedFunction();
217 $this->setIgnoreEnableFields(!$respectEnableFields);
218 $this->setIncludeDeleted(!$respectEnableFields);
219 return $this;
220 }
221
222 /**
223 * Returns the state, if the visibility settings for the frontend should be respected for the query.
224 *
225 * @return boolean TRUE, if the visibility settings for the frontend should should be respected; otherwise FALSE.
226 * @deprecated since Extbase 6.0, will be removed two versions later. Use getIgnoreEnableFields() and getEnableFieldsToBeIgnored() instead.
227 * @see getIgnoreEnableFields()
228 * @see getEnableFieldsToBeIgnored()
229 */
230 public function getRespectEnableFields() {
231 GeneralUtility::logDeprecatedFunction();
232 return !($this->getIgnoreEnableFields() && $this->getIncludeDeleted());
233 }
234
235 /**
236 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
237 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
238 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
239 *
240 * @param boolean $ignoreEnableFields
241 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
242 * @see setEnableFieldsToBeIgnored()
243 * @api
244 */
245 public function setIgnoreEnableFields($ignoreEnableFields) {
246 $this->ignoreEnableFields = $ignoreEnableFields;
247 return $this;
248 }
249
250 /**
251 * The returned value indicates whether all or some enable fields should be ignored.
252 *
253 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
254 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
255 *
256 * @return boolean
257 * @see getEnableFieldsToBeIgnored()
258 */
259 public function getIgnoreEnableFields() {
260 return $this->ignoreEnableFields;
261 }
262
263 /**
264 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
265 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
266 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
267 *
268 * @param array $enableFieldsToBeIgnored
269 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
270 * @see setIgnoreEnableFields()
271 * @api
272 */
273 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored) {
274 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
275 return $this;
276 }
277
278 /**
279 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
280 * to be ignored while building the query statement.
281 *
282 * @return array
283 * @see getIgnoreEnableFields()
284 */
285 public function getEnableFieldsToBeIgnored() {
286 return $this->enableFieldsToBeIgnored;
287 }
288
289 /**
290 * Sets the flag if the query should return objects that are deleted.
291 *
292 * @param boolean $includeDeleted
293 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
294 * @api
295 */
296 public function setIncludeDeleted($includeDeleted) {
297 $this->includeDeleted = $includeDeleted;
298 return $this;
299 }
300
301 /**
302 * Returns if the query should return objects that are deleted.
303 *
304 * @return boolean
305 */
306 public function getIncludeDeleted() {
307 return $this->includeDeleted;
308 }
309
310 /**
311 * Sets the state, if the QueryResult should be returned unmapped.
312 *
313 * @param boolean $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
314 * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
315 */
316 public function setReturnRawQueryResult($returnRawQueryResult) {
317 $this->returnRawQueryResult = $returnRawQueryResult;
318 return $this;
319 }
320
321 /**
322 * Returns the state, if the QueryResult should be returned unmapped.
323 *
324 * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
325 */
326 public function getReturnRawQueryResult() {
327 return $this->returnRawQueryResult;
328 }
329 }
330
331 ?>