[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel-generator/templates/om/php5/ -> Peer.tpl (source)

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


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7