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