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 'attachment' table.
5
 *
6
 *
7
 *
8
 * This class was autogenerated by Propel 1.4.2 on:
9
 *
10
 * Fri Aug  5 09:39:39 2011
11
 *
12
 * @package    lib.model.om
13
 */
14
abstract class BaseAttachment 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        AttachmentPeer
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 article_id field.
33
	 * @var        int
34
	 */
35
	protected $article_id;
36
 
37
	/**
38
	 * The value for the name field.
39
	 * @var        string
40
	 */
41
	protected $name;
42
 
43
	/**
44
	 * The value for the file field.
45
	 * @var        string
46
	 */
47
	protected $file;
48
 
49
	/**
50
	 * @var        Article
51
	 */
52
	protected $aArticle;
53
 
54
	/**
55
	 * Flag to prevent endless save loop, if this object is referenced
56
	 * by another object which falls in this transaction.
57
	 * @var        boolean
58
	 */
59
	protected $alreadyInSave = false;
60
 
61
	/**
62
	 * Flag to prevent endless validation loop, if this object is referenced
63
	 * by another object which falls in this transaction.
64
	 * @var        boolean
65
	 */
66
	protected $alreadyInValidation = false;
67
 
68
	// symfony behavior
69
 
70
	const PEER = 'AttachmentPeer';
71
 
72
	/**
73
	 * Get the [id] column value.
74
	 *
75
	 * @return     int
76
	 */
77
	public function getId()
78
	{
79
		return $this->id;
80
	}
81
 
82
	/**
83
	 * Get the [article_id] column value.
84
	 *
85
	 * @return     int
86
	 */
87
	public function getArticleId()
88
	{
89
		return $this->article_id;
90
	}
91
 
92
	/**
93
	 * Get the [name] column value.
94
	 *
95
	 * @return     string
96
	 */
97
	public function getName()
98
	{
99
		return $this->name;
100
	}
101
 
102
	/**
103
	 * Get the [file] column value.
104
	 *
105
	 * @return     string
106
	 */
107
	public function getFile()
108
	{
109
		return $this->file;
110
	}
111
 
112
	/**
113
	 * Set the value of [id] column.
114
	 *
115
	 * @param      int $v new value
116
	 * @return     Attachment The current object (for fluent API support)
117
	 */
118
	public function setId($v)
119
	{
120
		if ($v !== null) {
121
			$v = (int) $v;
122
		}
123
 
124
		if ($this->id !== $v) {
125
			$this->id = $v;
126
			$this->modifiedColumns[] = AttachmentPeer::ID;
127
		}
128
 
129
		return $this;
130
	} // setId()
131
 
132
	/**
133
	 * Set the value of [article_id] column.
134
	 *
135
	 * @param      int $v new value
136
	 * @return     Attachment The current object (for fluent API support)
137
	 */
138
	public function setArticleId($v)
139
	{
140
		if ($v !== null) {
141
			$v = (int) $v;
142
		}
143
 
144
		if ($this->article_id !== $v) {
145
			$this->article_id = $v;
146
			$this->modifiedColumns[] = AttachmentPeer::ARTICLE_ID;
147
		}
148
 
149
		if ($this->aArticle !== null && $this->aArticle->getId() !== $v) {
150
			$this->aArticle = null;
151
		}
152
 
153
		return $this;
154
	} // setArticleId()
155
 
156
	/**
157
	 * Set the value of [name] column.
158
	 *
159
	 * @param      string $v new value
160
	 * @return     Attachment The current object (for fluent API support)
161
	 */
162
	public function setName($v)
163
	{
164
		if ($v !== null) {
165
			$v = (string) $v;
166
		}
167
 
168
		if ($this->name !== $v) {
169
			$this->name = $v;
170
			$this->modifiedColumns[] = AttachmentPeer::NAME;
171
		}
172
 
173
		return $this;
174
	} // setName()
175
 
176
	/**
177
	 * Set the value of [file] column.
178
	 *
179
	 * @param      string $v new value
180
	 * @return     Attachment The current object (for fluent API support)
181
	 */
182
	public function setFile($v)
183
	{
184
		if ($v !== null) {
185
			$v = (string) $v;
186
		}
187
 
188
		if ($this->file !== $v) {
189
			$this->file = $v;
190
			$this->modifiedColumns[] = AttachmentPeer::FILE;
191
		}
192
 
193
		return $this;
194
	} // setFile()
195
 
196
	/**
197
	 * Indicates whether the columns in this object are only set to default values.
198
	 *
199
	 * This method can be used in conjunction with isModified() to indicate whether an object is both
200
	 * modified _and_ has some values set which are non-default.
201
	 *
202
	 * @return     boolean Whether the columns in this object are only been set with default values.
203
	 */
204
	public function hasOnlyDefaultValues()
205
	{
206
		// otherwise, everything was equal, so return TRUE
207
		return true;
208
	} // hasOnlyDefaultValues()
209
 
210
	/**
211
	 * Hydrates (populates) the object variables with values from the database resultset.
212
	 *
213
	 * An offset (0-based "start column") is specified so that objects can be hydrated
214
	 * with a subset of the columns in the resultset rows.  This is needed, for example,
215
	 * for results of JOIN queries where the resultset row includes columns from two or
216
	 * more tables.
217
	 *
218
	 * @param      array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
219
	 * @param      int $startcol 0-based offset column which indicates which restultset column to start with.
220
	 * @param      boolean $rehydrate Whether this object is being re-hydrated from the database.
221
	 * @return     int next starting column
222
	 * @throws     PropelException  - Any caught Exception will be rewrapped as a PropelException.
223
	 */
224
	public function hydrate($row, $startcol = 0, $rehydrate = false)
225
	{
226
		try {
227
 
228
			$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
229
			$this->article_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
230
			$this->name = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
231
			$this->file = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
232
			$this->resetModified();
233
 
234
			$this->setNew(false);
235
 
236
			if ($rehydrate) {
237
				$this->ensureConsistency();
238
			}
239
 
240
			// FIXME - using NUM_COLUMNS may be clearer.
241
			return $startcol + 4; // 4 = AttachmentPeer::NUM_COLUMNS - AttachmentPeer::NUM_LAZY_LOAD_COLUMNS).
242
 
243
		} catch (Exception $e) {
244
			throw new PropelException("Error populating Attachment object", $e);
245
		}
246
	}
247
 
248
	/**
249
	 * Checks and repairs the internal consistency of the object.
250
	 *
251
	 * This method is executed after an already-instantiated object is re-hydrated
252
	 * from the database.  It exists to check any foreign keys to make sure that
253
	 * the objects related to the current object are correct based on foreign key.
254
	 *
255
	 * You can override this method in the stub class, but you should always invoke
256
	 * the base method from the overridden method (i.e. parent::ensureConsistency()),
257
	 * in case your model changes.
258
	 *
259
	 * @throws     PropelException
260
	 */
261
	public function ensureConsistency()
262
	{
263
 
264
		if ($this->aArticle !== null && $this->article_id !== $this->aArticle->getId()) {
265
			$this->aArticle = null;
266
		}
267
	} // ensureConsistency
268
 
269
	/**
270
	 * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
271
	 *
272
	 * This will only work if the object has been saved and has a valid primary key set.
273
	 *
274
	 * @param      boolean $deep (optional) Whether to also de-associated any related objects.
275
	 * @param      PropelPDO $con (optional) The PropelPDO connection to use.
276
	 * @return     void
277
	 * @throws     PropelException - if this object is deleted, unsaved or doesn't have pk match in db
278
	 */
279
	public function reload($deep = false, PropelPDO $con = null)
280
	{
281
		if ($this->isDeleted()) {
282
			throw new PropelException("Cannot reload a deleted object.");
283
		}
284
 
285
		if ($this->isNew()) {
286
			throw new PropelException("Cannot reload an unsaved object.");
287
		}
288
 
289
		if ($con === null) {
290
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
291
		}
292
 
293
		// We don't need to alter the object instance pool; we're just modifying this instance
294
		// already in the pool.
295
 
296
		$stmt = AttachmentPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
297
		$row = $stmt->fetch(PDO::FETCH_NUM);
298
		$stmt->closeCursor();
299
		if (!$row) {
300
			throw new PropelException('Cannot find matching row in the database to reload object values.');
301
		}
302
		$this->hydrate($row, 0, true); // rehydrate
303
 
304
		if ($deep) {  // also de-associate any related objects?
305
 
306
			$this->aArticle = null;
307
		} // if (deep)
308
	}
309
 
310
	/**
311
	 * Removes this object from datastore and sets delete attribute.
312
	 *
313
	 * @param      PropelPDO $con
314
	 * @return     void
315
	 * @throws     PropelException
316
	 * @see        BaseObject::setDeleted()
317
	 * @see        BaseObject::isDeleted()
318
	 */
319
	public function delete(PropelPDO $con = null)
320
	{
321
		if ($this->isDeleted()) {
322
			throw new PropelException("This object has already been deleted.");
323
		}
324
 
325
		if ($con === null) {
326
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
327
		}
328
 
329
		$con->beginTransaction();
330
		try {
331
			$ret = $this->preDelete($con);
332
			// symfony_behaviors behavior
333
			foreach (sfMixer::getCallables('BaseAttachment:delete:pre') as $callable)
334
			{
335
			  if (call_user_func($callable, $this, $con))
336
			  {
337
			    $con->commit();
338
 
339
			    return;
340
			  }
341
			}
342
 
343
			if ($ret) {
344
				AttachmentPeer::doDelete($this, $con);
345
				$this->postDelete($con);
346
				// symfony_behaviors behavior
347
				foreach (sfMixer::getCallables('BaseAttachment:delete:post') as $callable)
348
				{
349
				  call_user_func($callable, $this, $con);
350
				}
351
 
352
				$this->setDeleted(true);
353
				$con->commit();
354
			} else {
355
				$con->commit();
356
			}
357
		} catch (PropelException $e) {
358
			$con->rollBack();
359
			throw $e;
360
		}
361
	}
362
 
363
	/**
364
	 * Persists this object to the database.
365
	 *
366
	 * If the object is new, it inserts it; otherwise an update is performed.
367
	 * All modified related objects will also be persisted in the doSave()
368
	 * method.  This method wraps all precipitate database operations in a
369
	 * single transaction.
370
	 *
371
	 * @param      PropelPDO $con
372
	 * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
373
	 * @throws     PropelException
374
	 * @see        doSave()
375
	 */
376
	public function save(PropelPDO $con = null)
377
	{
378
		if ($this->isDeleted()) {
379
			throw new PropelException("You cannot save an object that has been deleted.");
380
		}
381
 
382
		if ($con === null) {
383
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
384
		}
385
 
386
		$con->beginTransaction();
387
		$isInsert = $this->isNew();
388
		try {
389
			$ret = $this->preSave($con);
390
			// symfony_behaviors behavior
391
			foreach (sfMixer::getCallables('BaseAttachment:save:pre') as $callable)
392
			{
393
			  if (is_integer($affectedRows = call_user_func($callable, $this, $con)))
394
			  {
395
			    $con->commit();
396
 
397
			    return $affectedRows;
398
			  }
399
			}
400
 
401
			if ($isInsert) {
402
				$ret = $ret && $this->preInsert($con);
403
			} else {
404
				$ret = $ret && $this->preUpdate($con);
405
			}
406
			if ($ret) {
407
				$affectedRows = $this->doSave($con);
408
				if ($isInsert) {
409
					$this->postInsert($con);
410
				} else {
411
					$this->postUpdate($con);
412
				}
413
				$this->postSave($con);
414
				// symfony_behaviors behavior
415
				foreach (sfMixer::getCallables('BaseAttachment:save:post') as $callable)
416
				{
417
				  call_user_func($callable, $this, $con, $affectedRows);
418
				}
419
 
420
				AttachmentPeer::addInstanceToPool($this);
421
			} else {
422
				$affectedRows = 0;
423
			}
424
			$con->commit();
425
			return $affectedRows;
426
		} catch (PropelException $e) {
427
			$con->rollBack();
428
			throw $e;
429
		}
430
	}
431
 
432
	/**
433
	 * Performs the work of inserting or updating the row in the database.
434
	 *
435
	 * If the object is new, it inserts it; otherwise an update is performed.
436
	 * All related objects are also updated in this method.
437
	 *
438
	 * @param      PropelPDO $con
439
	 * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
440
	 * @throws     PropelException
441
	 * @see        save()
442
	 */
443
	protected function doSave(PropelPDO $con)
444
	{
445
		$affectedRows = 0; // initialize var to track total num of affected rows
446
		if (!$this->alreadyInSave) {
447
			$this->alreadyInSave = true;
448
 
449
			// We call the save method on the following object(s) if they
450
			// were passed to this object by their coresponding set
451
			// method.  This object relates to these object(s) by a
452
			// foreign key reference.
453
 
454
			if ($this->aArticle !== null) {
455
				if ($this->aArticle->isModified() || $this->aArticle->isNew()) {
456
					$affectedRows += $this->aArticle->save($con);
457
				}
458
				$this->setArticle($this->aArticle);
459
			}
460
 
461
			if ($this->isNew() ) {
462
				$this->modifiedColumns[] = AttachmentPeer::ID;
463
			}
464
 
465
			// If this object has been modified, then save it to the database.
466
			if ($this->isModified()) {
467
				if ($this->isNew()) {
468
					$pk = AttachmentPeer::doInsert($this, $con);
469
					$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
470
										 // should always be true here (even though technically
471
										 // BasePeer::doInsert() can insert multiple rows).
472
 
473
					$this->setId($pk);  //[IMV] update autoincrement primary key
474
 
475
					$this->setNew(false);
476
				} else {
477
					$affectedRows += AttachmentPeer::doUpdate($this, $con);
478
				}
479
 
480
				$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
481
			}
482
 
483
			$this->alreadyInSave = false;
484
 
485
		}
486
		return $affectedRows;
487
	} // doSave()
488
 
489
	/**
490
	 * Array of ValidationFailed objects.
491
	 * @var        array ValidationFailed[]
492
	 */
493
	protected $validationFailures = array();
494
 
495
	/**
496
	 * Gets any ValidationFailed objects that resulted from last call to validate().
497
	 *
498
	 *
499
	 * @return     array ValidationFailed[]
500
	 * @see        validate()
501
	 */
502
	public function getValidationFailures()
503
	{
504
		return $this->validationFailures;
505
	}
506
 
507
	/**
508
	 * Validates the objects modified field values and all objects related to this table.
509
	 *
510
	 * If $columns is either a column name or an array of column names
511
	 * only those columns are validated.
512
	 *
513
	 * @param      mixed $columns Column name or an array of column names.
514
	 * @return     boolean Whether all columns pass validation.
515
	 * @see        doValidate()
516
	 * @see        getValidationFailures()
517
	 */
518
	public function validate($columns = null)
519
	{
520
		$res = $this->doValidate($columns);
521
		if ($res === true) {
522
			$this->validationFailures = array();
523
			return true;
524
		} else {
525
			$this->validationFailures = $res;
526
			return false;
527
		}
528
	}
529
 
530
	/**
531
	 * This function performs the validation work for complex object models.
532
	 *
533
	 * In addition to checking the current object, all related objects will
534
	 * also be validated.  If all pass then <code>true</code> is returned; otherwise
535
	 * an aggreagated array of ValidationFailed objects will be returned.
536
	 *
537
	 * @param      array $columns Array of column names to validate.
538
	 * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
539
	 */
540
	protected function doValidate($columns = null)
541
	{
542
		if (!$this->alreadyInValidation) {
543
			$this->alreadyInValidation = true;
544
			$retval = null;
545
 
546
			$failureMap = array();
547
 
548
 
549
			// We call the validate method on the following object(s) if they
550
			// were passed to this object by their coresponding set
551
			// method.  This object relates to these object(s) by a
552
			// foreign key reference.
553
 
554
			if ($this->aArticle !== null) {
555
				if (!$this->aArticle->validate($columns)) {
556
					$failureMap = array_merge($failureMap, $this->aArticle->getValidationFailures());
557
				}
558
			}
559
 
560
 
561
			if (($retval = AttachmentPeer::doValidate($this, $columns)) !== true) {
562
				$failureMap = array_merge($failureMap, $retval);
563
			}
564
 
565
 
566
 
567
			$this->alreadyInValidation = false;
568
		}
569
 
570
		return (!empty($failureMap) ? $failureMap : true);
571
	}
572
 
573
	/**
574
	 * Retrieves a field from the object by name passed in as a string.
575
	 *
576
	 * @param      string $name name
577
	 * @param      string $type The type of fieldname the $name is of:
578
	 *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
579
	 *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
580
	 * @return     mixed Value of field.
581
	 */
582
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
583
	{
584
		$pos = AttachmentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
585
		$field = $this->getByPosition($pos);
586
		return $field;
587
	}
588
 
589
	/**
590
	 * Retrieves a field from the object by Position as specified in the xml schema.
591
	 * Zero-based.
592
	 *
593
	 * @param      int $pos position in xml schema
594
	 * @return     mixed Value of field at $pos
595
	 */
596
	public function getByPosition($pos)
597
	{
598
		switch($pos) {
599
			case 0:
600
				return $this->getId();
601
				break;
602
			case 1:
603
				return $this->getArticleId();
604
				break;
605
			case 2:
606
				return $this->getName();
607
				break;
608
			case 3:
609
				return $this->getFile();
610
				break;
611
			default:
612
				return null;
613
				break;
614
		} // switch()
615
	}
616
 
617
	/**
618
	 * Exports the object as an array.
619
	 *
620
	 * You can specify the key type of the array by passing one of the class
621
	 * type constants.
622
	 *
623
	 * @param      string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
624
	 *                        BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
625
	 * @param      boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns.  Defaults to TRUE.
626
	 * @return     an associative array containing the field names (as keys) and field values
627
	 */
628
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
629
	{
630
		$keys = AttachmentPeer::getFieldNames($keyType);
631
		$result = array(
632
			$keys[0] => $this->getId(),
633
			$keys[1] => $this->getArticleId(),
634
			$keys[2] => $this->getName(),
635
			$keys[3] => $this->getFile(),
636
		);
637
		return $result;
638
	}
639
 
640
	/**
641
	 * Sets a field from the object by name passed in as a string.
642
	 *
643
	 * @param      string $name peer name
644
	 * @param      mixed $value field value
645
	 * @param      string $type The type of fieldname the $name is of:
646
	 *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
647
	 *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
648
	 * @return     void
649
	 */
650
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
651
	{
652
		$pos = AttachmentPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
653
		return $this->setByPosition($pos, $value);
654
	}
655
 
656
	/**
657
	 * Sets a field from the object by Position as specified in the xml schema.
658
	 * Zero-based.
659
	 *
660
	 * @param      int $pos position in xml schema
661
	 * @param      mixed $value field value
662
	 * @return     void
663
	 */
664
	public function setByPosition($pos, $value)
665
	{
666
		switch($pos) {
667
			case 0:
668
				$this->setId($value);
669
				break;
670
			case 1:
671
				$this->setArticleId($value);
672
				break;
673
			case 2:
674
				$this->setName($value);
675
				break;
676
			case 3:
677
				$this->setFile($value);
678
				break;
679
		} // switch()
680
	}
681
 
682
	/**
683
	 * Populates the object using an array.
684
	 *
685
	 * This is particularly useful when populating an object from one of the
686
	 * request arrays (e.g. $_POST).  This method goes through the column
687
	 * names, checking to see whether a matching key exists in populated
688
	 * array. If so the setByName() method is called for that column.
689
	 *
690
	 * You can specify the key type of the array by additionally passing one
691
	 * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
692
	 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
693
	 * The default key type is the column's phpname (e.g. 'AuthorId')
694
	 *
695
	 * @param      array  $arr     An array to populate the object from.
696
	 * @param      string $keyType The type of keys the array uses.
697
	 * @return     void
698
	 */
699
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
700
	{
701
		$keys = AttachmentPeer::getFieldNames($keyType);
702
 
703
		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
704
		if (array_key_exists($keys[1], $arr)) $this->setArticleId($arr[$keys[1]]);
705
		if (array_key_exists($keys[2], $arr)) $this->setName($arr[$keys[2]]);
706
		if (array_key_exists($keys[3], $arr)) $this->setFile($arr[$keys[3]]);
707
	}
708
 
709
	/**
710
	 * Build a Criteria object containing the values of all modified columns in this object.
711
	 *
712
	 * @return     Criteria The Criteria object containing all modified values.
713
	 */
714
	public function buildCriteria()
715
	{
716
		$criteria = new Criteria(AttachmentPeer::DATABASE_NAME);
717
 
718
		if ($this->isColumnModified(AttachmentPeer::ID)) $criteria->add(AttachmentPeer::ID, $this->id);
719
		if ($this->isColumnModified(AttachmentPeer::ARTICLE_ID)) $criteria->add(AttachmentPeer::ARTICLE_ID, $this->article_id);
720
		if ($this->isColumnModified(AttachmentPeer::NAME)) $criteria->add(AttachmentPeer::NAME, $this->name);
721
		if ($this->isColumnModified(AttachmentPeer::FILE)) $criteria->add(AttachmentPeer::FILE, $this->file);
722
 
723
		return $criteria;
724
	}
725
 
726
	/**
727
	 * Builds a Criteria object containing the primary key for this object.
728
	 *
729
	 * Unlike buildCriteria() this method includes the primary key values regardless
730
	 * of whether or not they have been modified.
731
	 *
732
	 * @return     Criteria The Criteria object containing value(s) for primary key(s).
733
	 */
734
	public function buildPkeyCriteria()
735
	{
736
		$criteria = new Criteria(AttachmentPeer::DATABASE_NAME);
737
 
738
		$criteria->add(AttachmentPeer::ID, $this->id);
739
 
740
		return $criteria;
741
	}
742
 
743
	/**
744
	 * Returns the primary key for this object (row).
745
	 * @return     int
746
	 */
747
	public function getPrimaryKey()
748
	{
749
		return $this->getId();
750
	}
751
 
752
	/**
753
	 * Generic method to set the primary key (id column).
754
	 *
755
	 * @param      int $key Primary key.
756
	 * @return     void
757
	 */
758
	public function setPrimaryKey($key)
759
	{
760
		$this->setId($key);
761
	}
762
 
763
	/**
764
	 * Sets contents of passed object to values from current object.
765
	 *
766
	 * If desired, this method can also make copies of all associated (fkey referrers)
767
	 * objects.
768
	 *
769
	 * @param      object $copyObj An object of Attachment (or compatible) type.
770
	 * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
771
	 * @throws     PropelException
772
	 */
773
	public function copyInto($copyObj, $deepCopy = false)
774
	{
775
 
776
		$copyObj->setArticleId($this->article_id);
777
 
778
		$copyObj->setName($this->name);
779
 
780
		$copyObj->setFile($this->file);
781
 
782
 
783
		$copyObj->setNew(true);
784
 
785
		$copyObj->setId(NULL); // this is a auto-increment column, so set to default value
786
 
787
	}
788
 
789
	/**
790
	 * Makes a copy of this object that will be inserted as a new row in table when saved.
791
	 * It creates a new object filling in the simple attributes, but skipping any primary
792
	 * keys that are defined for the table.
793
	 *
794
	 * If desired, this method can also make copies of all associated (fkey referrers)
795
	 * objects.
796
	 *
797
	 * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
798
	 * @return     Attachment Clone of current object.
799
	 * @throws     PropelException
800
	 */
801
	public function copy($deepCopy = false)
802
	{
803
		// we use get_class(), because this might be a subclass
804
		$clazz = get_class($this);
805
		$copyObj = new $clazz();
806
		$this->copyInto($copyObj, $deepCopy);
807
		return $copyObj;
808
	}
809
 
810
	/**
811
	 * Returns a peer instance associated with this om.
812
	 *
813
	 * Since Peer classes are not to have any instance attributes, this method returns the
814
	 * same instance for all member of this class. The method could therefore
815
	 * be static, but this would prevent one from overriding the behavior.
816
	 *
817
	 * @return     AttachmentPeer
818
	 */
819
	public function getPeer()
820
	{
821
		if (self::$peer === null) {
822
			self::$peer = new AttachmentPeer();
823
		}
824
		return self::$peer;
825
	}
826
 
827
	/**
828
	 * Declares an association between this object and a Article object.
829
	 *
830
	 * @param      Article $v
831
	 * @return     Attachment The current object (for fluent API support)
832
	 * @throws     PropelException
833
	 */
834
	public function setArticle(Article $v = null)
835
	{
836
		if ($v === null) {
837
			$this->setArticleId(NULL);
838
		} else {
839
			$this->setArticleId($v->getId());
840
		}
841
 
842
		$this->aArticle = $v;
843
 
844
		// Add binding for other direction of this n:n relationship.
845
		// If this object has already been added to the Article object, it will not be re-added.
846
		if ($v !== null) {
847
			$v->addAttachment($this);
848
		}
849
 
850
		return $this;
851
	}
852
 
853
 
854
	/**
855
	 * Get the associated Article object
856
	 *
857
	 * @param      PropelPDO Optional Connection object.
858
	 * @return     Article The associated Article object.
859
	 * @throws     PropelException
860
	 */
861
	public function getArticle(PropelPDO $con = null)
862
	{
863
		if ($this->aArticle === null && ($this->article_id !== null)) {
864
			$this->aArticle = ArticlePeer::retrieveByPk($this->article_id);
865
			/* The following can be used additionally to
866
			   guarantee the related object contains a reference
867
			   to this object.  This level of coupling may, however, be
868
			   undesirable since it could result in an only partially populated collection
869
			   in the referenced object.
870
			   $this->aArticle->addAttachments($this);
871
			 */
872
		}
873
		return $this->aArticle;
874
	}
875
 
876
	/**
877
	 * Resets all collections of referencing foreign keys.
878
	 *
879
	 * This method is a user-space workaround for PHP's inability to garbage collect objects
880
	 * with circular references.  This is currently necessary when using Propel in certain
881
	 * daemon or large-volumne/high-memory operations.
882
	 *
883
	 * @param      boolean $deep Whether to also clear the references on all associated objects.
884
	 */
885
	public function clearAllReferences($deep = false)
886
	{
887
		if ($deep) {
888
		} // if ($deep)
889
 
890
			$this->aArticle = null;
891
	}
892
 
893
	// symfony_behaviors behavior
894
 
895
	/**
896
	 * Calls methods defined via {@link sfMixer}.
897
	 */
898
	public function __call($method, $arguments)
899
	{
900
	  if (!$callable = sfMixer::getCallable('BaseAttachment:'.$method))
901
	  {
902
	    throw new sfException(sprintf('Call to undefined method BaseAttachment::%s', $method));
903
	  }
904
 
905
	  array_unshift($arguments, $this);
906
 
907
	  return call_user_func_array($callable, $arguments);
908
	}
909
 
910
} // BaseAttachment