[FEATURE] Handle enable fields and deleted records settings granulary
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Typo3QuerySettings.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
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 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Query settings. This class is NOT part of the FLOW3 API.
30 * It reflects the settings unique to TYPO3 4.x.
31 *
32 * @package Extbase
33 * @subpackage Persistence
34 * @version $Id$
35 * @api
36 */
37 class Tx_Extbase_Persistence_Typo3QuerySettings implements Tx_Extbase_Persistence_QuerySettingsInterface {
38
39 /**
40 * Flag if the storage page should be respected for the query.
41 * @var boolean
42 */
43 protected $respectStoragePage = TRUE;
44
45 /**
46 * the pid(s) of the storage page(s) that should be respected for the query.
47 * @var array
48 */
49 protected $storagePageIds = array();
50
51 /**
52 * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
53 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
54 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
55 * @var boolean
56 */
57 protected $ignoreEnableFields = FALSE;
58
59 /**
60 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
61 * to be ignored while building the query statement
62 * @var array
63 */
64 protected $enableFieldsToBeIgnored = array();
65
66 /**
67 * Flag whether deleted records should be included in the result set.
68 * @var boolean
69 */
70 protected $includeDeleted = FALSE;
71
72 /**
73 * Flag if the sys_language_uid should be respected (default is TRUE).
74 * @var boolean
75 */
76 protected $respectSysLanguage = TRUE;
77
78 /**
79 * Flag if the the query result should be returned as raw QueryResult.
80 * @var boolean
81 */
82 protected $returnRawQueryResult = FALSE;
83
84 /**
85 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
86 * initializeObject is responsible for handling that.
87 */
88 public function initializeObject() {
89 /** @var $objectManager Tx_Extbase_Object_ObjectManager */
90 $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
91 /** @var $configurationManager Tx_Extbase_Configuration_ConfigurationManagerInterface */
92 $configurationManager = $objectManager->get('Tx_Extbase_Configuration_ConfigurationManagerInterface');
93 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
94 $this->setIgnoreEnableFields(TRUE);
95 }
96 }
97
98 /**
99 * Sets the flag if the storage page should be respected for the query.
100 *
101 * @param boolean $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
102 * @return Tx_Extbase_Persistence_QuerySettingsInterface (fluent interface)
103 * @api
104 */
105 public function setRespectStoragePage($respectStoragePage) {
106 $this->respectStoragePage = $respectStoragePage;
107 return $this;
108 }
109
110 /**
111 * Returns the state, if the storage page should be respected for the query.
112 *
113 * @return boolean TRUE, if the storage page should be respected; otherwise FALSE.
114 */
115 public function getRespectStoragePage() {
116 return $this->respectStoragePage;
117 }
118
119 /**
120 * Sets the pid(s) of the storage page(s) that should be respected for the query.
121 *
122 * @param array $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
123 * @return Tx_Extbase_Persistence_QuerySettingsInterface instance of $this to allow method chaining
124 * @api
125 */
126 public function setStoragePageIds(array $storagePageIds) {
127 $this->storagePageIds = $storagePageIds;
128 }
129
130 /**
131 * Returns the pid(s) of the storage page(s) that should be respected for the query.
132 *
133 * @return array list of integers that each represent a storage page id
134 */
135 public function getStoragePageIds() {
136 return $this->storagePageIds;
137 }
138
139 /**
140 * Sets the flag if a and language overlay should be performed.
141 *
142 * @param boolean $respectEnableFields TRUE if a and language overlay should be performed.
143 * @return Tx_Extbase_Persistence_QuerySettingsInterface (fluent interface)
144 * @api
145 */
146 public function setRespectSysLanguage($respectSysLanguage) {
147 $this->respectSysLanguage = $respectSysLanguage;
148 return $this;
149 }
150
151 /**
152 * Returns the state, if a and language overlay should be performed.
153 *
154 * @return boolean TRUE, if a and language overlay should be performed; otherwise FALSE.
155 */
156 public function getRespectSysLanguage() {
157 return $this->respectSysLanguage;
158 }
159
160 /**
161 * Sets the flag if the visibility in the frontend should be respected.
162 *
163 * @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.
164 * @return Tx_Extbase_Persistence_QuerySettingsInterface (fluent interface)
165 * @deprecated since Extbase 6.0, will be removed in Extbase 6.2. Use setIgnoreEnableFields() and setEnableFieldsToBeIgnored() instead.
166 * @see setIgnoreEnableFields()
167 * @see setEnableFieldsToBeIgnored()
168 * @api
169 */
170 public function setRespectEnableFields($respectEnableFields) {
171 t3lib_div::logDeprecatedFunction();
172 $this->setIgnoreEnableFields(!$respectEnableFields);
173 $this->setIncludeDeleted(!$respectEnableFields);
174 return $this;
175 }
176
177 /**
178 * Returns the state, if the visibility settings for the frontend should be respected for the query.
179 *
180 * @return boolean TRUE, if the visibility settings for the frontend should should be respected; otherwise FALSE.
181 * @deprecated since Extbase 6.0, will be removed in Extbase 6.2. Use getIgnoreEnableFields() and getEnableFieldsToBeIgnored() instead.
182 * @see getIgnoreEnableFields()
183 * @see getEnableFieldsToBeIgnored()
184 */
185 public function getRespectEnableFields() {
186 t3lib_div::logDeprecatedFunction();
187 return !($this->getIgnoreEnableFields() && $this->getIncludeDeleted());
188 }
189
190 /**
191 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
192 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
193 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
194 *
195 * @param boolean $ignoreEnableFields
196 * @see setEnableFieldsToBeIgnored()
197 * @api
198 */
199 public function setIgnoreEnableFields($ignoreEnableFields) {
200 $this->ignoreEnableFields = $ignoreEnableFields;
201 }
202
203 /**
204 * The returned value indicates whether all or some enable fields should be ignored.
205 *
206 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
207 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
208 *
209 * @return boolean
210 * @see getEnableFieldsToBeIgnored()
211 */
212 public function getIgnoreEnableFields() {
213 return $this->ignoreEnableFields;
214 }
215
216 /**
217 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
218 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
219 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
220 *
221 * @param array $enableFieldsToBeIgnored
222 * @return void
223 * @see setIgnoreEnableFields()
224 * @api
225 */
226 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored) {
227 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
228 }
229
230 /**
231 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
232 * to be ignored while building the query statement.
233 *
234 * @return array
235 * @see getIgnoreEnableFields()
236 */
237 public function getEnableFieldsToBeIgnored() {
238 return $this->enableFieldsToBeIgnored;
239 }
240
241 /**
242 * Sets the flag if the query should return objects that are deleted.
243 *
244 * @param boolean $includeDeleted
245 * @return void
246 * @api
247 */
248 public function setIncludeDeleted($includeDeleted) {
249 $this->includeDeleted = $includeDeleted;
250 }
251
252 /**
253 * Returns if the query should return objects that are deleted.
254 *
255 * @return boolean
256 */
257 public function getIncludeDeleted() {
258 return $this->includeDeleted;
259 }
260
261 /**
262 * Sets the state, if the QueryResult should be returned unmapped.
263 *
264 * @var boolean $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
265 * @return void
266 */
267 public function setReturnRawQueryResult($returnRawQueryResult) {
268 $this->returnRawQueryResult = $returnRawQueryResult;
269 }
270
271 /**
272 * Returns the state, if the QueryResult should be returned unmapped.
273 *
274 * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
275 */
276 public function getReturnRawQueryResult() {
277 return $this->returnRawQueryResult;
278 }
279
280 }
281 ?>