[+BUGFIX] Extbase (Persistence): Fixed broken IRRE setups. The type of relation is...
[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_BELONGS_TO_MANY = 'RELATION_BELONGS_TO_MANY';
42 const RELATION_HAS_AND_BELONGS_TO_MANY = 'RELATION_HAS_AND_BELONGS_TO_MANY';
43
44 /**
45 * Constants reflecting the loading strategy
46 */
47 const STRATEGY_EAGER = 'eager';
48 const STRATEGY_LAZY_PROXY = 'proxy';
49 const STRATEGY_LAZY_STORAGE = 'storage';
50
51 /**
52 * The property name corresponding to the table name
53 *
54 * @var string
55 **/
56 protected $propertyName;
57
58 /**
59 * The column name
60 *
61 * @var string
62 **/
63 protected $columnName;
64
65 /**
66 * The type of relation
67 *
68 * @var int
69 **/
70 protected $typeOfRelation;
71
72 /**
73 * The type of value
74 *
75 * @var int
76 **/
77 protected $propertyType;
78
79 /**
80 * The name of the child's class
81 *
82 * @var string
83 **/
84 protected $childClassName;
85
86 /**
87 * The name of the child's table
88 *
89 * @var string
90 **/
91 protected $childTableName;
92
93 /**
94 * The where clause to narrow down the selected child records
95 *
96 * @var string
97 **/
98 protected $childTableWhereStatement;
99
100 /**
101 * The name of the field the results from the child's table are sorted by
102 *
103 * @var string
104 **/
105 protected $childSortByFieldName;
106
107 /**
108 * The name of the relation table
109 *
110 * @var string
111 **/
112 protected $relationTableName;
113
114 /**
115 * An array of field => value pairs to both insert and match against when writing/reading MM relations
116 *
117 * @var array
118 **/
119 protected $relationTableMatchFields;
120
121 /**
122 * Array of field=>value pairs to insert when writing new MM relations
123 *
124 * @var array
125 **/
126 protected $relationTableInsertFields;
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_BELONGS_TO_MANY;
175 case self::RELATION_HAS_AND_BELONGS_TO_MANY;
176 $this->typeOfRelation = $typeOfRelation;
177 break;
178 default:
179 $this->typeOfRelation = NULL;
180 break;
181 }
182 }
183
184 public function isRelation() {
185 return $this->typeOfRelation !== NULL && $this->typeOfRelation !== self::RELATION_NONE;
186 }
187
188 public function getTypeOfRelation() {
189 return $this->typeOfRelation;
190 }
191
192 public function setPropertyType($propertyType) {
193 switch ($propertyType) {
194 case Tx_Extbase_Persistence_PropertyType::UNDEFINED;
195 case Tx_Extbase_Persistence_PropertyType::STRING;
196 case Tx_Extbase_Persistence_PropertyType::DATE;
197 case Tx_Extbase_Persistence_PropertyType::LONG;
198 case Tx_Extbase_Persistence_PropertyType::DOUBLE;
199 case Tx_Extbase_Persistence_PropertyType::BOOLEAN;
200 case Tx_Extbase_Persistence_PropertyType::REFERENCE;
201 $this->propertyType = $propertyType;
202 break;
203 default:
204 $this->propertyType = Tx_Extbase_Persistence_PropertyType::UNDEFINED;
205 break;
206 }
207 }
208
209 public function getPropertyType() {
210 return $this->propertyType;
211 }
212
213 public function setLoadingStrategy($loadingStrategy) {
214 switch ($loadingStrategy) {
215 case self::STRATEGY_LAZY_PROXY;
216 case self::STRATEGY_LAZY_STORAGE;
217 case self::STRATEGY_EAGER;
218 $this->loadingStrategy = $loadingStrategy;
219 break;
220 }
221 }
222
223 public function getLoadingStrategy() {
224 return $this->loadingStrategy;
225 }
226
227 public function setPropertyName($propertyName) {
228 $this->propertyName = $propertyName;
229 }
230
231 public function getPropertyName() {
232 return $this->propertyName;
233 }
234
235 public function setColumnName($columnName) {
236 $this->columnName = $columnName;
237 }
238
239 public function getColumnName() {
240 return $this->columnName;
241 }
242
243 public function setChildTableName($childTableName) {
244 $this->childTableName = $childTableName;
245 }
246
247 public function getChildTableName() {
248 return $this->childTableName;
249 }
250
251 public function setChildTableWhereStatement($childTableWhereStatement) {
252 $this->childTableWhereStatement = $childTableWhereStatement;
253 }
254
255 public function getChildTableWhereStatement() {
256 return $this->childTableWhereStatement;
257 }
258
259 public function setChildSortByFieldName($childSortByFieldName) {
260 $this->childSortByFieldName = $childSortByFieldName;
261 }
262
263 public function getChildSortByFieldName() {
264 return $this->childSortByFieldName;
265 }
266
267 public function setRelationTableName($relationTableName) {
268 $this->relationTableName = $relationTableName;
269 }
270
271 public function getRelationTableName() {
272 return $this->relationTableName;
273 }
274
275 public function setRelationTableMatchFields(array $relationTableMatchFields) {
276 $this->relationTableMatchFields = $relationTableMatchFields;
277 }
278
279 public function getRelationTableMatchFields() {
280 return $this->relationTableMatchFields;
281 }
282
283 public function setRelationTableInsertFields(array $relationTableInsertFields) {
284 $this->relationTableInsertFields = $relationTableInsertFields;
285 }
286
287 public function getRelationTableInsertFields() {
288 return $this->relationTableInsertFields;
289 }
290
291 public function setRelationTableWhereStatement($relationTableWhereStatement) {
292 $this->relationTableWhereStatement = $relationTableWhereStatement;
293 }
294
295 public function getRelationTableWhereStatement() {
296 return $this->relationTableWhereStatement;
297 }
298
299 public function setParentKeyFieldName($parentKeyFieldName) {
300 $this->parentKeyFieldName = $parentKeyFieldName;
301 }
302
303 public function getParentKeyFieldName() {
304 return $this->parentKeyFieldName;
305 }
306
307 public function setParentTableFieldName($parentTableFieldName) {
308 $this->parentTableFieldName = $parentTableFieldName;
309 }
310
311 public function getParentTableFieldName() {
312 return $this->parentTableFieldName;
313 }
314
315 public function setChildKeyFieldName($childKeyFieldName) {
316 $this->childKeyFieldName = $childKeyFieldName;
317 }
318
319 public function getChildKeyFieldName() {
320 return $this->childKeyFieldName;
321 }
322
323 }
324 ?>