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