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