Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/**
4
 * Base class that represents a row from the 'product' table.
5
 *
6
 *
7
 *
8
 * This class was autogenerated by Propel 1.4.2 on:
9
 *
10
 * Fri Aug  5 09:39:37 2011
11
 *
12
 * @package    lib.model.om
13
 */
14
abstract class BaseProduct extends BaseObject  implements Persistent {
15
 
16
 
17
	/**
18
	 * The Peer class.
19
	 * Instance provides a convenient way of calling static methods on a class
20
	 * that calling code may not be able to identify.
21
	 * @var        ProductPeer
22
	 */
23
	protected static $peer;
24
 
25
	/**
26
	 * The value for the id field.
27
	 * @var        int
28
	 */
29
	protected $id;
30
 
31
	/**
32
	 * The value for the price field.
33
	 * @var        double
34
	 */
35
	protected $price;
36
 
37
	/**
38
	 * The value for the a_primary_string field.
39
	 * @var        string
40
	 */
41
	protected $a_primary_string;
42
 
43
	/**
44
	 * @var        array ProductI18n[] Collection to store aggregation of ProductI18n objects.
45
	 */
46
	protected $collTranslations;
47
 
48
	/**
49
	 * @var        Criteria The criteria used to select the current contents of collTranslations.
50
	 */
51
	private $lastTranslationCriteria = null;
52
 
53
	/**
54
	 * Flag to prevent endless save loop, if this object is referenced
55
	 * by another object which falls in this transaction.
56
	 * @var        boolean
57
	 */
58
	protected $alreadyInSave = false;
59
 
60
	/**
61
	 * Flag to prevent endless validation loop, if this object is referenced
62
	 * by another object which falls in this transaction.
63
	 * @var        boolean
64
	 */
65
	protected $alreadyInValidation = false;
66
 
67
	// symfony behavior
68
 
69
	const PEER = 'ProductPeer';
70
 
71
	// symfony_i18n behavior
72
 
73
	/**
74
	 * @var string The value for the culture field
75
	 */
76
	protected $culture = null;
77
 
78
	/**
79
	 * @var array Current I18N objects
80
	 */
81
	protected $current_i18n = array();
82
 
83
	/**
84
	 * Get the [id] column value.
85
	 *
86
	 * @return     int
87
	 */
88
	public function getId()
89
	{
90
		return $this->id;
91
	}
92
 
93
	/**
94
	 * Get the [price] column value.
95
	 *
96
	 * @return     double
97
	 */
98
	public function getPrice()
99
	{
100
		return $this->price;
101
	}
102
 
103
	/**
104
	 * Get the [a_primary_string] column value.
105
	 *
106
	 * @return     string
107
	 */
108
	public function getAPrimaryString()
109
	{
110
		return $this->a_primary_string;
111
	}
112
 
113
	/**
114
	 * Set the value of [id] column.
115
	 *
116
	 * @param      int $v new value
117
	 * @return     Product The current object (for fluent API support)
118
	 */
119
	public function setId($v)
120
	{
121
		if ($v !== null) {
122
			$v = (int) $v;
123
		}
124
 
125
		if ($this->id !== $v) {
126
			$this->id = $v;
127
			$this->modifiedColumns[] = ProductPeer::ID;
128
		}
129
 
130
		return $this;
131
	} // setId()
132
 
133
	/**
134
	 * Set the value of [price] column.
135
	 *
136
	 * @param      double $v new value
137
	 * @return     Product The current object (for fluent API support)
138
	 */
139
	public function setPrice($v)
140
	{
141
		if ($v !== null) {
142
			$v = (double) $v;
143
		}
144
 
145
		if ($this->price !== $v) {
146
			$this->price = $v;
147
			$this->modifiedColumns[] = ProductPeer::PRICE;
148
		}
149
 
150
		return $this;
151
	} // setPrice()
152
 
153
	/**
154
	 * Set the value of [a_primary_string] column.
155
	 *
156
	 * @param      string $v new value
157
	 * @return     Product The current object (for fluent API support)
158
	 */
159
	public function setAPrimaryString($v)
160
	{
161
		if ($v !== null) {
162
			$v = (string) $v;
163
		}
164
 
165
		if ($this->a_primary_string !== $v) {
166
			$this->a_primary_string = $v;
167
			$this->modifiedColumns[] = ProductPeer::A_PRIMARY_STRING;
168
		}
169
 
170
		return $this;
171
	} // setAPrimaryString()
172
 
173
	/**
174
	 * Indicates whether the columns in this object are only set to default values.
175
	 *
176
	 * This method can be used in conjunction with isModified() to indicate whether an object is both
177
	 * modified _and_ has some values set which are non-default.
178
	 *
179
	 * @return     boolean Whether the columns in this object are only been set with default values.
180
	 */
181
	public function hasOnlyDefaultValues()
182
	{
183
		// otherwise, everything was equal, so return TRUE
184
		return true;
185
	} // hasOnlyDefaultValues()
186
 
187
	/**
188
	 * Hydrates (populates) the object variables with values from the database resultset.
189
	 *
190
	 * An offset (0-based "start column") is specified so that objects can be hydrated
191
	 * with a subset of the columns in the resultset rows.  This is needed, for example,
192
	 * for results of JOIN queries where the resultset row includes columns from two or
193
	 * more tables.
194
	 *
195
	 * @param      array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
196
	 * @param      int $startcol 0-based offset column which indicates which restultset column to start with.
197
	 * @param      boolean $rehydrate Whether this object is being re-hydrated from the database.
198
	 * @return     int next starting column
199
	 * @throws     PropelException  - Any caught Exception will be rewrapped as a PropelException.
200
	 */
201
	public function hydrate($row, $startcol = 0, $rehydrate = false)
202
	{
203
		try {
204
 
205
			$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
206
			$this->price = ($row[$startcol + 1] !== null) ? (double) $row[$startcol + 1] : null;
207
			$this->a_primary_string = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
208
			$this->resetModified();
209
 
210
			$this->setNew(false);
211
 
212
			if ($rehydrate) {
213
				$this->ensureConsistency();
214
			}
215
 
216
			// FIXME - using NUM_COLUMNS may be clearer.
217
			return $startcol + 3; // 3 = ProductPeer::NUM_COLUMNS - ProductPeer::NUM_LAZY_LOAD_COLUMNS).
218
 
219
		} catch (Exception $e) {
220
			throw new PropelException("Error populating Product object", $e);
221
		}
222
	}
223
 
224
	/**
225
	 * Checks and repairs the internal consistency of the object.
226
	 *
227
	 * This method is executed after an already-instantiated object is re-hydrated
228
	 * from the database.  It exists to check any foreign keys to make sure that
229
	 * the objects related to the current object are correct based on foreign key.
230
	 *
231
	 * You can override this method in the stub class, but you should always invoke
232
	 * the base method from the overridden method (i.e. parent::ensureConsistency()),
233
	 * in case your model changes.
234
	 *
235
	 * @throws     PropelException
236
	 */
237
	public function ensureConsistency()
238
	{
239
 
240
	} // ensureConsistency
241
 
242
	/**
243
	 * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
244
	 *
245
	 * This will only work if the object has been saved and has a valid primary key set.
246
	 *
247
	 * @param      boolean $deep (optional) Whether to also de-associated any related objects.
248
	 * @param      PropelPDO $con (optional) The PropelPDO connection to use.
249
	 * @return     void
250
	 * @throws     PropelException - if this object is deleted, unsaved or doesn't have pk match in db
251
	 */
252
	public function reload($deep = false, PropelPDO $con = null)
253
	{
254
		if ($this->isDeleted()) {
255
			throw new PropelException("Cannot reload a deleted object.");
256
		}
257
 
258
		if ($this->isNew()) {
259
			throw new PropelException("Cannot reload an unsaved object.");
260
		}
261
 
262
		if ($con === null) {
263
			$con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
264
		}
265
 
266
		// We don't need to alter the object instance pool; we're just modifying this instance
267
		// already in the pool.
268
 
269
		$stmt = ProductPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
270
		$row = $stmt->fetch(PDO::FETCH_NUM);
271
		$stmt->closeCursor();
272
		if (!$row) {
273
			throw new PropelException('Cannot find matching row in the database to reload object values.');
274
		}
275
		$this->hydrate($row, 0, true); // rehydrate
276
 
277
		if ($deep) {  // also de-associate any related objects?
278
 
279
			$this->collTranslations = null;
280
			$this->lastTranslationCriteria = null;
281
 
282
		} // if (deep)
283
	}
284
 
285
	/**
286
	 * Removes this object from datastore and sets delete attribute.
287
	 *
288
	 * @param      PropelPDO $con
289
	 * @return     void
290
	 * @throws     PropelException
291
	 * @see        BaseObject::setDeleted()
292
	 * @see        BaseObject::isDeleted()
293
	 */
294
	public function delete(PropelPDO $con = null)
295
	{
296
		if ($this->isDeleted()) {
297
			throw new PropelException("This object has already been deleted.");
298
		}
299
 
300
		if ($con === null) {
301
			$con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
302
		}
303
 
304
		$con->beginTransaction();
305
		try {
306
			$ret = $this->preDelete($con);
307
			// symfony_behaviors behavior
308
			foreach (sfMixer::getCallables('BaseProduct:delete:pre') as $callable)
309
			{
310
			  if (call_user_func($callable, $this, $con))
311
			  {
312
			    $con->commit();
313
 
314
			    return;
315
			  }
316
			}
317
 
318
			if ($ret) {
319
				ProductPeer::doDelete($this, $con);
320
				$this->postDelete($con);
321
				// symfony_behaviors behavior
322
				foreach (sfMixer::getCallables('BaseProduct:delete:post') as $callable)
323
				{
324
				  call_user_func($callable, $this, $con);
325
				}
326
 
327
				$this->setDeleted(true);
328
				$con->commit();
329
			} else {
330
				$con->commit();
331
			}
332
		} catch (PropelException $e) {
333
			$con->rollBack();
334
			throw $e;
335
		}
336
	}
337
 
338
	/**
339
	 * Persists this object to the database.
340
	 *
341
	 * If the object is new, it inserts it; otherwise an update is performed.
342
	 * All modified related objects will also be persisted in the doSave()
343
	 * method.  This method wraps all precipitate database operations in a
344
	 * single transaction.
345
	 *
346
	 * @param      PropelPDO $con
347
	 * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
348
	 * @throws     PropelException
349
	 * @see        doSave()
350
	 */
351
	public function save(PropelPDO $con = null)
352
	{
353
		if ($this->isDeleted()) {
354
			throw new PropelException("You cannot save an object that has been deleted.");
355
		}
356
 
357
		if ($con === null) {
358
			$con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
359
		}
360
 
361
		$con->beginTransaction();
362
		$isInsert = $this->isNew();
363
		try {
364
			$ret = $this->preSave($con);
365
			// symfony_behaviors behavior
366
			foreach (sfMixer::getCallables('BaseProduct:save:pre') as $callable)
367
			{
368
			  if (is_integer($affectedRows = call_user_func($callable, $this, $con)))
369
			  {
370
			    $con->commit();
371
 
372
			    return $affectedRows;
373
			  }
374
			}
375
 
376
			if ($isInsert) {
377
				$ret = $ret && $this->preInsert($con);
378
			} else {
379
				$ret = $ret && $this->preUpdate($con);
380
			}
381
			if ($ret) {
382
				$affectedRows = $this->doSave($con);
383
				if ($isInsert) {
384
					$this->postInsert($con);
385
				} else {
386
					$this->postUpdate($con);
387
				}
388
				$this->postSave($con);
389
				// symfony_behaviors behavior
390
				foreach (sfMixer::getCallables('BaseProduct:save:post') as $callable)
391
				{
392
				  call_user_func($callable, $this, $con, $affectedRows);
393
				}
394
 
395
				ProductPeer::addInstanceToPool($this);
396
			} else {
397
				$affectedRows = 0;
398
			}
399
			$con->commit();
400
			return $affectedRows;
401
		} catch (PropelException $e) {
402
			$con->rollBack();
403
			throw $e;
404
		}
405
	}
406
 
407
	/**
408
	 * Performs the work of inserting or updating the row in the database.
409
	 *
410
	 * If the object is new, it inserts it; otherwise an update is performed.
411
	 * All related objects are also updated in this method.
412
	 *
413
	 * @param      PropelPDO $con
414
	 * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
415
	 * @throws     PropelException
416
	 * @see        save()
417
	 */
418
	protected function doSave(PropelPDO $con)
419
	{
420
		$affectedRows = 0; // initialize var to track total num of affected rows
421
		if (!$this->alreadyInSave) {
422
			$this->alreadyInSave = true;
423
 
424
			if ($this->isNew() ) {
425
				$this->modifiedColumns[] = ProductPeer::ID;
426
			}
427
 
428
			// If this object has been modified, then save it to the database.
429
			if ($this->isModified()) {
430
				if ($this->isNew()) {
431
					$pk = ProductPeer::doInsert($this, $con);
432
					$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
433
										 // should always be true here (even though technically
434
										 // BasePeer::doInsert() can insert multiple rows).
435
 
436
					$this->setId($pk);  //[IMV] update autoincrement primary key
437
 
438
					$this->setNew(false);
439
				} else {
440
					$affectedRows += ProductPeer::doUpdate($this, $con);
441
				}
442
 
443
				$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
444
			}
445
 
446
			if ($this->collTranslations !== null) {
447
				foreach ($this->collTranslations as $referrerFK) {
448
					if (!$referrerFK->isDeleted()) {
449
						$affectedRows += $referrerFK->save($con);
450
					}
451
				}
452
			}
453
 
454
			$this->alreadyInSave = false;
455
 
456
		}
457
		return $affectedRows;
458
	} // doSave()
459
 
460
	/**
461
	 * Array of ValidationFailed objects.
462
	 * @var        array ValidationFailed[]
463
	 */
464
	protected $validationFailures = array();
465
 
466
	/**
467
	 * Gets any ValidationFailed objects that resulted from last call to validate().
468
	 *
469
	 *
470
	 * @return     array ValidationFailed[]
471
	 * @see        validate()
472
	 */
473
	public function getValidationFailures()
474
	{
475
		return $this->validationFailures;
476
	}
477
 
478
	/**
479
	 * Validates the objects modified field values and all objects related to this table.
480
	 *
481
	 * If $columns is either a column name or an array of column names
482
	 * only those columns are validated.
483
	 *
484
	 * @param      mixed $columns Column name or an array of column names.
485
	 * @return     boolean Whether all columns pass validation.
486
	 * @see        doValidate()
487
	 * @see        getValidationFailures()
488
	 */
489
	public function validate($columns = null)
490
	{
491
		$res = $this->doValidate($columns);
492
		if ($res === true) {
493
			$this->validationFailures = array();
494
			return true;
495
		} else {
496
			$this->validationFailures = $res;
497
			return false;
498
		}
499
	}
500
 
501
	/**
502
	 * This function performs the validation work for complex object models.
503
	 *
504
	 * In addition to checking the current object, all related objects will
505
	 * also be validated.  If all pass then <code>true</code> is returned; otherwise
506
	 * an aggreagated array of ValidationFailed objects will be returned.
507
	 *
508
	 * @param      array $columns Array of column names to validate.
509
	 * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
510
	 */
511
	protected function doValidate($columns = null)
512
	{
513
		if (!$this->alreadyInValidation) {
514
			$this->alreadyInValidation = true;
515
			$retval = null;
516
 
517
			$failureMap = array();
518
 
519
 
520
			if (($retval = ProductPeer::doValidate($this, $columns)) !== true) {
521
				$failureMap = array_merge($failureMap, $retval);
522
			}
523
 
524
 
525
				if ($this->collTranslations !== null) {
526
					foreach ($this->collTranslations as $referrerFK) {
527
						if (!$referrerFK->validate($columns)) {
528
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
529
						}
530
					}
531
				}
532
 
533
 
534
			$this->alreadyInValidation = false;
535
		}
536
 
537
		return (!empty($failureMap) ? $failureMap : true);
538
	}
539
 
540
	/**
541
	 * Retrieves a field from the object by name passed in as a string.
542
	 *
543
	 * @param      string $name name
544
	 * @param      string $type The type of fieldname the $name is of:
545
	 *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
546
	 *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
547
	 * @return     mixed Value of field.
548
	 */
549
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
550
	{
551
		$pos = ProductPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
552
		$field = $this->getByPosition($pos);
553
		return $field;
554
	}
555
 
556
	/**
557
	 * Retrieves a field from the object by Position as specified in the xml schema.
558
	 * Zero-based.
559
	 *
560
	 * @param      int $pos position in xml schema
561
	 * @return     mixed Value of field at $pos
562
	 */
563
	public function getByPosition($pos)
564
	{
565
		switch($pos) {
566
			case 0:
567
				return $this->getId();
568
				break;
569
			case 1:
570
				return $this->getPrice();
571
				break;
572
			case 2:
573
				return $this->getAPrimaryString();
574
				break;
575
			default:
576
				return null;
577
				break;
578
		} // switch()
579
	}
580
 
581
	/**
582
	 * Exports the object as an array.
583
	 *
584
	 * You can specify the key type of the array by passing one of the class
585
	 * type constants.
586
	 *
587
	 * @param      string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
588
	 *                        BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
589
	 * @param      boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns.  Defaults to TRUE.
590
	 * @return     an associative array containing the field names (as keys) and field values
591
	 */
592
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
593
	{
594
		$keys = ProductPeer::getFieldNames($keyType);
595
		$result = array(
596
			$keys[0] => $this->getId(),
597
			$keys[1] => $this->getPrice(),
598
			$keys[2] => $this->getAPrimaryString(),
599
		);
600
		return $result;
601
	}
602
 
603
	/**
604
	 * Sets a field from the object by name passed in as a string.
605
	 *
606
	 * @param      string $name peer name
607
	 * @param      mixed $value field value
608
	 * @param      string $type The type of fieldname the $name is of:
609
	 *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
610
	 *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
611
	 * @return     void
612
	 */
613
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
614
	{
615
		$pos = ProductPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
616
		return $this->setByPosition($pos, $value);
617
	}
618
 
619
	/**
620
	 * Sets a field from the object by Position as specified in the xml schema.
621
	 * Zero-based.
622
	 *
623
	 * @param      int $pos position in xml schema
624
	 * @param      mixed $value field value
625
	 * @return     void
626
	 */
627
	public function setByPosition($pos, $value)
628
	{
629
		switch($pos) {
630
			case 0:
631
				$this->setId($value);
632
				break;
633
			case 1:
634
				$this->setPrice($value);
635
				break;
636
			case 2:
637
				$this->setAPrimaryString($value);
638
				break;
639
		} // switch()
640
	}
641
 
642
	/**
643
	 * Populates the object using an array.
644
	 *
645
	 * This is particularly useful when populating an object from one of the
646
	 * request arrays (e.g. $_POST).  This method goes through the column
647
	 * names, checking to see whether a matching key exists in populated
648
	 * array. If so the setByName() method is called for that column.
649
	 *
650
	 * You can specify the key type of the array by additionally passing one
651
	 * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
652
	 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
653
	 * The default key type is the column's phpname (e.g. 'AuthorId')
654
	 *
655
	 * @param      array  $arr     An array to populate the object from.
656
	 * @param      string $keyType The type of keys the array uses.
657
	 * @return     void
658
	 */
659
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
660
	{
661
		$keys = ProductPeer::getFieldNames($keyType);
662
 
663
		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
664
		if (array_key_exists($keys[1], $arr)) $this->setPrice($arr[$keys[1]]);
665
		if (array_key_exists($keys[2], $arr)) $this->setAPrimaryString($arr[$keys[2]]);
666
	}
667
 
668
	/**
669
	 * Build a Criteria object containing the values of all modified columns in this object.
670
	 *
671
	 * @return     Criteria The Criteria object containing all modified values.
672
	 */
673
	public function buildCriteria()
674
	{
675
		$criteria = new Criteria(ProductPeer::DATABASE_NAME);
676
 
677
		if ($this->isColumnModified(ProductPeer::ID)) $criteria->add(ProductPeer::ID, $this->id);
678
		if ($this->isColumnModified(ProductPeer::PRICE)) $criteria->add(ProductPeer::PRICE, $this->price);
679
		if ($this->isColumnModified(ProductPeer::A_PRIMARY_STRING)) $criteria->add(ProductPeer::A_PRIMARY_STRING, $this->a_primary_string);
680
 
681
		return $criteria;
682
	}
683
 
684
	/**
685
	 * Builds a Criteria object containing the primary key for this object.
686
	 *
687
	 * Unlike buildCriteria() this method includes the primary key values regardless
688
	 * of whether or not they have been modified.
689
	 *
690
	 * @return     Criteria The Criteria object containing value(s) for primary key(s).
691
	 */
692
	public function buildPkeyCriteria()
693
	{
694
		$criteria = new Criteria(ProductPeer::DATABASE_NAME);
695
 
696
		$criteria->add(ProductPeer::ID, $this->id);
697
 
698
		return $criteria;
699
	}
700
 
701
	/**
702
	 * Returns the primary key for this object (row).
703
	 * @return     int
704
	 */
705
	public function getPrimaryKey()
706
	{
707
		return $this->getId();
708
	}
709
 
710
	/**
711
	 * Generic method to set the primary key (id column).
712
	 *
713
	 * @param      int $key Primary key.
714
	 * @return     void
715
	 */
716
	public function setPrimaryKey($key)
717
	{
718
		$this->setId($key);
719
	}
720
 
721
	/**
722
	 * Sets contents of passed object to values from current object.
723
	 *
724
	 * If desired, this method can also make copies of all associated (fkey referrers)
725
	 * objects.
726
	 *
727
	 * @param      object $copyObj An object of Product (or compatible) type.
728
	 * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
729
	 * @throws     PropelException
730
	 */
731
	public function copyInto($copyObj, $deepCopy = false)
732
	{
733
 
734
		$copyObj->setPrice($this->price);
735
 
736
		$copyObj->setAPrimaryString($this->a_primary_string);
737
 
738
 
739
		if ($deepCopy) {
740
			// important: temporarily setNew(false) because this affects the behavior of
741
			// the getter/setter methods for fkey referrer objects.
742
			$copyObj->setNew(false);
743
 
744
			foreach ($this->getTranslations() as $relObj) {
745
				if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
746
					$copyObj->addTranslation($relObj->copy($deepCopy));
747
				}
748
			}
749
 
750
		} // if ($deepCopy)
751
 
752
 
753
		$copyObj->setNew(true);
754
 
755
		$copyObj->setId(NULL); // this is a auto-increment column, so set to default value
756
 
757
	}
758
 
759
	/**
760
	 * Makes a copy of this object that will be inserted as a new row in table when saved.
761
	 * It creates a new object filling in the simple attributes, but skipping any primary
762
	 * keys that are defined for the table.
763
	 *
764
	 * If desired, this method can also make copies of all associated (fkey referrers)
765
	 * objects.
766
	 *
767
	 * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
768
	 * @return     Product Clone of current object.
769
	 * @throws     PropelException
770
	 */
771
	public function copy($deepCopy = false)
772
	{
773
		// we use get_class(), because this might be a subclass
774
		$clazz = get_class($this);
775
		$copyObj = new $clazz();
776
		$this->copyInto($copyObj, $deepCopy);
777
		return $copyObj;
778
	}
779
 
780
	/**
781
	 * Returns a peer instance associated with this om.
782
	 *
783
	 * Since Peer classes are not to have any instance attributes, this method returns the
784
	 * same instance for all member of this class. The method could therefore
785
	 * be static, but this would prevent one from overriding the behavior.
786
	 *
787
	 * @return     ProductPeer
788
	 */
789
	public function getPeer()
790
	{
791
		if (self::$peer === null) {
792
			self::$peer = new ProductPeer();
793
		}
794
		return self::$peer;
795
	}
796
 
797
	/**
798
	 * Clears out the collTranslations collection (array).
799
	 *
800
	 * This does not modify the database; however, it will remove any associated objects, causing
801
	 * them to be refetched by subsequent calls to accessor method.
802
	 *
803
	 * @return     void
804
	 * @see        addTranslations()
805
	 */
806
	public function clearTranslations()
807
	{
808
		$this->collTranslations = null; // important to set this to NULL since that means it is uninitialized
809
	}
810
 
811
	/**
812
	 * Initializes the collTranslations collection (array).
813
	 *
814
	 * By default this just sets the collTranslations collection to an empty array (like clearcollTranslations());
815
	 * however, you may wish to override this method in your stub class to provide setting appropriate
816
	 * to your application -- for example, setting the initial array to the values stored in database.
817
	 *
818
	 * @return     void
819
	 */
820
	public function initTranslations()
821
	{
822
		$this->collTranslations = array();
823
	}
824
 
825
	/**
826
	 * Gets an array of ProductI18n objects which contain a foreign key that references this object.
827
	 *
828
	 * If this collection has already been initialized with an identical Criteria, it returns the collection.
829
	 * Otherwise if this Product has previously been saved, it will retrieve
830
	 * related Translations from storage. If this Product is new, it will return
831
	 * an empty collection or the current collection, the criteria is ignored on a new object.
832
	 *
833
	 * @param      PropelPDO $con
834
	 * @param      Criteria $criteria
835
	 * @return     array ProductI18n[]
836
	 * @throws     PropelException
837
	 */
838
	public function getTranslations($criteria = null, PropelPDO $con = null)
839
	{
840
		if ($criteria === null) {
841
			$criteria = new Criteria(ProductPeer::DATABASE_NAME);
842
		}
843
		elseif ($criteria instanceof Criteria)
844
		{
845
			$criteria = clone $criteria;
846
		}
847
 
848
		if ($this->collTranslations === null) {
849
			if ($this->isNew()) {
850
			   $this->collTranslations = array();
851
			} else {
852
 
853
				$criteria->add(ProductI18nPeer::ID, $this->id);
854
 
855
				ProductI18nPeer::addSelectColumns($criteria);
856
				$this->collTranslations = ProductI18nPeer::doSelect($criteria, $con);
857
			}
858
		} else {
859
			// criteria has no effect for a new object
860
			if (!$this->isNew()) {
861
				// the following code is to determine if a new query is
862
				// called for.  If the criteria is the same as the last
863
				// one, just return the collection.
864
 
865
 
866
				$criteria->add(ProductI18nPeer::ID, $this->id);
867
 
868
				ProductI18nPeer::addSelectColumns($criteria);
869
				if (!isset($this->lastTranslationCriteria) || !$this->lastTranslationCriteria->equals($criteria)) {
870
					$this->collTranslations = ProductI18nPeer::doSelect($criteria, $con);
871
				}
872
			}
873
		}
874
		$this->lastTranslationCriteria = $criteria;
875
		return $this->collTranslations;
876
	}
877
 
878
	/**
879
	 * Returns the number of related ProductI18n objects.
880
	 *
881
	 * @param      Criteria $criteria
882
	 * @param      boolean $distinct
883
	 * @param      PropelPDO $con
884
	 * @return     int Count of related ProductI18n objects.
885
	 * @throws     PropelException
886
	 */
887
	public function countTranslations(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
888
	{
889
		if ($criteria === null) {
890
			$criteria = new Criteria(ProductPeer::DATABASE_NAME);
891
		} else {
892
			$criteria = clone $criteria;
893
		}
894
 
895
		if ($distinct) {
896
			$criteria->setDistinct();
897
		}
898
 
899
		$count = null;
900
 
901
		if ($this->collTranslations === null) {
902
			if ($this->isNew()) {
903
				$count = 0;
904
			} else {
905
 
906
				$criteria->add(ProductI18nPeer::ID, $this->id);
907
 
908
				$count = ProductI18nPeer::doCount($criteria, false, $con);
909
			}
910
		} else {
911
			// criteria has no effect for a new object
912
			if (!$this->isNew()) {
913
				// the following code is to determine if a new query is
914
				// called for.  If the criteria is the same as the last
915
				// one, just return count of the collection.
916
 
917
 
918
				$criteria->add(ProductI18nPeer::ID, $this->id);
919
 
920
				if (!isset($this->lastTranslationCriteria) || !$this->lastTranslationCriteria->equals($criteria)) {
921
					$count = ProductI18nPeer::doCount($criteria, false, $con);
922
				} else {
923
					$count = count($this->collTranslations);
924
				}
925
			} else {
926
				$count = count($this->collTranslations);
927
			}
928
		}
929
		return $count;
930
	}
931
 
932
	/**
933
	 * Method called to associate a ProductI18n object to this object
934
	 * through the ProductI18n foreign key attribute.
935
	 *
936
	 * @param      ProductI18n $l ProductI18n
937
	 * @return     void
938
	 * @throws     PropelException
939
	 */
940
	public function addTranslation(ProductI18n $l)
941
	{
942
		if ($this->collTranslations === null) {
943
			$this->initTranslations();
944
		}
945
		if (!in_array($l, $this->collTranslations, true)) { // only add it if the **same** object is not already associated
946
			array_push($this->collTranslations, $l);
947
			$l->setProduct($this);
948
		}
949
	}
950
 
951
	/**
952
	 * Resets all collections of referencing foreign keys.
953
	 *
954
	 * This method is a user-space workaround for PHP's inability to garbage collect objects
955
	 * with circular references.  This is currently necessary when using Propel in certain
956
	 * daemon or large-volumne/high-memory operations.
957
	 *
958
	 * @param      boolean $deep Whether to also clear the references on all associated objects.
959
	 */
960
	public function clearAllReferences($deep = false)
961
	{
962
		if ($deep) {
963
			if ($this->collTranslations) {
964
				foreach ((array) $this->collTranslations as $o) {
965
					$o->clearAllReferences($deep);
966
				}
967
			}
968
		} // if ($deep)
969
 
970
		$this->collTranslations = null;
971
	}
972
 
973
	// symfony_behaviors behavior
974
 
975
	/**
976
	 * Calls methods defined via {@link sfMixer}.
977
	 */
978
	public function __call($method, $arguments)
979
	{
980
	  if (!$callable = sfMixer::getCallable('BaseProduct:'.$method))
981
	  {
982
	    throw new sfException(sprintf('Call to undefined method BaseProduct::%s', $method));
983
	  }
984
 
985
	  array_unshift($arguments, $this);
986
 
987
	  return call_user_func_array($callable, $arguments);
988
	}
989
 
990
	// symfony_i18n behavior
991
 
992
	/**
993
	 * Returns the culture.
994
	 *
995
	 * @return string The culture
996
	 */
997
	public function getCulture()
998
	{
999
	  return $this->culture;
1000
	}
1001
 
1002
	/**
1003
	 * Sets the culture.
1004
	 *
1005
	 * @param string  The culture to set
1006
	 *
1007
	 * @return Product
1008
	 */
1009
	public function setCulture($culture)
1010
	{
1011
	  $this->culture = $culture;
1012
	  return $this;
1013
	}
1014
 
1015
	/**
1016
	 * Returns the "name" value from the current {@link ProductI18n}.
1017
	 */
1018
	public function getName($culture = null)
1019
	{
1020
	  return $this->getCurrentTranslation($culture)->getName();
1021
	}
1022
 
1023
	/**
1024
	 * Sets the "name" value of the current {@link ProductI18n}.
1025
	 *
1026
	 * @return Product
1027
	 */
1028
	public function setName($value, $culture = null)
1029
	{
1030
	  $this->getCurrentTranslation($culture)->setName($value);
1031
	  return $this;
1032
	}
1033
 
1034
	/**
1035
	 * Returns the current translation.
1036
	 *
1037
	 * @return ProductI18n
1038
	 */
1039
	public function getCurrentTranslation($culture = null)
1040
	{
1041
	  if (null === $culture)
1042
	  {
1043
	    $culture = null === $this->culture ? sfPropel::getDefaultCulture() : $this->culture;
1044
	  }
1045
 
1046
	  if (!isset($this->current_i18n[$culture]))
1047
	  {
1048
	    $object = $this->isNew() ? null : ProductI18nPeer::retrieveByPK($this->getPrimaryKey(), $culture);
1049
	    if ($object)
1050
	    {
1051
	      $this->setTranslationForCulture($object, $culture);
1052
	    }
1053
	    else
1054
	    {
1055
	      $this->setTranslationForCulture(new ProductI18n(), $culture);
1056
	      $this->current_i18n[$culture]->setCulture($culture);
1057
	    }
1058
	  }
1059
 
1060
	  return $this->current_i18n[$culture];
1061
	}
1062
 
1063
	/**
1064
	 * Sets the translation object for a culture.
1065
	 */
1066
	public function setTranslationForCulture(ProductI18n $object, $culture)
1067
	{
1068
	  $this->current_i18n[$culture] = $object;
1069
	  $this->addTranslation($object);
1070
	}
1071
 
1072
	/**
1073
	 * Return the string representation of this object
1074
	 *
1075
	 * @return string The value of the 'a_primary_string' column
1076
	 */
1077
  public function __toString()
1078
  {
1079
    return (string) $this->getAPrimaryString();
1080
  }
1081
 
1082
} // BaseProduct