[+FEATURE] Extbase (Persistence): Implemented a second Lazy Loading strategy called...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Mapper / ColumnMap.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * A column map to map a column configured in $TCA on a property of a domain object.
27 *
28 * @package Extbase
29 * @subpackage Persistence\Mapper
30 * @version $ID:$
31 */
32 // SK: PHPDoc ;-)
33 class Tx_Extbase_Persistence_Mapper_ColumnMap {
34
35 /**
36 * Constants reflecting the type of relation
37 */
38 const RELATION_NONE = 'RELATION_NONE';
39 const RELATION_HAS_ONE = 'RELATION_HAS_ONE';
40 const RELATION_HAS_MANY = 'RELATION_HAS_MANY';
41 const RELATION_HAS_AND_BELONGS_TO_MANY = 'RELATION_HAS_AND_BELONGS_TO_MANY';
42
43 /**
44 * Constants reflecting the loading strategy
45 */
46 const STRATEGY_EAGER = 'eager';
47 const STRATEGY_LAZY_PROXY = 'proxy';
48 const STRATEGY_LAZY_STORAGE = 'storage';
49
50 /**
51 * The property name corresponding to the table name
52 *
53 * @var string
54 **/
55 protected $propertyName;
56
57 /**
58 * The column name
59 *
60 * @var string
61 **/
62 protected $columnName;
63
64 /**
65 * The type of relation
66 *
67 * @var int
68 **/
69 protected $typeOfRelation;
70
71 /**
72 * The type of value
73 *
74 * @var int
75 **/
76 protected $propertyType;
77
78 /**
79 * The name of the child's class
80 *
81 * @var string
82 **/
83 protected $childClassName;
84
85 /**
86 * The name of the child's table
87 *
88 * @var string
89 **/
90 protected $childTableName;
91
92 /**
93 * The where clause to narrow down the selected child records
94 *
95 * @var string
96 **/
97 protected $childTableWhereStatement;
98
99 /**
100 * The name of the field the results from the child's table are sorted by
101 *
102 * @var string
103 **/
104 protected $childSortByFieldName;
105
106 /**
107 * Flag, if related objects should be deleted with their parents
108 *
109 * @var boolean
110 **/
111 protected $deleteChildObjects = FALSE;
112
113 /**
114 * The name of the relation table
115 *
116 * @var string
117 **/
118 protected $relationTableName;
119
120 /**
121 * An array of field => value pairs to both insert and match against when writing/reading MM relations
122 *
123 * @var string
124 **/
125 protected $relationTableMatchFields;
126
127
128 /**
129 * The where clause to narrow down the selected relation table records
130 *
131 * @var string
132 **/
133 protected $relationTableWhereStatement;
134
135 /**
136 * The name of the field holding the parents key
137 *
138 * @var string
139 **/
140 protected $parentKeyFieldName;
141
142 /**
143 * The name of the field holding the name of the table of the parent's records
144 *
145 * @var string
146 **/
147 protected $parentTableFieldName;
148
149 /**
150 * The name of the field holding the children key
151 *
152 * @var string
153 **/
154 protected $childKeyFieldName;
155
156 /**
157 * Constructs a Column Map
158 *
159 * @param string $columnName The column name
160 * @param string $propertyName The property name
161 * @return void
162 */
163 public function __construct($columnName, $propertyName) {
164 // TODO Enable aliases (tx_anotherextension_addedcolumn -> theAddedColumn)
165 $this->setColumnName($columnName);
166 $this->setPropertyName($propertyName);
167 }
168
169 public function setTypeOfRelation($typeOfRelation) {
170 switch ($typeOfRelation) {
171 case self::RELATION_NONE;
172 case self::RELATION_HAS_ONE;
173 case self::RELATION_HAS_MANY;
174 case self::RELATION_HAS_AND_BELONGS_TO_MANY;
175 $this->typeOfRelation = $typeOfRelation;
176 break;
177 default:
178 $this->typeOfRelation = NULL;
179 break;
180 }
181 }
182
183 public function isRelation() {
184 return $this->typeOfRelation !== NULL && $this->typeOfRelation !== self::RELATION_NONE;
185 }
186
187 public function getTypeOfRelation() {
188 return $this->typeOfRelation;
189 }
190
191 public function setPropertyType($propertyType) {
192 switch ($propertyType) {
193 case Tx_Extbase_Persistence_PropertyType::UNDEFINED;
194 case Tx_Extbase_Persistence_PropertyType::STRING;
195 case Tx_Extbase_Persistence_PropertyType::DATE;
196 case Tx_Extbase_Persistence_PropertyType::LONG;
197 case Tx_Extbase_Persistence_PropertyType::DOUBLE;
198 case Tx_Extbase_Persistence_PropertyType::BOOLEAN;
199 case Tx_Extbase_Persistence_PropertyType::REFERENCE;
200 $this->propertyType = $propertyType;
201 break;
202 default:
203 $this->propertyType = Tx_Extbase_Persistence_PropertyType::UNDEFINED;
204 break;
205 }
206 }
207
208 public function getPropertyType() {
209 return $this->propertyType;
210 }
211
212 public function setLoadingStrategy($loadingStrategy) {
213 switch ($loadingStrategy) {
214 case self::STRATEGY_LAZY_PROXY;
215 case self::STRATEGY_LAZY_STORAGE;
216 $this->loadingStrategy = $loadingStrategy;
217 break;
218 default:
219 $this->loadingStrategy = self::STRATEGY_EAGER;
220 break;
221 }
222 }
223
224 public function getLoadingStrategy() {
225 return $this->loadingStrategy;
226 }
227
228 public function setPropertyName($propertyName) {
229 $this->propertyName = $propertyName;
230 }
231
232 public function getPropertyName() {
233 return $this->propertyName;
234 }
235
236 public function setColumnName($columnName) {
237 $this->columnName = $columnName;
238 }
239
240 public function getColumnName() {
241 return $this->columnName;
242 }
243
244 public function setChildClassName($childClassName) {
245 $this->childClassName = $childClassName;
246 }
247
248 public function getChildClassName() {
249 return $this->childClassName;
250 }
251
252 public function setChildTableName($childTableName) {
253 $this->childTableName = $childTableName;
254 }
255
256 public function getChildTableName() {
257 return $this->childTableName;
258 }
259
260 public function setChildTableWhereStatement($childTableWhereStatement) {
261 $this->childTableWhereStatement = $childTableWhereStatement;
262 }
263
264 public function getChildTableWhereStatement() {
265 return $this->childTableWhereStatement;
266 }
267
268 public function setChildSortByFieldName($childSortByFieldName) {
269 $this->childSortByFieldName = $childSortByFieldName;
270 }
271
272 public function getChildSortByFieldName() {
273 return $this->childSortByFieldName;
274 }
275
276 public function setDeleteChildObjectsState($deleteChildObjects) {
277 $this->deleteChildObjects = (bool)$deleteChildObjects;
278 }
279
280 public function deleteChildObjects() {
281 return $this->deleteChildObjects;
282 }
283
284 public function setRelationTableName($relationTableName) {
285 $this->relationTableName = $relationTableName;
286 }
287
288 public function getRelationTableName() {
289 return $this->relationTableName;
290 }
291
292 public function setRelationTableMatchFields(array $relationTableMatchFields) {
293 $this->relationTableMatchFields = $relationTableMatchFields;
294 }
295
296 public function getRelationTableMatchFields() {
297 return $this->relationTableMatchFields;
298 }
299
300 public function setRelationTableWhereStatement($relationTableWhereStatement) {
301 $this->relationTableWhereStatement = $relationTableWhereStatement;
302 }
303
304 public function getRelationTableWhereStatement() {
305 return $this->relationTableWhereStatement;
306 }
307
308 public function setParentKeyFieldName($parentKeyFieldName) {
309 $this->parentKeyFieldName = $parentKeyFieldName;
310 }
311
312 public function getParentKeyFieldName() {
313 return $this->parentKeyFieldName;
314 }
315
316 public function setParentTableFieldName($parentTableFieldName) {
317 $this->parentTableFieldName = $parentTableFieldName;
318 }
319
320 public function getParentTableFieldName() {
321 return $this->parentTableFieldName;
322 }
323
324 public function setChildKeyFieldName($childKeyFieldName) {
325 $this->childKeyFieldName = $childKeyFieldName;
326 }
327
328 public function getChildKeyFieldName() {
329 return $this->childKeyFieldName;
330 }
331
332 }
333 ?>