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 static class for performing query and update operations on the 'attachment' table.
5
 *
6
 *
7
 *
8
 * This class was autogenerated by Propel 1.4.2 on:
9
 *
10
 * Fri Aug  5 09:39:38 2011
11
 *
12
 * @package    lib.model.om
13
 */
14
abstract class BaseAttachmentPeer {
15
 
16
	/** the default database name for this class */
17
	const DATABASE_NAME = 'propel';
18
 
19
	/** the table name for this class */
20
	const TABLE_NAME = 'attachment';
21
 
22
	/** the related Propel class for this table */
23
	const OM_CLASS = 'Attachment';
24
 
25
	/** A class that can be returned by this peer. */
26
	const CLASS_DEFAULT = 'lib.model.Attachment';
27
 
28
	/** the related TableMap class for this table */
29
	const TM_CLASS = 'AttachmentTableMap';
30
 
31
	/** The total number of columns. */
32
	const NUM_COLUMNS = 4;
33
 
34
	/** The number of lazy-loaded columns. */
35
	const NUM_LAZY_LOAD_COLUMNS = 0;
36
 
37
	/** the column name for the ID field */
38
	const ID = 'attachment.ID';
39
 
40
	/** the column name for the ARTICLE_ID field */
41
	const ARTICLE_ID = 'attachment.ARTICLE_ID';
42
 
43
	/** the column name for the NAME field */
44
	const NAME = 'attachment.NAME';
45
 
46
	/** the column name for the FILE field */
47
	const FILE = 'attachment.FILE';
48
 
49
	/**
50
	 * An identiy map to hold any loaded instances of Attachment objects.
51
	 * This must be public so that other peer classes can access this when hydrating from JOIN
52
	 * queries.
53
	 * @var        array Attachment[]
54
	 */
55
	public static $instances = array();
56
 
57
 
58
	// symfony behavior
59
 
60
	/**
61
	 * Indicates whether the current model includes I18N.
62
	 */
63
	const IS_I18N = false;
64
 
65
	/**
66
	 * holds an array of fieldnames
67
	 *
68
	 * first dimension keys are the type constants
69
	 * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
70
	 */
71
	private static $fieldNames = array (
72
		BasePeer::TYPE_PHPNAME => array ('Id', 'ArticleId', 'Name', 'File', ),
73
		BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'articleId', 'name', 'file', ),
74
		BasePeer::TYPE_COLNAME => array (self::ID, self::ARTICLE_ID, self::NAME, self::FILE, ),
75
		BasePeer::TYPE_FIELDNAME => array ('id', 'article_id', 'name', 'file', ),
76
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
77
	);
78
 
79
	/**
80
	 * holds an array of keys for quick access to the fieldnames array
81
	 *
82
	 * first dimension keys are the type constants
83
	 * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
84
	 */
85
	private static $fieldKeys = array (
86
		BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'ArticleId' => 1, 'Name' => 2, 'File' => 3, ),
87
		BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'articleId' => 1, 'name' => 2, 'file' => 3, ),
88
		BasePeer::TYPE_COLNAME => array (self::ID => 0, self::ARTICLE_ID => 1, self::NAME => 2, self::FILE => 3, ),
89
		BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'article_id' => 1, 'name' => 2, 'file' => 3, ),
90
		BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
91
	);
92
 
93
	/**
94
	 * Translates a fieldname to another type
95
	 *
96
	 * @param      string $name field name
97
	 * @param      string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
98
	 *                         BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
99
	 * @param      string $toType   One of the class type constants
100
	 * @return     string translated name of the field.
101
	 * @throws     PropelException - if the specified name could not be found in the fieldname mappings.
102
	 */
103
	static public function translateFieldName($name, $fromType, $toType)
104
	{
105
		$toNames = self::getFieldNames($toType);
106
		$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
107
		if ($key === null) {
108
			throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
109
		}
110
		return $toNames[$key];
111
	}
112
 
113
	/**
114
	 * Returns an array of field names.
115
	 *
116
	 * @param      string $type The type of fieldnames to return:
117
	 *                      One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
118
	 *                      BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
119
	 * @return     array A list of field names
120
	 */
121
 
122
	static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
123
	{
124
		if (!array_key_exists($type, self::$fieldNames)) {
125
			throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
126
		}
127
		return self::$fieldNames[$type];
128
	}
129
 
130
	/**
131
	 * Convenience method which changes table.column to alias.column.
132
	 *
133
	 * Using this method you can maintain SQL abstraction while using column aliases.
134
	 * <code>
135
	 *		$c->addAlias("alias1", TablePeer::TABLE_NAME);
136
	 *		$c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
137
	 * </code>
138
	 * @param      string $alias The alias for the current table.
139
	 * @param      string $column The column name for current table. (i.e. AttachmentPeer::COLUMN_NAME).
140
	 * @return     string
141
	 */
142
	public static function alias($alias, $column)
143
	{
144
		return str_replace(AttachmentPeer::TABLE_NAME.'.', $alias.'.', $column);
145
	}
146
 
147
	/**
148
	 * Add all the columns needed to create a new object.
149
	 *
150
	 * Note: any columns that were marked with lazyLoad="true" in the
151
	 * XML schema will not be added to the select list and only loaded
152
	 * on demand.
153
	 *
154
	 * @param      criteria object containing the columns to add.
155
	 * @throws     PropelException Any exceptions caught during processing will be
156
	 *		 rethrown wrapped into a PropelException.
157
	 */
158
	public static function addSelectColumns(Criteria $criteria)
159
	{
160
		$criteria->addSelectColumn(AttachmentPeer::ID);
161
		$criteria->addSelectColumn(AttachmentPeer::ARTICLE_ID);
162
		$criteria->addSelectColumn(AttachmentPeer::NAME);
163
		$criteria->addSelectColumn(AttachmentPeer::FILE);
164
	}
165
 
166
	/**
167
	 * Returns the number of rows matching criteria.
168
	 *
169
	 * @param      Criteria $criteria
170
	 * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
171
	 * @param      PropelPDO $con
172
	 * @return     int Number of matching rows.
173
	 */
174
	public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
175
	{
176
		// we may modify criteria, so copy it first
177
		$criteria = clone $criteria;
178
 
179
		// We need to set the primary table name, since in the case that there are no WHERE columns
180
		// it will be impossible for the BasePeer::createSelectSql() method to determine which
181
		// tables go into the FROM clause.
182
		$criteria->setPrimaryTableName(AttachmentPeer::TABLE_NAME);
183
 
184
		if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
185
			$criteria->setDistinct();
186
		}
187
 
188
		if (!$criteria->hasSelectClause()) {
189
			AttachmentPeer::addSelectColumns($criteria);
190
		}
191
 
192
		$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
193
		$criteria->setDbName(self::DATABASE_NAME); // Set the correct dbName
194
 
195
		if ($con === null) {
196
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
197
		}
198
		// symfony_behaviors behavior
199
		foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook)
200
		{
201
		  call_user_func($sf_hook, 'BaseAttachmentPeer', $criteria, $con);
202
		}
203
 
204
		// BasePeer returns a PDOStatement
205
		$stmt = BasePeer::doCount($criteria, $con);
206
 
207
		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
208
			$count = (int) $row[0];
209
		} else {
210
			$count = 0; // no rows returned; we infer that means 0 matches.
211
		}
212
		$stmt->closeCursor();
213
		return $count;
214
	}
215
	/**
216
	 * Method to select one object from the DB.
217
	 *
218
	 * @param      Criteria $criteria object used to create the SELECT statement.
219
	 * @param      PropelPDO $con
220
	 * @return     Attachment
221
	 * @throws     PropelException Any exceptions caught during processing will be
222
	 *		 rethrown wrapped into a PropelException.
223
	 */
224
	public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
225
	{
226
		$critcopy = clone $criteria;
227
		$critcopy->setLimit(1);
228
		$objects = AttachmentPeer::doSelect($critcopy, $con);
229
		if ($objects) {
230
			return $objects[0];
231
		}
232
		return null;
233
	}
234
	/**
235
	 * Method to do selects.
236
	 *
237
	 * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
238
	 * @param      PropelPDO $con
239
	 * @return     array Array of selected Objects
240
	 * @throws     PropelException Any exceptions caught during processing will be
241
	 *		 rethrown wrapped into a PropelException.
242
	 */
243
	public static function doSelect(Criteria $criteria, PropelPDO $con = null)
244
	{
245
		return AttachmentPeer::populateObjects(AttachmentPeer::doSelectStmt($criteria, $con));
246
	}
247
	/**
248
	 * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
249
	 *
250
	 * Use this method directly if you want to work with an executed statement durirectly (for example
251
	 * to perform your own object hydration).
252
	 *
253
	 * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
254
	 * @param      PropelPDO $con The connection to use
255
	 * @throws     PropelException Any exceptions caught during processing will be
256
	 *		 rethrown wrapped into a PropelException.
257
	 * @return     PDOStatement The executed PDOStatement object.
258
	 * @see        BasePeer::doSelect()
259
	 */
260
	public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
261
	{
262
		if ($con === null) {
263
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
264
		}
265
 
266
		if (!$criteria->hasSelectClause()) {
267
			$criteria = clone $criteria;
268
			AttachmentPeer::addSelectColumns($criteria);
269
		}
270
 
271
		// Set the correct dbName
272
		$criteria->setDbName(self::DATABASE_NAME);
273
		// symfony_behaviors behavior
274
		foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook)
275
		{
276
		  call_user_func($sf_hook, 'BaseAttachmentPeer', $criteria, $con);
277
		}
278
 
279
 
280
		// BasePeer returns a PDOStatement
281
		return BasePeer::doSelect($criteria, $con);
282
	}
283
	/**
284
	 * Adds an object to the instance pool.
285
	 *
286
	 * Propel keeps cached copies of objects in an instance pool when they are retrieved
287
	 * from the database.  In some cases -- especially when you override doSelect*()
288
	 * methods in your stub classes -- you may need to explicitly add objects
289
	 * to the cache in order to ensure that the same objects are always returned by doSelect*()
290
	 * and retrieveByPK*() calls.
291
	 *
292
	 * @param      Attachment $value A Attachment object.
293
	 * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
294
	 */
295
	public static function addInstanceToPool(Attachment $obj, $key = null)
296
	{
297
		if (Propel::isInstancePoolingEnabled()) {
298
			if ($key === null) {
299
				$key = (string) $obj->getId();
300
			} // if key === null
301
			self::$instances[$key] = $obj;
302
		}
303
	}
304
 
305
	/**
306
	 * Removes an object from the instance pool.
307
	 *
308
	 * Propel keeps cached copies of objects in an instance pool when they are retrieved
309
	 * from the database.  In some cases -- especially when you override doDelete
310
	 * methods in your stub classes -- you may need to explicitly remove objects
311
	 * from the cache in order to prevent returning objects that no longer exist.
312
	 *
313
	 * @param      mixed $value A Attachment object or a primary key value.
314
	 */
315
	public static function removeInstanceFromPool($value)
316
	{
317
		if (Propel::isInstancePoolingEnabled() && $value !== null) {
318
			if (is_object($value) && $value instanceof Attachment) {
319
				$key = (string) $value->getId();
320
			} elseif (is_scalar($value)) {
321
				// assume we've been passed a primary key
322
				$key = (string) $value;
323
			} else {
324
				$e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or Attachment object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
325
				throw $e;
326
			}
327
 
328
			unset(self::$instances[$key]);
329
		}
330
	} // removeInstanceFromPool()
331
 
332
	/**
333
	 * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
334
	 *
335
	 * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
336
	 * a multi-column primary key, a serialize()d version of the primary key will be returned.
337
	 *
338
	 * @param      string $key The key (@see getPrimaryKeyHash()) for this instance.
339
	 * @return     Attachment Found object or NULL if 1) no instance exists for specified key or 2) instance pooling has been disabled.
340
	 * @see        getPrimaryKeyHash()
341
	 */
342
	public static function getInstanceFromPool($key)
343
	{
344
		if (Propel::isInstancePoolingEnabled()) {
345
			if (isset(self::$instances[$key])) {
346
				return self::$instances[$key];
347
			}
348
		}
349
		return null; // just to be explicit
350
	}
351
 
352
	/**
353
	 * Clear the instance pool.
354
	 *
355
	 * @return     void
356
	 */
357
	public static function clearInstancePool()
358
	{
359
		self::$instances = array();
360
	}
361
 
362
	/**
363
	 * Method to invalidate the instance pool of all tables related to attachment
364
	 * by a foreign key with ON DELETE CASCADE
365
	 */
366
	public static function clearRelatedInstancePool()
367
	{
368
	}
369
 
370
	/**
371
	 * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
372
	 *
373
	 * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
374
	 * a multi-column primary key, a serialize()d version of the primary key will be returned.
375
	 *
376
	 * @param      array $row PropelPDO resultset row.
377
	 * @param      int $startcol The 0-based offset for reading from the resultset row.
378
	 * @return     string A string version of PK or NULL if the components of primary key in result array are all null.
379
	 */
380
	public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
381
	{
382
		// If the PK cannot be derived from the row, return NULL.
383
		if ($row[$startcol] === null) {
384
			return null;
385
		}
386
		return (string) $row[$startcol];
387
	}
388
 
389
	/**
390
	 * The returned array will contain objects of the default type or
391
	 * objects that inherit from the default.
392
	 *
393
	 * @throws     PropelException Any exceptions caught during processing will be
394
	 *		 rethrown wrapped into a PropelException.
395
	 */
396
	public static function populateObjects(PDOStatement $stmt)
397
	{
398
		$results = array();
399
 
400
		// set the class once to avoid overhead in the loop
401
		$cls = AttachmentPeer::getOMClass(false);
402
		// populate the object(s)
403
		while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
404
			$key = AttachmentPeer::getPrimaryKeyHashFromRow($row, 0);
405
			if (null !== ($obj = AttachmentPeer::getInstanceFromPool($key))) {
406
				// We no longer rehydrate the object, since this can cause data loss.
407
				// See http://propel.phpdb.org/trac/ticket/509
408
				// $obj->hydrate($row, 0, true); // rehydrate
409
				$results[] = $obj;
410
			} else {
411
				$obj = new $cls();
412
				$obj->hydrate($row);
413
				$results[] = $obj;
414
				AttachmentPeer::addInstanceToPool($obj, $key);
415
			} // if key exists
416
		}
417
		$stmt->closeCursor();
418
		return $results;
419
	}
420
 
421
	/**
422
	 * Returns the number of rows matching criteria, joining the related Article table
423
	 *
424
	 * @param      Criteria $criteria
425
	 * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
426
	 * @param      PropelPDO $con
427
	 * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
428
	 * @return     int Number of matching rows.
429
	 */
430
	public static function doCountJoinArticle(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
431
	{
432
		// we're going to modify criteria, so copy it first
433
		$criteria = clone $criteria;
434
 
435
		// We need to set the primary table name, since in the case that there are no WHERE columns
436
		// it will be impossible for the BasePeer::createSelectSql() method to determine which
437
		// tables go into the FROM clause.
438
		$criteria->setPrimaryTableName(AttachmentPeer::TABLE_NAME);
439
 
440
		if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
441
			$criteria->setDistinct();
442
		}
443
 
444
		if (!$criteria->hasSelectClause()) {
445
			AttachmentPeer::addSelectColumns($criteria);
446
		}
447
 
448
		$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
449
 
450
		// Set the correct dbName
451
		$criteria->setDbName(self::DATABASE_NAME);
452
 
453
		if ($con === null) {
454
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
455
		}
456
 
457
		$criteria->addJoin(AttachmentPeer::ARTICLE_ID, ArticlePeer::ID, $join_behavior);
458
 
459
		// symfony_behaviors behavior
460
		foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook)
461
		{
462
		  call_user_func($sf_hook, 'BaseAttachmentPeer', $criteria, $con);
463
		}
464
 
465
		$stmt = BasePeer::doCount($criteria, $con);
466
 
467
		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
468
			$count = (int) $row[0];
469
		} else {
470
			$count = 0; // no rows returned; we infer that means 0 matches.
471
		}
472
		$stmt->closeCursor();
473
		return $count;
474
	}
475
 
476
 
477
	/**
478
	 * Selects a collection of Attachment objects pre-filled with their Article objects.
479
	 * @param      Criteria  $criteria
480
	 * @param      PropelPDO $con
481
	 * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
482
	 * @return     array Array of Attachment objects.
483
	 * @throws     PropelException Any exceptions caught during processing will be
484
	 *		 rethrown wrapped into a PropelException.
485
	 */
486
	public static function doSelectJoinArticle(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
487
	{
488
		$criteria = clone $criteria;
489
 
490
		// Set the correct dbName if it has not been overridden
491
		if ($criteria->getDbName() == Propel::getDefaultDB()) {
492
			$criteria->setDbName(self::DATABASE_NAME);
493
		}
494
 
495
		AttachmentPeer::addSelectColumns($criteria);
496
		$startcol = (AttachmentPeer::NUM_COLUMNS - AttachmentPeer::NUM_LAZY_LOAD_COLUMNS);
497
		ArticlePeer::addSelectColumns($criteria);
498
 
499
		$criteria->addJoin(AttachmentPeer::ARTICLE_ID, ArticlePeer::ID, $join_behavior);
500
 
501
		// symfony_behaviors behavior
502
		foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook)
503
		{
504
		  call_user_func($sf_hook, 'BaseAttachmentPeer', $criteria, $con);
505
		}
506
 
507
		$stmt = BasePeer::doSelect($criteria, $con);
508
		$results = array();
509
 
510
		while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
511
			$key1 = AttachmentPeer::getPrimaryKeyHashFromRow($row, 0);
512
			if (null !== ($obj1 = AttachmentPeer::getInstanceFromPool($key1))) {
513
				// We no longer rehydrate the object, since this can cause data loss.
514
				// See http://propel.phpdb.org/trac/ticket/509
515
				// $obj1->hydrate($row, 0, true); // rehydrate
516
			} else {
517
 
518
				$cls = AttachmentPeer::getOMClass(false);
519
 
520
				$obj1 = new $cls();
521
				$obj1->hydrate($row);
522
				AttachmentPeer::addInstanceToPool($obj1, $key1);
523
			} // if $obj1 already loaded
524
 
525
			$key2 = ArticlePeer::getPrimaryKeyHashFromRow($row, $startcol);
526
			if ($key2 !== null) {
527
				$obj2 = ArticlePeer::getInstanceFromPool($key2);
528
				if (!$obj2) {
529
 
530
					$cls = ArticlePeer::getOMClass(false);
531
 
532
					$obj2 = new $cls();
533
					$obj2->hydrate($row, $startcol);
534
					ArticlePeer::addInstanceToPool($obj2, $key2);
535
				} // if obj2 already loaded
536
 
537
				// Add the $obj1 (Attachment) to $obj2 (Article)
538
				$obj2->addAttachment($obj1);
539
 
540
			} // if joined row was not null
541
 
542
			$results[] = $obj1;
543
		}
544
		$stmt->closeCursor();
545
		return $results;
546
	}
547
 
548
 
549
	/**
550
	 * Returns the number of rows matching criteria, joining all related tables
551
	 *
552
	 * @param      Criteria $criteria
553
	 * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
554
	 * @param      PropelPDO $con
555
	 * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
556
	 * @return     int Number of matching rows.
557
	 */
558
	public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
559
	{
560
		// we're going to modify criteria, so copy it first
561
		$criteria = clone $criteria;
562
 
563
		// We need to set the primary table name, since in the case that there are no WHERE columns
564
		// it will be impossible for the BasePeer::createSelectSql() method to determine which
565
		// tables go into the FROM clause.
566
		$criteria->setPrimaryTableName(AttachmentPeer::TABLE_NAME);
567
 
568
		if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
569
			$criteria->setDistinct();
570
		}
571
 
572
		if (!$criteria->hasSelectClause()) {
573
			AttachmentPeer::addSelectColumns($criteria);
574
		}
575
 
576
		$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
577
 
578
		// Set the correct dbName
579
		$criteria->setDbName(self::DATABASE_NAME);
580
 
581
		if ($con === null) {
582
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
583
		}
584
 
585
		$criteria->addJoin(AttachmentPeer::ARTICLE_ID, ArticlePeer::ID, $join_behavior);
586
 
587
		// symfony_behaviors behavior
588
		foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook)
589
		{
590
		  call_user_func($sf_hook, 'BaseAttachmentPeer', $criteria, $con);
591
		}
592
 
593
		$stmt = BasePeer::doCount($criteria, $con);
594
 
595
		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
596
			$count = (int) $row[0];
597
		} else {
598
			$count = 0; // no rows returned; we infer that means 0 matches.
599
		}
600
		$stmt->closeCursor();
601
		return $count;
602
	}
603
 
604
	/**
605
	 * Selects a collection of Attachment objects pre-filled with all related objects.
606
	 *
607
	 * @param      Criteria  $criteria
608
	 * @param      PropelPDO $con
609
	 * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
610
	 * @return     array Array of Attachment objects.
611
	 * @throws     PropelException Any exceptions caught during processing will be
612
	 *		 rethrown wrapped into a PropelException.
613
	 */
614
	public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
615
	{
616
		$criteria = clone $criteria;
617
 
618
		// Set the correct dbName if it has not been overridden
619
		if ($criteria->getDbName() == Propel::getDefaultDB()) {
620
			$criteria->setDbName(self::DATABASE_NAME);
621
		}
622
 
623
		AttachmentPeer::addSelectColumns($criteria);
624
		$startcol2 = (AttachmentPeer::NUM_COLUMNS - AttachmentPeer::NUM_LAZY_LOAD_COLUMNS);
625
 
626
		ArticlePeer::addSelectColumns($criteria);
627
		$startcol3 = $startcol2 + (ArticlePeer::NUM_COLUMNS - ArticlePeer::NUM_LAZY_LOAD_COLUMNS);
628
 
629
		$criteria->addJoin(AttachmentPeer::ARTICLE_ID, ArticlePeer::ID, $join_behavior);
630
 
631
		// symfony_behaviors behavior
632
		foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook)
633
		{
634
		  call_user_func($sf_hook, 'BaseAttachmentPeer', $criteria, $con);
635
		}
636
 
637
		$stmt = BasePeer::doSelect($criteria, $con);
638
		$results = array();
639
 
640
		while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
641
			$key1 = AttachmentPeer::getPrimaryKeyHashFromRow($row, 0);
642
			if (null !== ($obj1 = AttachmentPeer::getInstanceFromPool($key1))) {
643
				// We no longer rehydrate the object, since this can cause data loss.
644
				// See http://propel.phpdb.org/trac/ticket/509
645
				// $obj1->hydrate($row, 0, true); // rehydrate
646
			} else {
647
				$cls = AttachmentPeer::getOMClass(false);
648
 
649
				$obj1 = new $cls();
650
				$obj1->hydrate($row);
651
				AttachmentPeer::addInstanceToPool($obj1, $key1);
652
			} // if obj1 already loaded
653
 
654
			// Add objects for joined Article rows
655
 
656
			$key2 = ArticlePeer::getPrimaryKeyHashFromRow($row, $startcol2);
657
			if ($key2 !== null) {
658
				$obj2 = ArticlePeer::getInstanceFromPool($key2);
659
				if (!$obj2) {
660
 
661
					$cls = ArticlePeer::getOMClass(false);
662
 
663
					$obj2 = new $cls();
664
					$obj2->hydrate($row, $startcol2);
665
					ArticlePeer::addInstanceToPool($obj2, $key2);
666
				} // if obj2 loaded
667
 
668
				// Add the $obj1 (Attachment) to the collection in $obj2 (Article)
669
				$obj2->addAttachment($obj1);
670
			} // if joined row not null
671
 
672
			$results[] = $obj1;
673
		}
674
		$stmt->closeCursor();
675
		return $results;
676
	}
677
 
678
	/**
679
	 * Returns the TableMap related to this peer.
680
	 * This method is not needed for general use but a specific application could have a need.
681
	 * @return     TableMap
682
	 * @throws     PropelException Any exceptions caught during processing will be
683
	 *		 rethrown wrapped into a PropelException.
684
	 */
685
	public static function getTableMap()
686
	{
687
		return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
688
	}
689
 
690
	/**
691
	 * Add a TableMap instance to the database for this peer class.
692
	 */
693
	public static function buildTableMap()
694
	{
695
	  $dbMap = Propel::getDatabaseMap(BaseAttachmentPeer::DATABASE_NAME);
696
	  if (!$dbMap->hasTable(BaseAttachmentPeer::TABLE_NAME))
697
	  {
698
	    $dbMap->addTableObject(new AttachmentTableMap());
699
	  }
700
	}
701
 
702
	/**
703
	 * The class that the Peer will make instances of.
704
	 *
705
	 * If $withPrefix is true, the returned path
706
	 * uses a dot-path notation which is tranalted into a path
707
	 * relative to a location on the PHP include_path.
708
	 * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
709
	 *
710
	 * @param      boolean  Whether or not to return the path wit hthe class name
711
	 * @return     string path.to.ClassName
712
	 */
713
	public static function getOMClass($withPrefix = true)
714
	{
715
		return $withPrefix ? AttachmentPeer::CLASS_DEFAULT : AttachmentPeer::OM_CLASS;
716
	}
717
 
718
	/**
719
	 * Method perform an INSERT on the database, given a Attachment or Criteria object.
720
	 *
721
	 * @param      mixed $values Criteria or Attachment object containing data that is used to create the INSERT statement.
722
	 * @param      PropelPDO $con the PropelPDO connection to use
723
	 * @return     mixed The new primary key.
724
	 * @throws     PropelException Any exceptions caught during processing will be
725
	 *		 rethrown wrapped into a PropelException.
726
	 */
727
	public static function doInsert($values, PropelPDO $con = null)
728
	{
729
    // symfony_behaviors behavior
730
    foreach (sfMixer::getCallables('BaseAttachmentPeer:doInsert:pre') as $sf_hook)
731
    {
732
      if (false !== $sf_hook_retval = call_user_func($sf_hook, 'BaseAttachmentPeer', $values, $con))
733
      {
734
        return $sf_hook_retval;
735
      }
736
    }
737
 
738
		if ($con === null) {
739
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
740
		}
741
 
742
		if ($values instanceof Criteria) {
743
			$criteria = clone $values; // rename for clarity
744
		} else {
745
			$criteria = $values->buildCriteria(); // build Criteria from Attachment object
746
		}
747
 
748
		if ($criteria->containsKey(AttachmentPeer::ID) && $criteria->keyContainsValue(AttachmentPeer::ID) ) {
749
			throw new PropelException('Cannot insert a value for auto-increment primary key ('.AttachmentPeer::ID.')');
750
		}
751
 
752
 
753
		// Set the correct dbName
754
		$criteria->setDbName(self::DATABASE_NAME);
755
 
756
		try {
757
			// use transaction because $criteria could contain info
758
			// for more than one table (I guess, conceivably)
759
			$con->beginTransaction();
760
			$pk = BasePeer::doInsert($criteria, $con);
761
			$con->commit();
762
		} catch(PropelException $e) {
763
			$con->rollBack();
764
			throw $e;
765
		}
766
 
767
    // symfony_behaviors behavior
768
    foreach (sfMixer::getCallables('BaseAttachmentPeer:doInsert:post') as $sf_hook)
769
    {
770
      call_user_func($sf_hook, 'BaseAttachmentPeer', $values, $con, $pk);
771
    }
772
 
773
		return $pk;
774
	}
775
 
776
	/**
777
	 * Method perform an UPDATE on the database, given a Attachment or Criteria object.
778
	 *
779
	 * @param      mixed $values Criteria or Attachment object containing data that is used to create the UPDATE statement.
780
	 * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
781
	 * @return     int The number of affected rows (if supported by underlying database driver).
782
	 * @throws     PropelException Any exceptions caught during processing will be
783
	 *		 rethrown wrapped into a PropelException.
784
	 */
785
	public static function doUpdate($values, PropelPDO $con = null)
786
	{
787
    // symfony_behaviors behavior
788
    foreach (sfMixer::getCallables('BaseAttachmentPeer:doUpdate:pre') as $sf_hook)
789
    {
790
      if (false !== $sf_hook_retval = call_user_func($sf_hook, 'BaseAttachmentPeer', $values, $con))
791
      {
792
        return $sf_hook_retval;
793
      }
794
    }
795
 
796
		if ($con === null) {
797
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
798
		}
799
 
800
		$selectCriteria = new Criteria(self::DATABASE_NAME);
801
 
802
		if ($values instanceof Criteria) {
803
			$criteria = clone $values; // rename for clarity
804
 
805
			$comparison = $criteria->getComparison(AttachmentPeer::ID);
806
			$selectCriteria->add(AttachmentPeer::ID, $criteria->remove(AttachmentPeer::ID), $comparison);
807
 
808
		} else { // $values is Attachment object
809
			$criteria = $values->buildCriteria(); // gets full criteria
810
			$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
811
		}
812
 
813
		// set the correct dbName
814
		$criteria->setDbName(self::DATABASE_NAME);
815
 
816
		$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
817
 
818
    // symfony_behaviors behavior
819
    foreach (sfMixer::getCallables('BaseAttachmentPeer:doUpdate:post') as $sf_hook)
820
    {
821
      call_user_func($sf_hook, 'BaseAttachmentPeer', $values, $con, $ret);
822
    }
823
 
824
    return $ret;
825
	}
826
 
827
	/**
828
	 * Method to DELETE all rows from the attachment table.
829
	 *
830
	 * @return     int The number of affected rows (if supported by underlying database driver).
831
	 */
832
	public static function doDeleteAll($con = null)
833
	{
834
		if ($con === null) {
835
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
836
		}
837
		$affectedRows = 0; // initialize var to track total num of affected rows
838
		try {
839
			// use transaction because $criteria could contain info
840
			// for more than one table or we could emulating ON DELETE CASCADE, etc.
841
			$con->beginTransaction();
842
			$affectedRows += BasePeer::doDeleteAll(AttachmentPeer::TABLE_NAME, $con);
843
			// Because this db requires some delete cascade/set null emulation, we have to
844
			// clear the cached instance *after* the emulation has happened (since
845
			// instances get re-added by the select statement contained therein).
846
			AttachmentPeer::clearInstancePool();
847
			AttachmentPeer::clearRelatedInstancePool();
848
			$con->commit();
849
			return $affectedRows;
850
		} catch (PropelException $e) {
851
			$con->rollBack();
852
			throw $e;
853
		}
854
	}
855
 
856
	/**
857
	 * Method perform a DELETE on the database, given a Attachment or Criteria object OR a primary key value.
858
	 *
859
	 * @param      mixed $values Criteria or Attachment object or primary key or array of primary keys
860
	 *              which is used to create the DELETE statement
861
	 * @param      PropelPDO $con the connection to use
862
	 * @return     int 	The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
863
	 *				if supported by native driver or if emulated using Propel.
864
	 * @throws     PropelException Any exceptions caught during processing will be
865
	 *		 rethrown wrapped into a PropelException.
866
	 */
867
	 public static function doDelete($values, PropelPDO $con = null)
868
	 {
869
		if ($con === null) {
870
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
871
		}
872
 
873
		if ($values instanceof Criteria) {
874
			// invalidate the cache for all objects of this type, since we have no
875
			// way of knowing (without running a query) what objects should be invalidated
876
			// from the cache based on this Criteria.
877
			AttachmentPeer::clearInstancePool();
878
			// rename for clarity
879
			$criteria = clone $values;
880
		} elseif ($values instanceof Attachment) { // it's a model object
881
			// invalidate the cache for this single object
882
			AttachmentPeer::removeInstanceFromPool($values);
883
			// create criteria based on pk values
884
			$criteria = $values->buildPkeyCriteria();
885
		} else { // it's a primary key, or an array of pks
886
			$criteria = new Criteria(self::DATABASE_NAME);
887
			$criteria->add(AttachmentPeer::ID, (array) $values, Criteria::IN);
888
			// invalidate the cache for this object(s)
889
			foreach ((array) $values as $singleval) {
890
				AttachmentPeer::removeInstanceFromPool($singleval);
891
			}
892
		}
893
 
894
		// Set the correct dbName
895
		$criteria->setDbName(self::DATABASE_NAME);
896
 
897
		$affectedRows = 0; // initialize var to track total num of affected rows
898
 
899
		try {
900
			// use transaction because $criteria could contain info
901
			// for more than one table or we could emulating ON DELETE CASCADE, etc.
902
			$con->beginTransaction();
903
 
904
			$affectedRows += BasePeer::doDelete($criteria, $con);
905
			AttachmentPeer::clearRelatedInstancePool();
906
			$con->commit();
907
			return $affectedRows;
908
		} catch (PropelException $e) {
909
			$con->rollBack();
910
			throw $e;
911
		}
912
	}
913
 
914
	/**
915
	 * Validates all modified columns of given Attachment object.
916
	 * If parameter $columns is either a single column name or an array of column names
917
	 * than only those columns are validated.
918
	 *
919
	 * NOTICE: This does not apply to primary or foreign keys for now.
920
	 *
921
	 * @param      Attachment $obj The object to validate.
922
	 * @param      mixed $cols Column name or array of column names.
923
	 *
924
	 * @return     mixed TRUE if all columns are valid or the error message of the first invalid column.
925
	 */
926
	public static function doValidate(Attachment $obj, $cols = null)
927
	{
928
		$columns = array();
929
 
930
		if ($cols) {
931
			$dbMap = Propel::getDatabaseMap(AttachmentPeer::DATABASE_NAME);
932
			$tableMap = $dbMap->getTable(AttachmentPeer::TABLE_NAME);
933
 
934
			if (! is_array($cols)) {
935
				$cols = array($cols);
936
			}
937
 
938
			foreach ($cols as $colName) {
939
				if ($tableMap->containsColumn($colName)) {
940
					$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
941
					$columns[$colName] = $obj->$get();
942
				}
943
			}
944
		} else {
945
 
946
		}
947
 
948
		return BasePeer::doValidate(AttachmentPeer::DATABASE_NAME, AttachmentPeer::TABLE_NAME, $columns);
949
	}
950
 
951
	/**
952
	 * Retrieve a single object by pkey.
953
	 *
954
	 * @param      int $pk the primary key.
955
	 * @param      PropelPDO $con the connection to use
956
	 * @return     Attachment
957
	 */
958
	public static function retrieveByPK($pk, PropelPDO $con = null)
959
	{
960
 
961
		if (null !== ($obj = AttachmentPeer::getInstanceFromPool((string) $pk))) {
962
			return $obj;
963
		}
964
 
965
		if ($con === null) {
966
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
967
		}
968
 
969
		$criteria = new Criteria(AttachmentPeer::DATABASE_NAME);
970
		$criteria->add(AttachmentPeer::ID, $pk);
971
 
972
		$v = AttachmentPeer::doSelect($criteria, $con);
973
 
974
		return !empty($v) > 0 ? $v[0] : null;
975
	}
976
 
977
	/**
978
	 * Retrieve multiple objects by pkey.
979
	 *
980
	 * @param      array $pks List of primary keys
981
	 * @param      PropelPDO $con the connection to use
982
	 * @throws     PropelException Any exceptions caught during processing will be
983
	 *		 rethrown wrapped into a PropelException.
984
	 */
985
	public static function retrieveByPKs($pks, PropelPDO $con = null)
986
	{
987
		if ($con === null) {
988
			$con = Propel::getConnection(AttachmentPeer::DATABASE_NAME, Propel::CONNECTION_READ);
989
		}
990
 
991
		$objs = null;
992
		if (empty($pks)) {
993
			$objs = array();
994
		} else {
995
			$criteria = new Criteria(AttachmentPeer::DATABASE_NAME);
996
			$criteria->add(AttachmentPeer::ID, $pks, Criteria::IN);
997
			$objs = AttachmentPeer::doSelect($criteria, $con);
998
		}
999
		return $objs;
1000
	}
1001
 
1002
	// symfony behavior
1003
 
1004
	/**
1005
	 * Returns an array of arrays that contain columns in each unique index.
1006
	 *
1007
	 * @return array
1008
	 */
1009
	static public function getUniqueColumnNames()
1010
	{
1011
	  return array();
1012
	}
1013
 
1014
	// symfony_behaviors behavior
1015
 
1016
	/**
1017
	 * Returns the name of the hook to call from inside the supplied method.
1018
	 *
1019
	 * @param string $method The calling method
1020
	 *
1021
	 * @return string A hook name for {@link sfMixer}
1022
	 *
1023
	 * @throws LogicException If the method name is not recognized
1024
	 */
1025
	static private function getMixerPreSelectHook($method)
1026
	{
1027
	  if (preg_match('/^do(Select|Count)(Join(All(Except)?)?|Stmt)?/', $method, $match))
1028
	  {
1029
	    return sprintf('BaseAttachmentPeer:%s:%1$s', 'Count' == $match[1] ? 'doCount' : $match[0]);
1030
	  }
1031
 
1032
	  throw new LogicException(sprintf('Unrecognized function "%s"', $method));
1033
	}
1034
 
1035
} // BaseAttachmentPeer
1036
 
1037
// This is the static code needed to register the TableMap for this table with the main Propel class.
1038
//
1039
BaseAttachmentPeer::buildTableMap();
1040