PageRenderTime 67ms CodeModel.GetById 2ms app.highlight 54ms RepoModel.GetById 1ms app.codeStats 1ms

/package/app/app/symfony/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5BasicPeerBuilder.php

https://bitbucket.org/pandaos/kaltura
PHP | 1472 lines | 812 code | 146 blank | 514 comment | 78 complexity | b8bb3f9675eac159d13d81d973776b3c MD5 | raw file
   1<?php
   2
   3/*
   4 *  $Id: PHP5BasicPeerBuilder.php 358 2006-04-18 17:40:40Z oliver $
   5 *
   6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17 *
  18 * This software consists of voluntary contributions made by many individuals
  19 * and is licensed under the LGPL. For more information please see
  20 * <http://propel.phpdb.org>.
  21 */
  22
  23require_once 'propel/engine/builder/om/PeerBuilder.php';
  24
  25/**
  26 * Generates a PHP5 base Peer class for user object model (OM).
  27 *
  28 * This class produces the base peer class (e.g. BaseMyPeer) which contains all
  29 * the custom-built query and manipulator methods.
  30 *
  31 * This class replaces the Peer.tpl, with the intent of being easier for users
  32 * to customize (through extending & overriding).
  33 *
  34 * @author Hans Lellelid <hans@xmpl.org>
  35 * @package propel.engine.builder.om.php5
  36 */
  37class PHP5BasicPeerBuilder extends PeerBuilder {
  38
  39	/**
  40	 * Returns the name of the current class being built.
  41	 * @return string
  42	 */
  43	public function getClassname()
  44	{
  45		return $this->getBuildProperty('basePrefix') . $this->getStubPeerBuilder()->getClassname();
  46	}
  47
  48	/**
  49	 * Gets the package for the [base] peer classes.
  50	 * @return string
  51	 */
  52	public function getPackage()
  53	{
  54		return parent::getPackage() . ".om";
  55	}
  56
  57	/**
  58	 * Adds the include() statements for files that this class depends on or utilizes.
  59	 * @param string &$script The script will be modified in this method.
  60	 */
  61	protected function addIncludes(&$script) {
  62
  63		$table = $this->getTable();
  64
  65		$basePeerFile = $this->getFilePath($this->basePeerClass);
  66		$objectFile = $this->getStubObjectBuilder()->getClassFilePath();
  67
  68		$script .= "
  69require_once '$basePeerFile';
  70// The object class -- needed for instanceof checks in this class.
  71// actual class may be a subclass -- as returned by ".$this->getPeerClassname()."::getOMClass()
  72include_once '$objectFile';";
  73
  74		$script .= "
  75";
  76
  77	} // addIncludes()
  78
  79	/**
  80	 * Adds class phpdoc comment and openning of class.
  81	 * @param string &$script The script will be modified in this method.
  82	 */
  83	protected function addClassOpen(&$script) {
  84
  85		$tableName = $this->getTable()->getName();
  86		$tableDesc = $this->getTable()->getDescription();
  87
  88		$script .= "
  89/**
  90 * Base static class for performing query and update operations on the '$tableName' table.
  91 *
  92 * $tableDesc
  93 *";
  94		if ($this->getBuildProperty('addTimeStamp')) {
  95			$now = strftime('%c');
  96			$script .= "
  97 * This class was autogenerated by Propel on:
  98 *
  99 * $now
 100 *";
 101		}
 102		$script .= "
 103 * @package ".$this->getPackage()."
 104 */
 105abstract class ".$this->getClassname()." {
 106";
 107	}
 108
 109	/**
 110	 * Closes class.
 111	 * Adds closing brace at end of class and the static map builder registration code.
 112	 * @param string &$script The script will be modified in this method.
 113	 * @see addStaticMapBuilderRegistration()
 114	 */
 115	protected function addClassClose(&$script)
 116	{
 117		$script .= "
 118} // " . $this->getClassname() . "
 119";
 120		$this->addStaticMapBuilderRegistration($script);
 121	}
 122
 123	/**
 124	 * Adds the static map builder registraction code.
 125	 * @param string &$script The script will be modified in this method.
 126	 */
 127	protected function addStaticMapBuilderRegistration(&$script)
 128	{
 129		$table = $this->getTable();
 130		$mapBuilderFile = $this->getMapBuilderBuilder()->getClassFilePath();
 131
 132		$script .= "
 133// static code to register the map builder for this Peer with the main Propel class
 134if (Propel::isInit()) {
 135	// the MapBuilder classes register themselves with Propel during initialization
 136	// so we need to load them here.
 137	try {
 138		".$this->getClassname()."::getMapBuilder();
 139	} catch (Exception \$e) {
 140		Propel::log('Could not initialize Peer: ' . \$e->getMessage(), Propel::LOG_ERR);
 141	}
 142} else {
 143	// even if Propel is not yet initialized, the map builder class can be registered
 144	// now and then it will be loaded when Propel initializes.
 145	require_once '$mapBuilderFile';
 146	Propel::registerMapBuilder('".$this->getMapBuilderBuilder()->getClasspath()."');
 147}
 148";
 149	}
 150
 151	/**
 152	 * Adds constant and variable declarations that go at the top of the class.
 153	 * @param string &$script The script will be modified in this method.
 154	 * @see addColumnNameConstants()
 155	 */
 156	protected function addConstantsAndAttributes(&$script)
 157	{
 158		$tableName = $this->getTable()->getName();
 159		$dbName = $this->getDatabase()->getName();
 160		$script .= "
 161	/** the default database name for this class */
 162	const DATABASE_NAME = '$dbName';
 163
 164	/** the table name for this class */
 165	const TABLE_NAME = '$tableName';
 166
 167	/** A class that can be returned by this peer. */
 168	const CLASS_DEFAULT = '".$this->getStubObjectBuilder()->getClasspath()."';
 169
 170	/** The total number of columns. */
 171	const NUM_COLUMNS = ".$this->getTable()->getNumColumns().";
 172
 173	/** The number of lazy-loaded columns. */
 174	const NUM_LAZY_LOAD_COLUMNS = ".$this->getTable()->getNumLazyLoadColumns().";
 175
 176";
 177		$this->addColumnNameConstants($script);
 178		$this->addInheritanceColumnConstants($script);
 179
 180		$script .= "
 181	/** The PHP to DB Name Mapping */
 182	private static \$phpNameMap = null;
 183
 184";
 185
 186		$this->addFieldNamesAttribute($script);
 187		$this->addFieldKeysAttribute($script);
 188		
 189	}
 190
 191	/**
 192	 * Adds the COLUMN_NAME contants to the class definition.
 193	 * @param string &$script The script will be modified in this method.
 194	 */
 195	protected function addColumnNameConstants(&$script)
 196	{
 197		foreach ($this->getTable()->getColumns() as $col) {
 198
 199			$script .= "
 200	/** the column name for the ".strtoupper($col->getName()) ." field */
 201	const ".$this->getColumnName($col) ." = '".$this->getTable()->getName().".".strtoupper($col->getName())."';
 202";
 203		} // foreach
 204	}
 205
 206	protected function addFieldNamesAttribute(&$script)
 207	{
 208		$table = $this->getTable();
 209
 210		$tableColumns = $table->getColumns();
 211		$tablePhpname = $table->getPhpName();
 212
 213		$script .= "
 214	/**
 215	 * holds an array of fieldnames
 216	 *
 217	 * first dimension keys are the type constants
 218	 * e.g. self::\$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
 219	 */
 220	private static \$fieldNames = array (
 221		BasePeer::TYPE_PHPNAME => array (";
 222		foreach ($tableColumns as $col) {
 223			$script .= "'".$col->getPhpName()."', ";
 224		}
 225		$script .= "),
 226		BasePeer::TYPE_COLNAME => array (";
 227		foreach ($tableColumns as $col) {
 228			$script .= $this->getColumnConstant($col).", ";
 229		}
 230		$script .= "),
 231		BasePeer::TYPE_FIELDNAME => array (";
 232		foreach ($tableColumns as $col) {
 233			$script .= "'".$col->getName()."', ";
 234		}
 235		$script .= "),
 236		BasePeer::TYPE_NUM => array (";
 237		foreach ($tableColumns as $num => $col) {
 238			$script .= "$num, ";
 239		}
 240		$script .= ")
 241	);
 242";
 243	}
 244
 245	protected function addFieldKeysAttribute(&$script)
 246	{
 247		$table = $this->getTable();
 248
 249		$tableColumns = $table->getColumns();
 250		$tablePhpname = $table->getPhpName();
 251
 252		$script .= "
 253	/**
 254	 * holds an array of keys for quick access to the fieldnames array
 255	 *
 256	 * first dimension keys are the type constants
 257	 * e.g. self::\$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
 258	 */
 259	private static \$fieldKeys = array (
 260		BasePeer::TYPE_PHPNAME => array (";
 261		foreach ($tableColumns as $num => $col) {
 262			$script .= "'".$col->getPhpName()."' => $num, ";
 263		}
 264		$script .= "),
 265		BasePeer::TYPE_COLNAME => array (";
 266		foreach ($tableColumns as $num => $col) {
 267			$script .= $this->getColumnConstant($col)." => $num, ";
 268		}
 269		$script .= "),
 270		BasePeer::TYPE_FIELDNAME => array (";
 271		foreach ($tableColumns as $num => $col) {
 272			$script .= "'".$col->getName()."' => $num, ";
 273		}
 274		$script .= "),
 275		BasePeer::TYPE_NUM => array (";
 276		foreach ($tableColumns as $num => $col) {
 277			$script .= "$num, ";
 278		}
 279		$script .= ")
 280	);
 281";
 282	} // addFielKeysAttribute
 283
 284
 285	protected function addGetFieldNames(&$script)
 286	{
 287		$script .= "
 288	/**
 289	 * Returns an array of of field names.
 290	 *
 291	 * @param  string \$type The type of fieldnames to return:
 292	 *                      One of the class type constants TYPE_PHPNAME,
 293	 *                      TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
 294	 * @return array A list of field names
 295	 */
 296
 297	static public function getFieldNames(\$type = BasePeer::TYPE_PHPNAME)
 298	{
 299		if (!array_key_exists(\$type, self::\$fieldNames)) {
 300			throw new PropelException('Method getFieldNames() expects the parameter \$type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . \$type . ' was given.');
 301		}
 302		return self::\$fieldNames[\$type];
 303	}
 304";
 305
 306	} // addGetFieldNames()
 307
 308	protected function addTranslateFieldName(&$script)
 309	{
 310		$script .= "
 311	/**
 312	 * Translates a fieldname to another type
 313	 *
 314	 * @param string \$name field name
 315	 * @param string \$fromType One of the class type constants TYPE_PHPNAME,
 316	 *                         TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
 317	 * @param string \$toType   One of the class type constants
 318	 * @return string translated name of the field.
 319	 */
 320	static public function translateFieldName(\$name, \$fromType, \$toType)
 321	{
 322		\$toNames = self::getFieldNames(\$toType);
 323		\$key = isset(self::\$fieldKeys[\$fromType][\$name]) ? self::\$fieldKeys[\$fromType][\$name] : null;
 324		if (\$key === null) {
 325			throw new PropelException(\"'\$name' could not be found in the field names of type '\$fromType'. These are: \" . print_r(self::\$fieldKeys[\$fromType], true));
 326		}
 327		return \$toNames[\$key];
 328	}
 329";
 330	} // addTranslateFieldName()
 331
 332	/**
 333	 * Adds the getMapBuilder() method.
 334	 * @param string &$script The script will be modified in this method.
 335	 */
 336	protected function addGetMapBuilder(&$script)
 337	{
 338		$script .= "
 339	/**
 340	 * @return MapBuilder the map builder for this peer
 341	 * @throws PropelException Any exceptions caught during processing will be
 342	 *		 rethrown wrapped into a PropelException.
 343	 */
 344	public static function getMapBuilder()
 345	{
 346		include_once '" . $this->getMapBuilderBuilder()->getClassFilePath()."';
 347		return ".$this->basePeerClassname."::getMapBuilder('". $this->getMapBuilderBuilder()->getClasspath() ."');
 348	}";
 349	}
 350
 351	/**
 352	 * Adds the getPhpNameMap() method.
 353	 * @param string &$script The script will be modified in this method.
 354	 * @todo Replace with static version (this can be built at build-time).
 355	 */
 356	protected function addGetPhpNameMap(&$script)
 357	{
 358		$script .= "
 359	/**
 360	 * Gets a map (hash) of PHP names to DB column names.
 361	 *
 362	 * @return array The PHP to DB name map for this peer
 363	 * @throws PropelException Any exceptions caught during processing will be
 364	 *		 rethrown wrapped into a PropelException.
 365	 * @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
 366	 */
 367	public static function getPhpNameMap()
 368	{
 369		if (self::\$phpNameMap === null) {
 370			\$map = ".$this->getTable()->getPhpName()."Peer::getTableMap();
 371			\$columns = \$map->getColumns();
 372			\$nameMap = array();
 373			foreach (\$columns as \$column) {
 374				\$nameMap[\$column->getPhpName()] = \$column->getColumnName();
 375			}
 376			self::\$phpNameMap = \$nameMap;
 377		}
 378		return self::\$phpNameMap;
 379	}";
 380	}
 381
 382	/**
 383	 * Adds the CLASSKEY_* and CLASSNAME_* constants used for inheritance.
 384	 * @param string &$script The script will be modified in this method.
 385	 */
 386	public function addInheritanceColumnConstants(&$script)
 387	{
 388		if ($this->getTable()->getChildrenColumn()) {
 389
 390			$col = $this->getTable()->getChildrenColumn();
 391			$tfc = $this->getTable()->getPhpName();
 392			$cfc = $col->getPhpName();
 393
 394			if ($col->isEnumeratedClasses()) {
 395
 396				if ($col->isPrimitiveNumeric()) $quote = "";
 397				else $quote = '"';
 398
 399				foreach ($col->getChildren() as $child) {
 400					$childBuilder = $this->getMultiExtendObjectBuilder();
 401					$childBuilder->setChild($child);
 402
 403					$script .= "
 404	/** A key representing a particular subclass */
 405	const CLASSKEY_".strtoupper($child->getKey())." = '" . $child->getKey() . "';
 406
 407        /** A key representing a particular subclass */
 408        const CLASSKEY_".strtoupper($child->getClassName())." = '" . $child->getKey() . "';
 409
 410	/** A class that can be returned by this peer. */
 411	const CLASSNAME_".strtoupper($child->getKey())." = '". $childBuilder->getClasspath() . "';
 412";
 413				} /* foreach children */
 414			} /* if col->isenumerated...() */
 415		} /* if table->getchildrencolumn() */
 416
 417	} //
 418
 419
 420
 421	/**
 422	 * Adds the alias() utility method.
 423	 * @param string &$script The script will be modified in this method.
 424	 */
 425	protected function addAlias(&$script)
 426	{
 427		$script .= "
 428	/**
 429	 * Convenience method which changes table.column to alias.column.
 430	 *
 431	 * Using this method you can maintain SQL abstraction while using column aliases.
 432	 * <code>
 433	 *		\$c->addAlias(\"alias1\", TablePeer::TABLE_NAME);
 434	 *		\$c->addJoin(TablePeer::alias(\"alias1\", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
 435	 * </code>
 436	 * @param string \$alias The alias for the current table.
 437	 * @param string \$column The column name for current table. (i.e. ".$this->getTable()->getPhpName()."Peer::COLUMN_NAME).
 438	 * @return string
 439	 */
 440	public static function alias(\$alias, \$column)
 441	{
 442		return str_replace(".$this->getPeerClassname()."::TABLE_NAME.'.', \$alias.'.', \$column);
 443	}
 444";
 445	} // addAliasMethod
 446
 447	/**
 448	 * Adds the addSelectColumns() method.
 449	 * @param string &$script The script will be modified in this method.
 450	 */
 451	protected function addAddSelectColumns(&$script)
 452	{
 453		$script .= "
 454	/**
 455	 * Add all the columns needed to create a new object.
 456	 *
 457	 * Note: any columns that were marked with lazyLoad=\"true\" in the
 458	 * XML schema will not be added to the select list and only loaded
 459	 * on demand.
 460	 *
 461	 * @param criteria object containing the columns to add.
 462	 * @throws PropelException Any exceptions caught during processing will be
 463	 *		 rethrown wrapped into a PropelException.
 464	 */
 465	public static function addSelectColumns(Criteria \$criteria)
 466	{
 467";
 468		foreach ($this->getTable()->getColumns() as $col) {
 469			if (!$col->isLazyLoad()) {
 470				$script .= "
 471		\$criteria->addSelectColumn(".$this->getPeerClassname()."::".$this->getColumnName($col).");
 472";
 473			} // if !col->isLazyLoad
 474		} // foreach
 475		$script .="
 476	}
 477";
 478	} // addAddSelectColumns()
 479
 480
 481
 482	/**
 483	 * Adds the COUNT constants.
 484	 * @param string &$script The script will be modified in this method.
 485	 */
 486	protected function addCountConstants(&$script)
 487	{
 488		$table = $this->getTable();
 489		$count_col = "*";
 490		/*
 491		* FIXME
 492		* (HL) wanted to remove this because AFAIK count(*) is generally
 493		* optimized in databases, and furthermore the code below isn't correct
 494		* (multi-pkey needs to be accounted for)....
 495		*/
 496		if ($table->hasPrimaryKey()) {
 497			$pk = $table->getPrimaryKey();
 498			$count_col = $table->getName().".".strtoupper($pk[0]->getName());
 499		}
 500
 501		$script .= "
 502	const COUNT = 'COUNT($count_col)';
 503	const COUNT_DISTINCT = 'COUNT(DISTINCT $count_col)';
 504";
 505	}
 506
 507	/**
 508	 * Adds the doCount() method.
 509	 * @param string &$script The script will be modified in this method.
 510	 */
 511	protected function addDoCount(&$script)
 512	{
 513		$script .= "
 514	/**
 515	 * Returns the number of rows matching criteria.
 516	 *
 517	 * @param Criteria \$criteria
 518	 * @param boolean \$distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
 519	 * @param Connection \$con
 520	 * @return int Number of matching rows.
 521	 */
 522	public static function doCount(Criteria \$criteria, \$distinct = false, \$con = null)
 523	{
 524		// we're going to modify criteria, so copy it first
 525		\$criteria = clone \$criteria;
 526
 527		// clear out anything that might confuse the ORDER BY clause
 528		\$criteria->clearSelectColumns()->clearOrderByColumns();
 529		if (\$distinct || in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
 530			\$criteria->addSelectColumn(".$this->getPeerClassname()."::COUNT_DISTINCT);
 531		} else {
 532			\$criteria->addSelectColumn(".$this->getPeerClassname()."::COUNT);
 533		}
 534
 535		// just in case we're grouping: add those columns to the select statement
 536		foreach(\$criteria->getGroupByColumns() as \$column)
 537		{
 538			\$criteria->addSelectColumn(\$column);
 539		}
 540
 541		\$rs = ".$this->getPeerClassname()."::doSelectRS(\$criteria, \$con);
 542		if (\$rs->next()) {
 543			return \$rs->getInt(1);
 544		} else {
 545			// no rows returned; we infer that means 0 matches.
 546			return 0;
 547		}
 548	}";
 549	}
 550
 551	/**
 552	 * Adds the doSelectOne() method.
 553	 * @param string &$script The script will be modified in this method.
 554	 */
 555	protected function addDoSelectOne(&$script)
 556	{
 557		$script .= "
 558	/**
 559	 * Method to select one object from the DB.
 560	 *
 561	 * @param Criteria \$criteria object used to create the SELECT statement.
 562	 * @param Connection \$con
 563	 * @return ".$this->getTable()->getPhpName()."
 564	 * @throws PropelException Any exceptions caught during processing will be
 565	 *		 rethrown wrapped into a PropelException.
 566	 */
 567	public static function doSelectOne(Criteria \$criteria, \$con = null)
 568	{
 569		\$critcopy = clone \$criteria;
 570		\$critcopy->setLimit(1);
 571		\$objects = ".$this->getPeerClassname()."::doSelect(\$critcopy, \$con);
 572		if (\$objects) {
 573			return \$objects[0];
 574		}
 575		return null;
 576	}";
 577	}
 578
 579	/**
 580	 * Adds the doSelect() method.
 581	 * @param string &$script The script will be modified in this method.
 582	 */
 583	protected function addDoSelect(&$script)
 584	{
 585		$script .= "
 586	/**
 587	 * Method to do selects.
 588	 *
 589	 * @param Criteria \$criteria The Criteria object used to build the SELECT statement.
 590	 * @param Connection \$con
 591	 * @return array Array of selected Objects
 592	 * @throws PropelException Any exceptions caught during processing will be
 593	 *		 rethrown wrapped into a PropelException.
 594	 */
 595	public static function doSelect(Criteria \$criteria, \$con = null)
 596	{
 597		return ".$this->getPeerClassname()."::populateObjects(".$this->getPeerClassname()."::doSelectRS(\$criteria, \$con));
 598	}";
 599	}
 600
 601	/**
 602	 * Adds the doSelectRS() method.
 603	 * @param string &$script The script will be modified in this method.
 604	 */
 605	protected function addDoSelectRS(&$script)
 606	{
 607
 608		$script .= "
 609	/**
 610	 * Prepares the Criteria object and uses the parent doSelect()
 611	 * method to get a ResultSet.
 612	 *
 613	 * Use this method directly if you want to just get the resultset
 614	 * (instead of an array of objects).
 615	 *
 616	 * @param Criteria \$criteria The Criteria object used to build the SELECT statement.
 617	 * @param Connection \$con the connection to use
 618	 * @throws PropelException Any exceptions caught during processing will be
 619	 *		 rethrown wrapped into a PropelException.
 620	 * @return ResultSet The resultset object with numerically-indexed fields.
 621	 * @see ".$this->basePeerClassname."::doSelect()
 622	 */
 623	public static function doSelectRS(Criteria \$criteria, \$con = null)
 624	{
 625		if (\$con === null) {
 626			\$con = Propel::getConnection(self::DATABASE_NAME);
 627		}
 628
 629		if (!\$criteria->getSelectColumns()) {
 630			\$criteria = clone \$criteria;
 631			".$this->getPeerClassname()."::addSelectColumns(\$criteria);
 632		}
 633
 634		// Set the correct dbName
 635		\$criteria->setDbName(self::DATABASE_NAME);
 636
 637		// BasePeer returns a Creole ResultSet, set to return
 638		// rows indexed numerically.
 639		return ".$this->basePeerClassname."::doSelect(\$criteria, \$con);
 640	}";
 641	}
 642
 643	/**
 644	 * Adds the populateObjects() method.
 645	 * @param string &$script The script will be modified in this method.
 646	 */
 647	protected function addPopulateObjects(&$script)
 648	{
 649		$table = $this->getTable();
 650		$script .= "
 651	/**
 652	 * The returned array will contain objects of the default type or
 653	 * objects that inherit from the default.
 654	 *
 655	 * @throws PropelException Any exceptions caught during processing will be
 656	 *		 rethrown wrapped into a PropelException.
 657	 */
 658	public static function populateObjects(ResultSet \$rs)
 659	{
 660		\$results = array();
 661	";
 662		if (!$table->getChildrenColumn()) {
 663			$script .= "
 664		// set the class once to avoid overhead in the loop
 665		\$cls = ".$this->getPeerClassname()."::getOMClass();
 666		\$cls = Propel::import(\$cls);";
 667		}
 668
 669		$script .= "
 670		// populate the object(s)
 671		while(\$rs->next()) {
 672		";
 673		if ($table->getChildrenColumn()) {
 674			$script .= "
 675			// class must be set each time from the record row
 676			\$cls = Propel::import(".$this->getPeerClassname()."::getOMClass(\$rs, 1));
 677			\$obj = new \$cls();
 678			\$obj->hydrate(\$rs);
 679			\$results[] = \$obj;
 680			";
 681		} else {
 682			$script .= "
 683			\$obj = new \$cls();
 684			\$obj->hydrate(\$rs);
 685			\$results[] = \$obj;
 686			";
 687		}
 688		$script .= "
 689		}
 690		return \$results;
 691	}";
 692	}
 693
 694	/**
 695	 * Adds a getOMClass() for non-abstract tables that have inheritance.
 696	 * @param string &$script The script will be modified in this method.
 697	 */
 698	protected function addGetOMClass_Inheritance(&$script)
 699	{
 700		$col = $this->getTable()->getChildrenColumn();
 701		$script .= "
 702	/**
 703	 * The returned Class will contain objects of the default type or
 704	 * objects that inherit from the default.
 705	 *
 706	 * @param ResultSet \$rs ResultSet with pointer to record containing om class.
 707	 * @param int \$colnum Column to examine for OM class information (first is 1).
 708	 * @throws PropelException Any exceptions caught during processing will be
 709	 *		 rethrown wrapped into a PropelException.
 710	 */
 711	public static function getOMClass(ResultSet \$rs, \$colnum)
 712	{
 713		try {
 714";
 715		if ($col->isEnumeratedClasses()) {
 716			$script .= "
 717			\$omClass = null;
 718			\$classKey = \$rs->getString(\$colnum - 1 + " . $col->getPosition() . ");
 719
 720			switch(\$classKey) {
 721";
 722			foreach ($col->getChildren() as $child) {
 723				$script .= "
 724				case self::CLASSKEY_".$child->getKey().":
 725					\$omClass = self::CLASSNAME_".strtoupper($child->getKey()).";
 726					break;
 727";
 728			} /* foreach */
 729			$script .= "
 730				default:
 731					\$omClass = self::CLASS_DEFAULT;
 732";
 733			$script .= "
 734			} // switch
 735";
 736		} else { /* if not enumerated */
 737			$script .= "
 738			\$omClass = Propel::import(\$rs->getString(\$colnum - 1 + ".$col->getPosition()."));
 739";
 740		}
 741		$script .= "
 742		} catch (Exception \$e) {
 743			throw new PropelException('Unable to get OM class.', \$e);
 744		}
 745		return \$omClass;
 746	}
 747";
 748	}
 749
 750	/**
 751	 * Adds a getOMClass() signature for abstract tables that have inheritance.
 752	 * @param string &$script The script will be modified in this method.
 753	 */
 754	protected function addGetOMClass_Inheritance_Abstract(&$script)
 755	{
 756		$script .= "
 757	/**
 758	 * The returned Class will contain objects of the default type or
 759	 * objects that inherit from the default.
 760	 *
 761	 * This method must be overridden by the stub subclass, because
 762	 * ".$this->getTable()->getPhpName()." is declared abstract in the schema.
 763	 *
 764	 * @param ResultSet \$rs ResultSet with pointer to record containing om class.
 765	 * @param int \$colnum Column to examine for OM class information (first is 1).
 766	 * @throws PropelException Any exceptions caught during processing will be
 767	 *		 rethrown wrapped into a PropelException.
 768	 */
 769	abstract public static function getOMClass();
 770";
 771	}
 772
 773	/**
 774	 * Adds a getOMClass() for non-abstract tables that do note use inheritance.
 775	 * @param string &$script The script will be modified in this method.
 776	 */
 777	protected function addGetOMClass_NoInheritance(&$script)
 778	{
 779		$script .= "
 780	/**
 781	 * The class that the Peer will make instances of.
 782	 *
 783	 * This uses a dot-path notation which is tranalted into a path
 784	 * relative to a location on the PHP include_path.
 785	 * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
 786	 *
 787	 * @return string path.to.ClassName
 788	 */
 789	public static function getOMClass()
 790	{
 791		return ".$this->getPeerClassname()."::CLASS_DEFAULT;
 792	}
 793";
 794	}
 795
 796	/**
 797	 * Adds a getOMClass() signature for abstract tables that do not have inheritance.
 798	 * @param string &$script The script will be modified in this method.
 799	 */
 800	protected function addGetOMClass_NoInheritance_Abstract(&$script)
 801	{
 802		$script .= "
 803	/**
 804	 * The class that the Peer will make instances of.
 805	 *
 806	 * This method must be overridden by the stub subclass, because
 807	 * ".$this->getTable()->getPhpName()." is declared abstract in the schema.
 808	 */
 809	abstract public static function getOMClass();
 810";
 811	}
 812
 813	/**
 814	 * Adds the doInsert() method.
 815	 * @param string &$script The script will be modified in this method.
 816	 */
 817	protected function addDoInsert(&$script)
 818	{
 819		$table = $this->getTable();
 820		$script .= "
 821	/**
 822	 * Method perform an INSERT on the database, given a ".$table->getPhpName()." or Criteria object.
 823	 *
 824	 * @param mixed \$values Criteria or ".$table->getPhpName()." object containing data that is used to create the INSERT statement.
 825	 * @param Connection \$con the connection to use
 826	 * @return mixed The new primary key.
 827	 * @throws PropelException Any exceptions caught during processing will be
 828	 *		 rethrown wrapped into a PropelException.
 829	 */
 830	public static function doInsert(\$values, \$con = null)
 831	{
 832		if (\$con === null) {
 833			\$con = Propel::getConnection(self::DATABASE_NAME);
 834		}
 835
 836		if (\$values instanceof Criteria) {
 837			\$criteria = clone \$values; // rename for clarity
 838		} else {
 839			\$criteria = \$values->buildCriteria(); // build Criteria from ".$table->getPhpName()." object
 840		}
 841";
 842
 843		foreach ($table->getColumns() as $col) {
 844			$cfc = $col->getPhpName();
 845			if ($col->isPrimaryKey() && $col->isAutoIncrement() && $table->getIdMethod() != "none") {
 846				$script .= "
 847		\$criteria->remove(".$this->getColumnConstant($col)."); // remove pkey col since this table uses auto-increment
 848";
 849			}
 850		}
 851		$script .= "
 852
 853		// Set the correct dbName
 854		\$criteria->setDbName(self::DATABASE_NAME);
 855
 856		try {
 857			// use transaction because \$criteria could contain info
 858			// for more than one table (I guess, conceivably)
 859			\$con->begin();
 860			\$pk = ".$this->basePeerClassname."::doInsert(\$criteria, \$con);
 861			\$con->commit();
 862		} catch(PropelException \$e) {
 863			\$con->rollback();
 864			throw \$e;
 865		}
 866
 867		return \$pk;
 868	}
 869";
 870	}
 871
 872	/**
 873	 * Adds the doUpdate() method.
 874	 * @param string &$script The script will be modified in this method.
 875	 */
 876	protected function addDoUpdate(&$script)
 877	{
 878		$table = $this->getTable();
 879		$script .= "
 880	/**
 881	 * Method perform an UPDATE on the database, given a ".$table->getPhpName()." or Criteria object.
 882	 *
 883	 * @param mixed \$values Criteria or ".$table->getPhpName()." object containing data that is used to create the UPDATE statement.
 884	 * @param Connection \$con The connection to use (specify Connection object to exert more control over transactions).
 885	 * @return int The number of affected rows (if supported by underlying database driver).
 886	 * @throws PropelException Any exceptions caught during processing will be
 887	 *		 rethrown wrapped into a PropelException.
 888	 */
 889	public static function doUpdate(\$values, \$con = null)
 890	{
 891		if (\$con === null) {
 892			\$con = Propel::getConnection(self::DATABASE_NAME);
 893		}
 894
 895		\$selectCriteria = new Criteria(self::DATABASE_NAME);
 896
 897		if (\$values instanceof Criteria) {
 898			\$criteria = clone \$values; // rename for clarity
 899";
 900		foreach ($table->getColumns() as $col) {
 901			if($col->isPrimaryKey()) {
 902				$script .= "
 903			\$comparison = \$criteria->getComparison(".$this->getColumnConstant($col).");
 904			\$selectCriteria->add(".$this->getColumnConstant($col).", \$criteria->remove(".$this->getColumnConstant($col)."), \$comparison);
 905";
 906			}  /* if col is prim key */
 907	 	} /* foreach */
 908
 909		$script .= "
 910		} else { // \$values is ".$table->getPhpName()." object
 911			\$criteria = \$values->buildCriteria(); // gets full criteria
 912			\$selectCriteria = \$values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
 913		}
 914
 915		// set the correct dbName
 916		\$criteria->setDbName(self::DATABASE_NAME);
 917
 918		return {$this->basePeerClassname}::doUpdate(\$selectCriteria, \$criteria, \$con);
 919	}
 920";
 921	}
 922
 923	/**
 924	 * Adds the doDeleteAll() method.
 925	 * @param string &$script The script will be modified in this method.
 926	 */
 927	protected function addDoDeleteAll(&$script)
 928	{
 929		$table = $this->getTable();
 930		$script .= "
 931	/**
 932	 * Method to DELETE all rows from the ".$table->getName()." table.
 933	 *
 934	 * @return int The number of affected rows (if supported by underlying database driver).
 935	 */
 936	public static function doDeleteAll(\$con = null)
 937	{
 938		if (\$con === null) {
 939			\$con = Propel::getConnection(self::DATABASE_NAME);
 940		}
 941		\$affectedRows = 0; // initialize var to track total num of affected rows
 942		try {
 943			// use transaction because \$criteria could contain info
 944			// for more than one table or we could emulating ON DELETE CASCADE, etc.
 945			\$con->begin();
 946			";
 947			if ($this->isDeleteCascadeEmulationNeeded()) {
 948			    $script .="\$affectedRows += ".$this->getPeerClassname()."::doOnDeleteCascade(new Criteria(), \$con);
 949			";
 950			}
 951			if ($this->isDeleteSetNullEmulationNeeded()) {
 952				$script .= $this->getPeerClassname() . "::doOnDeleteSetNull(new Criteria(), \$con);
 953			";
 954			}
 955			$script .= "\$affectedRows += BasePeer::doDeleteAll(".$this->getPeerClassname()."::TABLE_NAME, \$con);
 956			\$con->commit();
 957			return \$affectedRows;
 958		} catch (PropelException \$e) {
 959			\$con->rollback();
 960			throw \$e;
 961		}
 962	}
 963";
 964	}
 965
 966	/**
 967	 * Adds the doDelete() method.
 968	 * @param string &$script The script will be modified in this method.
 969	 */
 970	protected function addDoDelete(&$script)
 971	{
 972		$table = $this->getTable();
 973		$script .= "
 974	/**
 975	 * Method perform a DELETE on the database, given a ".$table->getPhpName()." or Criteria object OR a primary key value.
 976	 *
 977	 * @param mixed \$values Criteria or ".$table->getPhpName()." object or primary key or array of primary keys
 978	 *              which is used to create the DELETE statement
 979	 * @param Connection \$con the connection to use
 980	 * @return int 	The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
 981	 *				if supported by native driver or if emulated using Propel.
 982	 * @throws PropelException Any exceptions caught during processing will be
 983	 *		 rethrown wrapped into a PropelException.
 984	 */
 985	 public static function doDelete(\$values, \$con = null)
 986	 {
 987		if (\$con === null) {
 988			\$con = Propel::getConnection(".$this->getPeerClassname()."::DATABASE_NAME);
 989		}
 990
 991		if (\$values instanceof Criteria) {
 992			\$criteria = clone \$values; // rename for clarity
 993		} elseif (\$values instanceof ".$table->getPhpName().") {
 994";
 995		if (count($table->getPrimaryKey()) > 0) {
 996			$script .= "
 997			\$criteria = \$values->buildPkeyCriteria();";
 998		} else {
 999			$script .= "
1000			\$criteria = \$values->buildCriteria();";
1001		}
1002
1003		$script .= "
1004		} else {
1005			// it must be the primary key
1006			\$criteria = new Criteria(self::DATABASE_NAME);";
1007
1008		if (count($table->getPrimaryKey()) === 1) {
1009			$pkey = $table->getPrimaryKey();
1010			$col = array_shift($pkey);
1011			$script .= "
1012			\$criteria->add(".$this->getColumnConstant($col).", (array) \$values, Criteria::IN);";
1013		} else {
1014			$script .= "
1015			// primary key is composite; we therefore, expect
1016			// the primary key passed to be an array of pkey
1017			// values
1018			if(count(\$values) == count(\$values, COUNT_RECURSIVE))
1019			{
1020				// array is not multi-dimensional
1021				\$values = array(\$values);
1022			}
1023			\$vals = array();
1024			foreach(\$values as \$value)
1025			{
1026";
1027			$i=0;
1028			foreach($table->getPrimaryKey() as $col) {
1029				$script .= "
1030				\$vals[$i][] = \$value[$i];";
1031				$i++;
1032			}
1033			$script .= "
1034			}
1035";
1036			$i=0;
1037			foreach($table->getPrimaryKey() as $col) {
1038				$script .= "
1039			\$criteria->add(".$this->getColumnConstant($col).", \$vals[$i], Criteria::IN);";
1040				$i++;
1041			}
1042		} /* if count(table->getPrimaryKeys()) */
1043
1044		$script .= "
1045		}
1046
1047		// Set the correct dbName
1048		\$criteria->setDbName(self::DATABASE_NAME);
1049
1050		\$affectedRows = 0; // initialize var to track total num of affected rows
1051
1052		try {
1053			// use transaction because \$criteria could contain info
1054			// for more than one table or we could emulating ON DELETE CASCADE, etc.
1055			\$con->begin();
1056			";
1057
1058		if ($this->isDeleteCascadeEmulationNeeded()) {
1059		    $script .= "\$affectedRows += ".$this->getPeerClassname()."::doOnDeleteCascade(\$criteria, \$con);";
1060		}
1061		if ($this->isDeleteSetNullEmulationNeeded()) {
1062			$script .= $this->getPeerClassname() . "::doOnDeleteSetNull(\$criteria, \$con);";
1063		}
1064
1065		$script .= "
1066			\$affectedRows += {$this->basePeerClassname}::doDelete(\$criteria, \$con);
1067			\$con->commit();
1068			return \$affectedRows;
1069		} catch (PropelException \$e) {
1070			\$con->rollback();
1071			throw \$e;
1072		}
1073	}
1074";
1075	}
1076
1077	/**
1078	 * Adds the doOnDeleteCascade() method, which provides ON DELETE CASCADE emulation.
1079	 * @param string &$script The script will be modified in this method.
1080	 */
1081	protected function addDoOnDeleteCascade(&$script)
1082	{
1083		$table = $this->getTable();
1084		$script .= "
1085	/**
1086	 * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
1087	 * feature (like MySQL or SQLite).
1088	 *
1089	 * This method is not very speedy because it must perform a query first to get
1090	 * the implicated records and then perform the deletes by calling those Peer classes.
1091	 *
1092	 * This method should be used within a transaction if possible.
1093	 *
1094	 * @param Criteria \$criteria
1095	 * @param Connection \$con
1096	 * @return int The number of affected rows (if supported by underlying database driver).
1097	 */
1098	protected static function doOnDeleteCascade(Criteria \$criteria, Connection \$con)
1099	{
1100		// initialize var to track total num of affected rows
1101		\$affectedRows = 0;
1102
1103		// first find the objects that are implicated by the \$criteria
1104		\$objects = ".$this->getPeerClassname()."::doSelect(\$criteria, \$con);
1105		foreach(\$objects as \$obj) {
1106";
1107
1108		foreach ($table->getReferrers() as $fk) {
1109
1110			// $fk is the foreign key in the other table, so localTableName will
1111			// actually be the table name of other table
1112			$tblFK = $fk->getTable();
1113
1114			$joinedTablePeerBuilder = OMBuilder::getNewPeerBuilder($tblFK);
1115			$tblFKPackage = $joinedTablePeerBuilder->getStubPeerBuilder()->getPackage();
1116
1117			if (!$tblFK->isForReferenceOnly()) {
1118				// we can't perform operations on tables that are
1119				// not within the schema (i.e. that we have no map for, etc.)
1120
1121				$fkClassName = $tblFK->getPhpName();
1122
1123				// i'm not sure whether we can allow delete cascade for foreign keys
1124				// within the same table?  perhaps we can?
1125				if ( $fk->getOnDelete() == ForeignKey::CASCADE && $tblFK->getName() != $table->getName()) {
1126
1127					// backwards on purpose
1128					$columnNamesF = $fk->getLocalColumns();
1129					$columnNamesL = $fk->getForeignColumns();
1130
1131					$script .= "
1132
1133			include_once '".$this->getFilePath($tblFKPackage, $tblFK->getPhpName())."';
1134
1135			// delete related $fkClassName objects
1136			\$c = new Criteria();
1137			";
1138					for($x=0,$xlen=count($columnNamesF); $x < $xlen; $x++) {
1139						$columnFK = $tblFK->getColumn($columnNamesF[$x]);
1140						$columnL = $table->getColumn($columnNamesL[$x]);
1141
1142						$script .= "
1143			\$c->add(".$joinedTablePeerBuilder->getColumnConstant($columnFK) .", \$obj->get".$columnL->getPhpName()."());";
1144					}
1145
1146					$script .= "
1147			\$affectedRows += ".$joinedTablePeerBuilder->getPeerClassname()."::doDelete(\$c, \$con);";
1148
1149				} // if cascade && fkey table name != curr table name
1150
1151			} // if not for ref only
1152		} // foreach foreign keys
1153			$script .= "
1154		}
1155		return \$affectedRows;
1156	}
1157";
1158	} // end addDoOnDeleteCascade
1159
1160	/**
1161	 * Adds the doOnDeleteSetNull() method, which provides ON DELETE SET NULL emulation.
1162	 * @param string &$script The script will be modified in this method.
1163	 */
1164	protected function addDoOnDeleteSetNull(&$script)
1165	{
1166		$table = $this->getTable();
1167		$script .= "
1168	/**
1169	 * This is a method for emulating ON DELETE SET NULL DBs that don't support this
1170	 * feature (like MySQL or SQLite).
1171	 *
1172	 * This method is not very speedy because it must perform a query first to get
1173	 * the implicated records and then perform the deletes by calling those Peer classes.
1174	 *
1175	 * This method should be used within a transaction if possible.
1176	 *
1177	 * @param Criteria \$criteria
1178	 * @param Connection \$con
1179	 * @return void
1180	 */
1181	protected static function doOnDeleteSetNull(Criteria \$criteria, Connection \$con)
1182	{
1183
1184		// first find the objects that are implicated by the \$criteria
1185		\$objects = ".$this->getPeerClassname()."::doSelect(\$criteria, \$con);
1186		foreach(\$objects as \$obj) {
1187";
1188
1189		// This logic is almost exactly the same as that in doOnDeleteCascade()
1190		// it may make sense to refactor this, provided that thigns don't
1191		// get too complicated.
1192
1193		foreach ($table->getReferrers() as $fk) {
1194
1195			// $fk is the foreign key in the other table, so localTableName will
1196			// actually be the table name of other table
1197			$tblFK = $fk->getTable();
1198			$refTablePeerBuilder = OMBuilder::getNewPeerBuilder($tblFK);
1199
1200			if (!$tblFK->isForReferenceOnly()) {
1201				// we can't perform operations on tables that are
1202				// not within the schema (i.e. that we have no map for, etc.)
1203
1204				$fkClassName = $tblFK->getPhpName();
1205
1206				// i'm not sure whether we can allow delete setnull for foreign keys
1207				// within the same table?  perhaps we can?
1208				if ( $fk->getOnDelete() == ForeignKey::SETNULL &&
1209						$fk->getTable()->getName() != $table->getName()) {
1210
1211							// backwards on purpose
1212							$columnNamesF = $fk->getLocalColumns();
1213							$columnNamesL = $fk->getForeignColumns(); // should be same num as foreign
1214					$script .= "
1215			// set fkey col in related $fkClassName rows to NULL
1216			\$selectCriteria = new Criteria(".$this->getPeerClassname()."::DATABASE_NAME);
1217			\$updateValues = new Criteria(".$this->getPeerClassname()."::DATABASE_NAME);";
1218
1219					for ($x=0,$xlen=count($columnNamesF); $x < $xlen; $x++) {
1220						$columnFK = $tblFK->getColumn($columnNamesF[$x]);
1221						$columnL = $table->getColumn($columnNamesL[$x]);
1222						$script .= "
1223			\$selectCriteria->add(".$refTablePeerBuilder->getColumnConstant($columnFK).", \$obj->get".$columnL->getPhpName()."());
1224			\$updateValues->add(".$refTablePeerBuilder->getColumnConstant($columnFK).", null);
1225";
1226					}
1227
1228					$script .= "
1229			{$this->basePeerClassname}::doUpdate(\$selectCriteria, \$updateValues, \$con); // use BasePeer because generated Peer doUpdate() methods only update using pkey
1230";
1231				} // if setnull && fkey table name != curr table name
1232			} // if not for ref only
1233		} // foreach foreign keys
1234
1235		$script .= "
1236		}
1237	}
1238";
1239	}
1240
1241	/**
1242	 * Adds the doValidate() method.
1243	 * @param string &$script The script will be modified in this method.
1244	 */
1245	protected function addDoValidate(&$script)
1246	{
1247		$table = $this->getTable();
1248		$script .= "
1249	/**
1250	 * Validates all modified columns of given ".$table->getPhpName()." object.
1251	 * If parameter \$columns is either a single column name or an array of column names
1252	 * than only those columns are validated.
1253	 *
1254	 * NOTICE: This does not apply to primary or foreign keys for now.
1255	 *
1256	 * @param ".$table->getPhpName()." \$obj The object to validate.
1257	 * @param mixed \$cols Column name or array of column names.
1258	 *
1259	 * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
1260	 */
1261	public static function doValidate(".$table->getPhpName()." \$obj, \$cols = null)
1262	{
1263		\$columns = array();
1264
1265		if (\$cols) {
1266			\$dbMap = Propel::getDatabaseMap(".$this->getPeerClassname()."::DATABASE_NAME);
1267			\$tableMap = \$dbMap->getTable(".$this->getPeerClassname()."::TABLE_NAME);
1268
1269			if (! is_array(\$cols)) {
1270				\$cols = array(\$cols);
1271			}
1272
1273			foreach(\$cols as \$colName) {
1274				if (\$tableMap->containsColumn(\$colName)) {
1275					\$get = 'get' . \$tableMap->getColumn(\$colName)->getPhpName();
1276					\$columns[\$colName] = \$obj->\$get();
1277				}
1278			}
1279		} else {
1280";
1281		foreach ($table->getValidators() as $val) {
1282			$col = $val->getColumn();
1283			if (!$col->isAutoIncrement()) {
1284				$script .= "
1285		if (\$obj->isNew() || \$obj->isColumnModified(".$this->getColumnConstant($col)."))
1286			\$columns[".$this->getColumnConstant($col)."] = \$obj->get".$col->getPhpName()."();
1287";
1288			} // if
1289  		} // foreach
1290
1291  		$script .= "
1292		}
1293
1294		return {$this->basePeerClassname}::doValidate(".$this->getPeerClassname()."::DATABASE_NAME, ".$this->getPeerClassname()."::TABLE_NAME, \$columns);
1295	}
1296";
1297	} // end addDoValidate()
1298
1299	/**
1300	 * Adds the retrieveByPK method for tables with single-column primary key.
1301	 * @param string &$script The script will be modified in this method.
1302	 */
1303	protected function addRetrieveByPK_SinglePK(&$script)
1304	{
1305		$table = $this->getTable();
1306		$script .= "
1307	/**
1308	 * Retrieve a single object by pkey.
1309	 *
1310	 * @param mixed \$pk the primary key.
1311	 * @param Connection \$con the connection to use
1312	 * @return " . $table->getPhpName() . "
1313	 */
1314	public static function ".$this->getRetrieveMethodName()."(\$pk, \$con = null)
1315	{
1316		if (\$con === null) {
1317			\$con = Propel::getConnection(self::DATABASE_NAME);
1318		}
1319
1320		\$criteria = new Criteria(".$this->getPeerClassname()."::DATABASE_NAME);
1321";
1322		if (count($table->getPrimaryKey()) === 1) {
1323			$pkey = $table->getPrimaryKey();
1324			$col = array_shift($pkey);
1325			$script .= "
1326		\$criteria->add(".$this->getColumnConstant($col).", \$pk);
1327";
1328		} else {
1329			// primary key is composite; we therefore, expect
1330			// the primary key passed to be an array of pkey
1331			// values
1332			$i=0;
1333			foreach($table->getPrimaryKey() as $col) {
1334	   			$script .= "
1335		\$criteria->add(".$this->getColumnConstant($col).", \$pk[$i]);";
1336				$i++;
1337			}
1338		} /* if count(table.PrimaryKeys) */
1339		$script .= "
1340
1341		\$v = ".$this->getPeerClassname()."::doSelect(\$criteria, \$con);
1342
1343		return !empty(\$v) > 0 ? \$v[0] : null;
1344	}
1345";
1346	}
1347
1348	/**
1349	 * Adds the retrieveByPKs method for tables with single-column primary key.
1350	 * @param string &$script The script will be modified in this method.
1351	 */
1352	protected function addRetrieveByPKs_SinglePK(&$script)
1353	{
1354		$table = $this->getTable();
1355		$script .= "
1356	/**
1357	 * Retrieve multiple objects by pkey.
1358	 *
1359	 * @param array \$pks List of primary keys
1360	 * @param Connection \$con the connection to use
1361	 * @throws PropelException Any exceptions caught during processing will be
1362	 *		 rethrown wrapped into a PropelException.
1363	 */
1364	public static function ".$this->getRetrieveMethodName()."s(\$pks, \$con = null)
1365	{
1366		if (\$con === null) {
1367			\$con = Propel::getConnection(self::DATABASE_NAME);
1368		}
1369
1370		\$objs = null;
1371		if (empty(\$pks)) {
1372			\$objs = array();
1373		} else {
1374			\$criteria = new Criteria();";
1375		if (count($table->getPrimaryKey()) == 1) {
1376			$k1 = $table->getPrimaryKey();
1377			$script .= "
1378			\$criteria->add(".$this->getColumnConstant($k1[0]).", \$pks, Criteria::IN);";
1379		} else {
1380			$script .= "
1381			foreach(\$pks as \$pk) {";
1382			$i = 0;
1383			foreach($table->getPrimaryKey() as $col) {
1384				$script .= "
1385				\$c{$i} = \$criteria->getNewCriterion(".$this->getPeerClassname($col).", \$pk[$i], Criteria::EQUAL);";
1386				$j = $i - 1;
1387				if ($i > 0) {
1388					$script .= "
1389				\$c{$j}->addAnd(\$c{$i});";
1390				} /* if $i > 0 */
1391				$i++;
1392			} /* foreach */
1393
1394			$script .= "
1395
1396				\$criteria->addOr(\$c0);
1397			}";
1398		} /* if count prim keys == 1 */
1399		$script .= "
1400			\$objs = ".$this->getPeerClassname()."::doSelect(\$criteria, \$con);
1401		}
1402		return \$objs;
1403	}
1404";
1405	}
1406
1407	/**
1408	 * Adds the retrieveByPK method for tables with multi-column primary key.
1409	 * @param string &$script The script will be modified in this method.
1410	 */
1411	protected function addRetrieveByPK_MultiPK(&$script)
1412	{
1413		$table = $this->getTable();
1414		$script .= "
1415	/**
1416	 * Retrieve object using using composite pkey values.
1417	 * ";
1418		foreach ($table->getPrimaryKey() as $col) {
1419			$clo = strtolower($col->getName());
1420			$cptype = $col->getPhpNative();
1421			$script .= "@param $cptype $".$clo."
1422	   ";
1423	   }
1424	   $script .= "
1425	 * @param Connection \$con
1426	 * @return ".$table->getPhpName()."
1427	 */
1428	public static function ".$this->getRetrieveMethodName()."(";
1429		$co = 0;
1430		foreach ($table->getPrimaryKey() as $col) {
1431			$clo = strtolower($col->getName());
1432			$script .= ($co++ ? "," : "") . " $".$clo;
1433		} /* foreach */
1434		$script .= ", \$con = null) {
1435		if (\$con === null) {
1436			\$con = Propel::getConnection(self::DATABASE_NAME);
1437		}
1438		\$criteria = new Criteria();";
1439		foreach ($table->getPrimaryKey() as $col) {
1440			$clo = strtolower($col->getName());
1441			$script .= "
1442		\$criteria->add(".$this->getColumnConstant($col).", $".$clo.");";
1443		}
1444		$script .= "
1445		\$v = ".$this->getPeerClassname()."::doSelect(\$criteria, \$con);
1446
1447		return !empty(\$v) ? \$v[0] : null;
1448	}";
1449	}
1450
1451	/**
1452	 * Adds the getTableMap() method which is a convenience method for apps to get DB metadata.
1453	 * @param string &$script The script will be modified in this method.
1454	 */
1455	protected function addGetTableMap(&$script)
1456	{
1457		$script .= "
1458	/**
1459	 * Returns the TableMap related to this peer.
1460	 * This method is not needed for general use but a specific application could have a need.
1461	 * @return TableMap
1462	 * @throws PropelException Any exceptions caught during processing will be
1463	 *		 rethrown wrapped into a PropelException.
1464	 */
1465	public static function getTableMap()
1466	{
1467		return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
1468	}
1469";
1470
1471	}
1472} // PHP5BasicPeerBuilder