Add Extbase 1.0.1 to TYPO3core. Do NOT make changes inside! See misc/core_svn_rules...
[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 * The name of the relation table
108 *
109 * @var string
110 **/
111 protected $relationTableName;
112
113 /**
114 * An array of field => value pairs to both insert and match against when writing/reading MM relations
115 *
116 * @var array
117 **/
118 protected $relationTableMatchFields;
119
120 /**
121 * Array of field=>value pairs to insert when writing new MM relations
122 *
123 * @var array
124 **/
125 protected $relationTableInsertFields;
126
127 /**
128 * The where clause to narrow down the selected relation table records
129 *
130 * @var string
131 **/
132 protected $relationTableWhereStatement;
133
134 /**
135 * The name of the field holding the parents key
136 *
137 * @var string
138 **/
139 protected $parentKeyFieldName;
140
141 /**
142 * The name of the field holding the name of the table of the parent's records
143 *
144 * @var string
145 **/
146 protected $parentTableFieldName;
147
148 /**
149 * The name of the field holding the children key
150 *
151 * @var string
152 **/
153 protected $childKeyFieldName;
154
155 /**
156 * Constructs a Column Map
157 *
158 * @param string $columnName The column name
159 * @param string $propertyName The property name
160 * @return void
161 */
162 public function __construct($columnName, $propertyName) {
163 // TODO Enable aliases (tx_anotherextension_addedcolumn -> theAddedColumn)
164 $this->setColumnName($columnName);
165 $this->setPropertyName($propertyName);
166 }
167
168 public function setTypeOfRelation($typeOfRelation) {
169 switch ($typeOfRelation) {
170 case self::RELATION_NONE;
171 case self::RELATION_HAS_ONE;
172 case self::RELATION_HAS_MANY;
173 case self::RELATION_HAS_AND_BELONGS_TO_MANY;
174 $this->typeOfRelation = $typeOfRelation;
175 break;
176 default:
177 $this->typeOfRelation = NULL;
178 break;
179 }
180 }
181
182 public function isRelation() {
183 return $this->typeOfRelation !== NULL && $this->typeOfRelation !== self::RELATION_NONE;
184 }
185
186 public function getTypeOfRelation() {
187 return $this->typeOfRelation;
188 }
189
190 public function setPropertyType($propertyType) {
191 switch ($propertyType) {
192 case Tx_Extbase_Persistence_PropertyType::UNDEFINED;
193 case Tx_Extbase_Persistence_PropertyType::STRING;
194 case Tx_Extbase_Persistence_PropertyType::DATE;
195 case Tx_Extbase_Persistence_PropertyType::LONG;
196 case Tx_Extbase_Persistence_PropertyType::DOUBLE;
197 case Tx_Extbase_Persistence_PropertyType::BOOLEAN;
198 case Tx_Extbase_Persistence_PropertyType::REFERENCE;
199 $this->propertyType = $propertyType;
200 break;
201 default:
202 $this->propertyType = Tx_Extbase_Persistence_PropertyType::UNDEFINED;
203 break;
204 }
205 }
206
207 public function getPropertyType() {
208 return $this->propertyType;
209 }
210
211 public function setLoadingStrategy($loadingStrategy) {
212 switch ($loadingStrategy) {
213 case self::STRATEGY_LAZY_PROXY;
214 case self::STRATEGY_LAZY_STORAGE;
215 case self::STRATEGY_EAGER;
216 $this->loadingStrategy = $loadingStrategy;
217 break;
218 }
219 }
220
221 public function getLoadingStrategy() {
222 return $this->loadingStrategy;
223 }
224
225 public function setPropertyName($propertyName) {
226 $this->propertyName = $propertyName;
227 }
228
229 public function getPropertyName() {
230 return $this->propertyName;
231 }
232
233 public function setColumnName($columnName) {
234 $this->columnName = $columnName;
235 }
236
237 public function getColumnName() {
238 return $this->columnName;
239 }
240
241 public function setChildClassName($childClassName) {
242 $this->childClassName = $childClassName;
243 }
244
245 public function getChildClassName() {
246 return $this->childClassName;
247 }
248
249 public function setChildTableName($childTableName) {
250 $this->childTableName = $childTableName;
251 }
252
253 public function getChildTableName() {
254 return $this->childTableName;
255 }
256
257 public function setChildTableWhereStatement($childTableWhereStatement) {
258 $this->childTableWhereStatement = $childTableWhereStatement;
259 }
260
261 public function getChildTableWhereStatement() {
262 return $this->childTableWhereStatement;
263 }
264
265 public function setChildSortByFieldName($childSortByFieldName) {
266 $this->childSortByFieldName = $childSortByFieldName;
267 }
268
269 public function getChildSortByFieldName() {
270 return $this->childSortByFieldName;
271 }
272
273 public function setRelationTableName($relationTableName) {
274 $this->relationTableName = $relationTableName;
275 }
276
277 public function getRelationTableName() {
278 return $this->relationTableName;
279 }
280
281 public function setRelationTableMatchFields(array $relationTableMatchFields) {
282 $this->relationTableMatchFields = $relationTableMatchFields;
283 }
284
285 public function getRelationTableMatchFields() {
286 return $this->relationTableMatchFields;
287 }
288
289 public function setRelationTableInsertFields(array $relationTableInsertFields) {
290 $this->relationTableInsertFields = $relationTableInsertFields;
291 }
292
293 public function getRelationTableInsertFields() {
294 return $this->relationTableInsertFields;
295 }
296
297 public function setRelationTableWhereStatement($relationTableWhereStatement) {
298 $this->relationTableWhereStatement = $relationTableWhereStatement;
299 }
300
301 public function getRelationTableWhereStatement() {
302 return $this->relationTableWhereStatement;
303 }
304
305 public function setParentKeyFieldName($parentKeyFieldName) {
306 $this->parentKeyFieldName = $parentKeyFieldName;
307 }
308
309 public function getParentKeyFieldName() {
310 return $this->parentKeyFieldName;
311 }
312
313 public function setParentTableFieldName($parentTableFieldName) {
314 $this->parentTableFieldName = $parentTableFieldName;
315 }
316
317 public function getParentTableFieldName() {
318 return $this->parentTableFieldName;
319 }
320
321 public function setChildKeyFieldName($childKeyFieldName) {
322 $this->childKeyFieldName = $childKeyFieldName;
323 }
324
325 public function getChildKeyFieldName() {
326 return $this->childKeyFieldName;
327 }
328
329 }
330 ?>