[ 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/php4/ -> Object.tpl (source)

   1  <?php
   2  
   3  // Template for creating an object class.

   4  //

   5  // This is based on the Torque Object.vm Velocity template.  A number of changes

   6  // have, of course, been made to make this PHP.

   7  //

   8  // $Id: Object.tpl,v 1.21 2005/03/19 13:34:59 micha Exp $

   9  
  10  // helper class

  11  include_once 'propel/engine/builder/om/PeerBuilder.php';
  12  include_once 'propel/engine/builder/om/ClassTools.php';
  13  
  14  echo '<' . '?' . 'php';
  15  
  16  $db = $table->getDatabase();
  17  if ($table->getPackage()) {
  18    $package = $table->getPackage();
  19  } else {
  20    $package = $targetPackage;
  21  }
  22  
  23  $parentClass = ClassTools::getBaseClass($table); 
  24  ?>
  25  
  26  require_once '<?php echo ClassTools::getFilePath($parentClass) ?>';
  27  
  28  <?php
  29  if (! $table->isAlias()) 
  30  {
  31    // If any columns in table are BLOB or CLOB then we need to make

  32    // sure those classes are included so we can do things like

  33    // if ($v instanceof Lob) etc.

  34    $includes_lobs = false;
  35  
  36    foreach ($table->getColumns() as $col) {
  37      if ($col->isLob()) {
  38        $includes_lobs = true;
  39        break;
  40      }
  41    }
  42  
  43    if($includes_lobs) 
  44    { 
  45  ?>
  46  include_once 'creole/util/Clob.php';
  47  include_once 'creole/util/Blob.php';
  48  <?php
  49    }
  50  }
  51  ?>
  52  
  53  include_once 'propel/util/Criteria.php';
  54  <?php
  55  foreach ($table->getForeignKeys() as $fk) 
  56  {
  57    $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
  58    $className = $tblFK->getPhpName();
  59    if ($tblFK->getInterface()) {
  60      $className = $tblFK->getInterface();
  61    }
  62  
  63    $tblFKPackage = ($tblFK->getPackage() ? $tblFK->getPackage() : $package);
  64    $tblFKPackagePath = strtr($tblFKPackage, '.', '/');
  65    if ($tblFKPackagePath != "") {
  66      $tblFKPackagePath .= '/';
  67    } 
  68  ?>
  69  
  70  // (on-demand) include_once '<?php echo ClassTools::getFilePath($tblFKPackage, $className) ?>';

  71  // (on-demand) include_once '<?php echo ClassTools::getFilePath($tblFKPackage, $tblFK->getPhpName() . 'Peer') ?>';

  72  <?php 
  73  } /* ($table->getForeignKeys() as $fk) */ 
  74  ?>
  75  
  76  include_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName() . 'Peer') ?>';
  77  
  78  /**

  79   * Base class that represents a row from the '<?php echo $table->getName() ?>' table.

  80   *

  81   * <?php echo $table->getDescription() ?> 

  82   *

  83  <?php if ($addTimeStamp) { ?>

  84   * This class was autogenerated by Propel on:

  85   *

  86   * [<?php echo $now ?>]

  87   *

  88  <?php } ?>

  89   * You should not use this class directly.  It should not even be

  90   * extended; all references should be to <?php echo $table->getPhpName() ?> class.

  91   *

  92   * @package <?php echo $package ?> 

  93   */
  94  class <?php echo $basePrefix . $table->getPhpName() ?> extends <?php echo ClassTools::classname($parentClass) ?> 
  95  {
  96    /**

  97    * The Peer class.

  98    * Instance provides a convenient way of calling static methods on a class

  99    * that calling code may not be able to identify.

 100    * @var <?php echo $table->getPhpName() ?>Peer

 101    */
 102    var $peer;
 103  
 104  <?php
 105  if (! $table->isAlias()) 
 106  {
 107    foreach ($table->getColumns() as $col) 
 108    {
 109      $cptype = $col->getPhpNative();
 110      $clo=strtolower($col->getName());
 111      $defVal = "";
 112      if (($val = $col->getPhpDefaultValue()) !== null) {
 113        settype($val, $cptype);
 114        $defaultValue = var_export($val, true);
 115        $defVal = " = " . $defaultValue;
 116      }
 117  ?>
 118    /**

 119    * The value for the <?php echo $clo ?> field.

 120    * @var <?php echo $cptype ?> 

 121    */
 122    var $<?php echo $clo . $defVal ?>;
 123  
 124  <?php 
 125      if ($col->isLazyLoad()) { 
 126  ?>
 127    /**

 128     * Whether the lazy-loaded <?php echo $clo ?> value has been loaded from database.

 129     * This is necessary to avoid repeated lookups if <?php echo $clo ?> column is NULL.

 130     * @var boolean

 131     */
 132     var $<?php echo $clo ?>_isLoaded = false;
 133  
 134  <?php 
 135      } /* if ($col->isLazyLoad()) */
 136    } /* foreach ($table->getColumns() as $col) */
 137   
 138    foreach ($table->getColumns() as $col) 
 139    {
 140      $cfc=$col->getPhpName();
 141      $clo=strtolower($col->getName());
 142      $cptype = $col->getPhpNative();
 143  
 144      $defaultValue = null;
 145      if (($val = $col->getPhpDefaultValue()) !== null) {
 146        settype($val, $cptype);
 147        $defaultValue = var_export($val, true);
 148      }
 149      
 150      if ($col->getType() === PropelTypes::DATE || $col->getType() === PropelTypes::TIME || $col->getType() === PropelTypes::TIMESTAMP)
 151      {
 152        // these default values are based on the Creole defaults

 153        // the date and time default formats are locale-sensitive

 154        if ($col->getType() === PropelTypes::DATE) {
 155          $defaultfmt = '%x';
 156        } elseif ($col->getType() === PropelTypes::TIME) {
 157          $defaultfmt = '%X';
 158        } elseif ($col->getType() === PropelTypes::TIMESTAMP) {
 159          $defaultfmt = 'Y-m-d H:i:s';
 160        }
 161  ?>
 162    /**

 163    * Get the [optionally formatted] `<?php echo $cfc ?>` value.

 164    * <?php echo $col->getDescription() ?> 

 165    *

 166    * @param string $format The date/time format string (either date()-style or strftime()-style).

 167    *              If format is NULL, then the integer unix timestamp will be returned.

 168    * @return mixed Formatted date/time value as string or integer unix timestamp (if format is NULL) on success,

 169    *               PropelException, if unable to convert the date/time to timestamp.

 170    */
 171    function get<?php echo $cfc ?>($format = '<?php echo $defaultfmt ?>')
 172    {
 173  <?php 
 174        if ($col->isLazyLoad()) { 
 175  ?>
 176      if (! $this-><?php echo $clo ?>_isLoaded && $this-><?php echo $clo ?> === null && !$this->isNew()) {
 177        if (($e = $this->load<?php echo $cfc ?>()) !== true) {
 178          return $e;
 179        }
 180      }
 181  <?php
 182        } /* if ($col->isLazyLoad) */ 
 183  ?>
 184      if ($this-><?php echo $clo ?> === null || $this-><?php echo $clo?> === '') {
 185        return null;
 186      } elseif (!is_int($this-><?php echo $clo ?>)) {
 187        // a non-timestamp value was set externally, so we convert it

 188        $ts = strtotime($this-><?php echo $clo ?>);
 189        if ($ts === -1) {
 190          return new PropelException(PROPEL_ERROR_INVALID, "Unable to parse value of <?php echo $clo ?> as date/time value: " . $this-><?php echo $clo ?>);
 191        }
 192      } else {
 193        $ts = $this-><?php echo $clo ?>;
 194      }
 195      if ($format === null) {
 196        return $ts;
 197      } elseif (strpos($format, '%') !== false) {
 198        return strftime($format, $ts);
 199      } else {
 200        return date($format, $ts);
 201      }
 202    }
 203  
 204  <?php 
 205      } else { /* $col->getType() != DATE | TIME | TIMESTAMP */ 
 206  ?>
 207    /**

 208    * Get the <?php echo $cfc ?> column value.

 209    * <?php echo $col->getDescription() ?> 

 210    *

 211    * @return <?php echo $cptype ?> 

 212    */
 213    function get<?php echo $cfc ?>()
 214    {
 215  <?php 
 216        if ($col->isLazyLoad()) 
 217        { 
 218  ?>
 219      if (! $this-><?php echo $clo ?>_isLoaded && $this-><?php echo $clo ?> === null && !$this->isNew()) {
 220        if (($e = $this->load<?php echo $cfc ?>()) !== true) {
 221          return $e;
 222        }
 223      }
 224  
 225  <?php 
 226        } /* if $col->isLazyLoad */
 227  ?>
 228      return $this-><?php echo $clo ?>;
 229    }
 230  <?php 
 231      } /* $col->getType() != DATE | TIME | TIMESTAMP */
 232  ?>
 233  
 234  <?php 
 235      if ($col->isLazyLoad()) 
 236      { 
 237  ?>
 238    /**

 239    * Load the value for the [lazy-load] `<?php echo $clo ?>` column.

 240    *

 241    * This method performs an additional query to return the value for

 242    * the `<?php echo $clo ?>` column, since it is not populated by

 243    * the hydrate() method.

 244    *

 245    * @return void

 246    * @returns mixed boolean TRUE on success, PropelException - any underlying error will be wrapped and re-thrown.

 247    */
 248    function load<?php echo $cfc ?>()
 249    {
 250      $c = $this->buildPkeyCriteria();
 251      $c->addSelectColumn(<?php echo PeerBuilder::getColumnName($col, $table->getPhpName()) ?>());
 252  
 253      $rs =& <?php echo $table->getPhpName()?>Peer::doSelectRS($c);
 254  
 255      if (Propel::isError($e =& $rs) || Propel::isError($e = $rs->next())) {
 256        return new PropelException(PROPEL_ERROR, "Error loading value for `<?php echo $clo ?>` column on demand.", $e);
 257      }
 258  
 259  <?php
 260        $affix = CreoleTypes::getAffix(CreoleTypes::getCreoleCode($col->getType()));                                    
 261        $clo = strtolower($col->getName());
 262        switch($col->getType()) 
 263        {
 264          case PropelTypes::DATE:                    
 265          case PropelTypes::TIME:
 266          case PropelTypes::TIMESTAMP:
 267  ?>
 268      $this-><?php echo $clo ?> = $rs->get<?php echo $affix ?>(1, null);
 269  <?php
 270            break;
 271          default:
 272  ?>
 273      $this-><?php echo $clo?> = $rs->get<?php echo $affix ?>(1);
 274  <?php   
 275        } /* switch $col->getType */ 
 276  ?>
 277      if (Propel::isError($this-><?php echo $clo?>)) {
 278        return new PropelException(PROPEL_ERROR, "Error loading value for `<?php echo $clo ?>` column on demand.", $this-><?php echo $clo?>);
 279      }
 280        
 281      $this-><?php echo $clo ?>_isLoaded = true;
 282  
 283      return true;
 284    }
 285  
 286  <?php 
 287      } /* if $col->isLazyLoad */ 
 288  
 289      if (! $table->isReadOnly())
 290      {
 291        $throwsClause = "";
 292        if ($complexObjectModel) 
 293        {
 294          if ($col->isForeignKey()) {
 295            $throwsClause = "@throws PropelException";
 296          }
 297          if (count($col->getReferrers()) > 0 ) {
 298            if ($throwsClause == "") {
 299                $throwsClause = "@throws PropelException";
 300            }
 301          }
 302        }
 303        if ($col->getType() === PropelTypes::DATE || $col->getType() === PropelTypes::TIME || $col->getType() === PropelTypes::TIMESTAMP) {
 304          $throwsClause = "@throws PropelException - If passed [not-null] date/time is in an invalid format.";
 305        }
 306  ?>
 307    /**

 308    * Set the value of `<?php echo $cfc ?>`

 309    * <?php echo $col->getDescription() ?> 

 310    *

 311    * @param <?php echo $cptype  ?> $v new value

 312    * @return void

 313    * <?php echo $throwsClause ?> 

 314    */
 315    function set<?php echo $cfc ?>($v)
 316    {
 317  <?php 
 318        if ($col->isLazyLoad()) 
 319        { 
 320  ?>
 321      // explicitly set the is-loaded flag to true for this lazy load col; 

 322      // it doesn't matter if the value is actually set or not (logic below) as

 323      // any attempt to set the value means that no db lookup should be performed

 324      // when the get<?php echo $cfc ?>() method is called. 

 325      $this-><?php echo $clo ?>_isLoaded = true;
 326  <?php 
 327        } /* if $col->isLazyLoad */ 
 328    
 329        if ($addSaveMethod) 
 330        {
 331          if ($col->isLob()) 
 332          {
 333            // Setting of LOB columns gets some special handling

 334            if ($col->getPropelType() === PropelTypes::BLOB || $col->getPropelType() === PropelTypes::LONGVARBINARY ) {
 335              $lobClass = "Blob";
 336            } else {
 337              $lobClass = "Clob";
 338            }
 339  ?>
 340      // if the passed in parameter is the *same* object that

 341      // is stored internally then we use the Lob->isModified()

 342      // method to know whether contents changed.

 343      if (is_a($v, 'Lob') && $v === $this-><?php echo $clo ?>) {
 344        $changed = $v->isModified();
 345      } else {
 346        $changed = ($this-><?php echo $clo ?> !== $v);
 347      }
 348      if ($changed) {
 349        if ( ! is_a($v, 'Lob') ) {
 350          $obj = new <?php echo $lobClass ?>();
 351          $obj->setContents($v);
 352        } else {
 353          $obj =& $v;
 354        }
 355        $this-><?php echo $clo ?> = $obj;
 356        $this->modifiedColumns[] = <?php echo PeerBuilder::getColumnName($col, $table->getPhpName()) ?>();
 357      }
 358  <?php
 359          } 
 360          elseif ($col->getType() === PropelTypes::DATE || $col->getType() === PropelTypes::TIME || $col->getType() === PropelTypes::TIMESTAMP) 
 361          {
 362          // Setting a DATE/TIME value gets some special handling.

 363  ?>
 364      if ($v !== null && !is_int($v)) {
 365        $ts = strtotime($v);
 366        if ($ts === -1) {
 367          return new PropelException(PROPEL_ERROR_INVALID, "Unable to parse date/time value for <?php echo $clo ?> from input: " . var_export($v, true));
 368        }
 369      } else {
 370        $ts = $v;
 371      }
 372  
 373      if ($this-><?php echo $clo ?> !== $ts<?php if ($defaultValue !== null) { ?> || $ts === <?php echo $defaultValue ?><?php } ?>) {
 374        $this-><?php echo $clo ?> = $ts;
 375        $this->modifiedColumns[] = <?php echo PeerBuilder::getColumnName($col, $table->getPhpName()) ?>();
 376      }
 377  <?php
 378          } 
 379          else 
 380          { 
 381            // NORMAL column

 382  ?>
 383      if ($this-><?php echo $clo ?> !== $v<?php if ($defaultValue !== null) { ?> || $v === <?php echo $defaultValue ?><?php } ?>) {
 384        $this-><?php echo $clo ?> = $v;
 385        $this->modifiedColumns[] = <?php echo PeerBuilder::getColumnName($col, $table->getPhpName()) ?>();
 386      }
 387  
 388  <?php 
 389          } /* end normal column */
 390        } /* end $addSaveMethod */ 
 391        else 
 392        {
 393  ?>
 394        $this-><?php echo $clo ?> =& $v;
 395  
 396  <?php
 397        } // if (addSaveMethod)

 398    
 399        if ($complexObjectModel) 
 400        {
 401          if ($col->isForeignKey()) 
 402          {
 403            $tblFK = $table->getDatabase()->getTable($col->getRelatedTableName());
 404            $colFK = $tblFK->getColumn($col->getRelatedColumnName());
 405            if ($col->isMultipleFK() || $col->getRelatedTableName() == $table->getName()) {
 406              $relCol = "";
 407              foreach ($col->getForeignKey()->getLocalColumns() as $columnName) {
 408                  $column = $table->getColumn($columnName);
 409                  $relCol .= $column->getPhpName();
 410              }
 411              if ($relCol != "") {
 412                  $relCol = "RelatedBy".$relCol;
 413              }
 414              $varName = "a".$tblFK->getPhpName() . $relCol;
 415            } else {
 416              $varName = "a".$tblFK->getPhpName();
 417            }
 418  ?>
 419      if ($this-><?php echo $varName ?> !== null && $this-><?php echo $varName ?>->get<?php echo $colFK->getPhpName() ?>() !== $v) {
 420        /*

 421        * Save a reference to null instead of null directly as this would

 422        * overwrite a previous stored <?php echo $tblFK->getPhpName() ?> object.

 423        */
 424        $this-><?php echo $varName ?> =& Propel::null();
 425      }
 426  <?php
 427          } /* if ($col->isForeignKey) */
 428    
 429          foreach ($col->getReferrers() as $fk) 
 430          {
 431            // used to be getLocalForeignMapping() which did not work.

 432            $flmap = $fk->getForeignLocalMapping();
 433            $fkColName = $flmap[$col->getName()];
 434            $tblFK = $fk->getTable();
 435            if ( $tblFK->getName() != $table->getName() ) 
 436            {
 437              $colFK = $tblFK->getColumn($fkColName);
 438              if ($colFK->isMultipleFK()) {
 439                $collName = "coll" . $tblFK->getPhpName() . "sRelatedBy" . $colFK->getPhpName();
 440              } else {
 441                $collName = "coll" . $tblFK->getPhpName() . "s";
 442              }
 443  ?>
 444  
 445        // update associated <?php echo $tblFK->getPhpName() ?>

 446  
 447        if ($this-><?php echo $collName ?> !== null) {
 448            for ($i=0,$size=count($this-><?php echo $collName ?>); $i < $size; $i++) {
 449                $this-><?php echo $collName ?>[$i]->set<?php echo $colFK->getPhpName()?>($v);
 450            }
 451        }
 452  <?php     
 453            } /* if  $tblFk != $table */
 454          } /* foreach referrers */
 455        } /* if complex object model */ 
 456  ?>
 457    }
 458  
 459  <?php
 460      } /* if ! $table->isReadOnly() */ 
 461    } /* foreach ($table->getColumns() as $col) */ 
 462  ?>
 463    /**

 464    * Hydrates (populates) the object variables with values from the database resultset.

 465    *

 466    * An offset (1-based "start column") is specified so that objects can be hydrated

 467    * with a subset of the columns in the resultset rows.  This is needed, for example,

 468    * for results of JOIN queries where the resultset row includes columns from two or

 469    * more tables.

 470    *

 471    * @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.

 472    * @param int $startcol 1-based offset column which indicates which restultset column to start with.

 473    * @return int next starting column

 474    * @throws PropelException  - Any caught Exception will be rewrapped as a PropelException.

 475    */
 476    function hydrate(&$rs, $startcol = 1)
 477    {
 478      assert('is_a($rs, "ResultSet")');
 479  
 480  <?php 
 481    $n = 0;
 482    foreach($table->getColumns() as $col) 
 483    {
 484      if (! $col->isLazyLoad())
 485      {
 486        $affix = CreoleTypes::getAffix(CreoleTypes::getCreoleCode($col->getType()));                                    
 487        $clo = strtolower($col->getName());
 488        switch($col->getType()) 
 489        {
 490          case PropelTypes::DATE:                    
 491          case PropelTypes::TIME:
 492          case PropelTypes::TIMESTAMP:
 493  ?>
 494      if (Creole::isError($value = $rs->get<?php echo $affix ?>($startcol + <?php echo $n ?>, null))) {
 495        return new PropelException(PROPEL_ERROR_DB, "Error populating <?php echo $table->getPhpName()?> object", $value);
 496      }
 497      
 498      $this-><?php echo $clo ?> = $value;
 499  <?php
 500            break;
 501          default:
 502  ?>
 503      if (Creole::isError($value = $rs->get<?php echo $affix ?>($startcol + <?php echo $n ?>))) {
 504        return new PropelException(PROPEL_ERROR_DB, "Error populating object", $value);
 505      }
 506  
 507      $this-><?php echo $clo?> = $value;
 508  <?php
 509        } /* switch */
 510        $n++;
 511      } /* if ! $col->isLazyLoad() */
 512    } /* foreach ($table->getColumns() as $col) */
 513  
 514    if ($addSaveMethod) 
 515    { 
 516  ?>
 517      $this->resetModified();
 518  <?php 
 519    } /* if ($addSaveMethod) */
 520  ?>
 521      $this->setNew(false);
 522      return $startcol + <?php echo $n; ?>;
 523    }
 524      
 525    /**

 526    * Builds a Criteria object containing the primary key for this object.

 527    *

 528    * Unlike buildCriteria() this method includes the primary key values regardless

 529    * of whether or not they have been modified.

 530    * 

 531    * @return Criteria The Criteria object containing value(s) for primary key(s).

 532    */
 533    function &buildPkeyCriteria()
 534    {        
 535      $criteria = new Criteria(<?php echo $table->getPhpName()?>Peer::DATABASE_NAME());
 536  <?php
 537    foreach ($table->getColumns() as $col) 
 538    {
 539      $clo = strtolower($col->getName());
 540      if ($col->isPrimaryKey()) 
 541      { 
 542  ?>
 543      $criteria->add(<?php echo PeerBuilder::getColumnName($col, $table->getPhpName()) ?>(), $this-><?php echo $clo ?>);
 544  <?php
 545      } /* if $col->isPrimaryKey */
 546    } /* foreach ($table->getColumns() as $col) */
 547  ?>
 548      return $criteria;
 549    }
 550      
 551    /**

 552    * Build a Criteria object containing the values of all modified columns in this object.

 553    *

 554    * @return Criteria The Criteria object containing all modified values.

 555    */
 556    function &buildCriteria()
 557    {        
 558      $criteria = new Criteria(<?php echo $table->getPhpName()?>Peer::DATABASE_NAME());
 559  
 560  <?php
 561    foreach ($table->getColumns() as $col) 
 562    {
 563      $clo = strtolower($col->getName());
 564  ?>
 565      if ($this->isColumnModified(<?php echo PeerBuilder::getColumnName($col, $table->getPhpName()) ?>())) { 
 566        $criteria->add(<?php echo PeerBuilder::getColumnName($col, $table->getPhpName()) ?>(), $this-><?php echo $clo ?>);
 567      }
 568  
 569  <?php
 570    } /* foreach */
 571  ?>
 572      return $criteria;
 573    }
 574      
 575  <?php 
 576  } /* if !table->isAlias */ 
 577  
 578  // association code

 579  if ($complexObjectModel) 
 580  {
 581    $pVars = array();  // Array of object set method names for later reference.

 582    $aVars = array();  // Array of object field names for later reference.

 583  
 584    foreach ($table->getForeignKeys() as $fk)
 585    {
 586      $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
 587      $className = $tblFK->getPhpName();
 588  
 589      $tblFKPackage = ($tblFK->getPackage() ? $tblFK->getPackage() : $package);
 590      $tblFKPackagePath = strtr($tblFKPackage, '.', '/');
 591      if ($tblFKPackagePath != "") {
 592          $tblFKPackagePath .= '/';
 593      }
 594  
 595      $relCol = "";
 596      foreach ($fk->getLocalColumns() as $columnName) {
 597        $column = $table->getColumn($columnName);
 598        if ($column->isMultipleFK() || $fk->getForeignTableName() == $table->getName()) {
 599          $relCol .= $column->getPhpName();
 600        }
 601      }
 602  
 603      if ($relCol != "") {
 604        $relCol = "RelatedBy" . $relCol;
 605      }
 606  
 607      $pVarName = $className . $relCol;
 608      $varName = "a" . $pVarName;
 609      $retVal = ($pVars[] = $pVarName);
 610      $retVal = ($aVars[] = $varName);
 611  ?>
 612    /**

 613    * @var <?php echo $className ?>

 614    */
 615    var $<?php echo $varName ?>;
 616  
 617    /**

 618    * Declares an association between this object and a <?php echo $className ?> object

 619    *

 620    * @param <?php echo $className ?> $v

 621    * @return void

 622    * @throws PropelException

 623    */
 624    function set<?php echo $pVarName ?>(&$v)
 625    {
 626  <?php
 627      foreach ($fk->getLocalColumns() as $columnName) 
 628      {
 629        $column = $table->getColumn($columnName);
 630        $lfmap = $fk->getLocalForeignMapping();
 631        $colFKName = $lfmap[$columnName];
 632        $colFK = $tblFK->getColumn($colFKName);
 633  ?>
 634      if ($v === null) {
 635        $this->set<?php echo $column->getPhpName() ?>(<?php echo var_export($column->getPhpDefaultValue()) ?>);
 636      } else {
 637        $this->set<?php echo $column->getPhpName() ?>($v->get<?php echo $colFK->getPhpName() ?>());
 638      }
 639  
 640  <?php 
 641      } /* foreach local col */ 
 642  ?>
 643      $this-><?php echo $varName ?> =& $v;
 644    }
 645  
 646  <?php
 647      $and = "";
 648      $comma = "";
 649      $conditional = "";
 650      $arglist = "";
 651      $argsize = 0;
 652      foreach ($fk->getLocalColumns() as $columnName) 
 653      {
 654        $column = $table->getColumn($columnName);
 655        $cptype = $column->getPhpNative();
 656        $clo = strtolower($column->getName());
 657        if ($cptype == "integer" || $cptype == "float" || $cptype == "double") {
 658          $conditional .= $and . "\$this->". $clo ." > 0";
 659        } elseif($cptype == "string") {
 660          $conditional .= $and . "(\$this->" . $clo ." !== \"\" && \$this->".$clo." !== null)";
 661        } else {
 662          $conditional .= $and . "\$this->" . $clo ." !== null";
 663        }
 664        $arglist .= $comma . "\$this->" . $clo;
 665        $and = " && ";
 666        $comma = ", ";
 667        $argsize = $argsize + 1;
 668      }
 669  
 670      $pCollName = $table->getPhpName() . 's' . $relCol;
 671  ?>
 672    /**

 673    * Get the associated <?php echo $className ?> object

 674    *

 675    * @return <?php echo $className ?> The associated <?php echo $className ?> object.

 676    * @throws PropelException

 677    */
 678    function & get<?php echo $pVarName ?>()
 679    {
 680      // include the Peer class

 681      include_once '<?php echo $tblFKPackagePath . $className ?>Peer.php';
 682  
 683      if ($this-><?php echo $varName ?> === null && (<?php echo $conditional ?>))
 684      {
 685  <?php
 686      if ($tblFK->isAlias()) 
 687      {
 688        if ($argsize > 1) {
 689  ?>
 690        $<?php echo $varName ?> =& <?php echo $className ?>Peer::retrieve<?php echo $className ?>ByPK(<?php echo $arglist ?>);
 691  <?php
 692        } else { 
 693  ?>
 694        $<?php echo $varName ?> =& <?php echo $className ?>Peer::retrieve<?php echo $className ?>ByPK(<?php echo $arglist ?>);
 695  <?php    
 696        } /* if ($argsize > 1) */
 697      } 
 698      else 
 699      {
 700        if ($argsize > 1) {
 701  ?>
 702        $<?php echo $varName ?> =& <?php echo $className ?>Peer::retrieveByPK(<?php echo $arglist ?>);
 703  <?php
 704        } else { 
 705  ?>
 706        $<?php echo $varName ?> =& <?php echo $className ?>Peer::retrieveByPK(<?php echo $arglist ?>);
 707  <?php 
 708        }
 709      } // if tblFK->isAlias

 710  ?>
 711        if (Propel::isError($<?php echo $varName ?>)) { return $<?php echo $varName ?>; }
 712  
 713        $this-><?php echo $varName ?> =& $<?php echo $varName ?>;
 714  
 715        /* The following can be used instead of the line above to

 716           guarantee the related object contains a reference

 717           to this object, but this level of coupling

 718           may be undesirable in many circumstances.

 719           As it can lead to a db query with many results that may

 720           never be used.

 721           $obj = <?php echo $className ?>Peer::retrieveByPK(<?php echo $arglist ?>);

 722           $obj->add<?php echo $pCollName ?>($this);

 723         */
 724      }
 725  
 726      return $this-><?php echo $varName ?>;
 727    }
 728  
 729    /**

 730    * Provides convenient way to set a relationship based on a

 731    * key.  e.g.

 732    * <code>$bar->setFooKey($foo->getPrimaryKey())</code>

 733    *

 734  <?php 

 735      if (count($fk->getLocalColumns()) > 1) { 

 736  ?>

 737    * Note: It is important that the xml schema used to create this class

 738    * maintains consistency in the order of related columns between

 739    * <?php echo $table->getName() ?> and <?php echo $tblFK->getName() ?>.

 740    * If for some reason this is impossible, this method should be

 741    * overridden in <code><?php echo $table->getPhpName() ?></code>.

 742  <?php 

 743      } 

 744  ?>

 745    * @return void

 746    * @throws PropelException

 747    */
 748    function set<?php echo $pVarName ?>Key($key)
 749    {
 750  <?php 
 751      if (count($fk->getLocalColumns()) > 1) 
 752      {
 753        $i = 0;
 754        foreach ($fk->getLocalColumns() as $colName) 
 755        {
 756          $col = $table->getColumn($colName);
 757          $fktype = $col->getPhpNative();
 758  ?>
 759      $this->set<?php echo $col->getPhpName() ?>( (<?php echo $fktype ?>) $key[<?php echo $i ?>] );
 760  <?php
 761          $i++;
 762        } /* foreach */
 763      } else {
 764        $lcols = $fk->getLocalColumns();
 765        $colName = $lcols[0];
 766        $col = $table->getColumn($colName);
 767        $fktype = $col->getPhpNative();
 768  ?>
 769      $this->set<?php echo $col->getPhpName() ?>( (<?php echo $fktype ?>) $key);
 770  <?php 
 771      } 
 772  ?>
 773    }
 774  
 775  <?php 
 776    } /*  end of foreach loop over foreign keys */
 777  
 778    //

 779    // setup foreign key associations

 780    //

 781    foreach ($table->getReferrers() as $fk) 
 782    {
 783      $tblFK = $fk->getTable();
 784      $tblFKPackage = ($tblFK->getPackage() ? $tblFK->getPackage() : $package);
 785      $tblFKPackagePath = strtr($tblFKPackage, '.', '/');
 786      if ($tblFKPackagePath != "") {
 787          $tblFKPackagePath .= '/';
 788      }
 789  
 790      $className = $tblFK->getPhpName();
 791      $relatedByCol = "";
 792      foreach ($fk->getLocalColumns() as $columnName) {
 793        $column = $tblFK->getColumn($columnName);
 794        if ($column->isMultipleFK() || $tblFK->getName() == $table->getName()) {
 795          // if there are seeral foreign keys that point to the same table

 796          // then we need to generate methods like getAuthorRelatedByColName()

 797          // instead of just getAuthor().  Currently we are doing the same

 798          // for self-referential foreign keys, to avoid confusion.

 799          $relatedByCol .= $column->getPhpName();
 800        }
 801      }
 802  
 803      if ($relatedByCol == "") {
 804        $suffix = "";
 805        $relCol = $className . "s";
 806        $relColMs = $className;
 807      } else {
 808        $suffix = "RelatedBy" . $relatedByCol;
 809        $relCol= $className . "sRelatedBy" . $relatedByCol;
 810        $relColMs= $className . "RelatedBy" . $relatedByCol;
 811      }
 812      $collName = "coll" . $relCol;
 813  ?>
 814    /**

 815    * Collection to store aggregation of <?php echo $collName ?>

 816    * @var array

 817    */
 818    var $<?php echo $collName ?>;
 819  
 820    /**

 821    * Temporary storage of <?php echo $collName ?> to save a possible db hit in

 822    * the event objects are add to the collection, but the

 823    * complete collection is never requested.

 824    * @return void

 825    */
 826    function init<?php echo $relCol ?>()
 827    {
 828      if ($this-><?php echo $collName ?> === null) {
 829        $this-><?php echo $collName ?> = array();
 830      }
 831    }
 832  
 833    /**

 834    * Method called to associate a <?php echo $tblFK->getPhpName() ?> object to this object

 835    * through the <?php echo $className ?> foreign key attribute

 836    *

 837    * @param <?php echo $className ?> $l $className

 838    * @return void

 839    * @throws PropelException

 840    */
 841    function add<?php echo $relColMs ?>(/*<?php echo $className ?>*/ &$l)
 842    {
 843      $this-><?php echo $collName ?>[] =& $l;
 844      $l->set<?php echo $table->getPhpName() . $suffix ?>($this);
 845    }
 846  
 847    /**

 848    * The criteria used to select the current contents of <?php echo $collName ?>.

 849    * @var Criteria

 850    */
 851    var $last<?php echo $relCol ?>Criteria = null;
 852  
 853      /**

 854       * Returns the number of related <?php echo $relCol ?>

 855       *

 856       * @param Criteria $criteria

 857       * @param boolean $distinct

 858       * @throws PropelException

 859       */
 860  	function count<?php echo $relCol ?>($criteria = null, $distinct = false)
 861      {
 862          // include the Peer class

 863          include_once '<?php echo $tblFKPackagePath . $className ?>Peer.php';
 864          if ($criteria === null) {
 865              $criteria = new Criteria();
 866          }
 867  <?php
 868      foreach ($fk->getForeignColumns() as $columnName) {
 869          $column = $table->getColumn($columnName);
 870          // used to be getLocalForeignMapping() but that didn't seem to work

 871          // (maybe a problem in translation of HashTable code to PHP).

 872          $flmap = $fk->getForeignLocalMapping();
 873          $colFKName = $flmap[$columnName];
 874          $colFK = $tblFK->getColumn($colFKName);
 875  ?>
 876          $criteria->add(<?php echo PeerBuilder::getColumnName($colFK, $className) ?>(), $this->get<?php echo $column->getPhpName() ?>() );
 877  <?php
 878      } // end foreach ($fk->getForeignColumns()

 879  ?>
 880          return <?php echo $className ?>Peer::doCount($criteria, $distinct);
 881      }
 882  
 883    /**

 884    * If this collection has already been initialized with

 885    * an identical criteria, it returns the collection.

 886    * Otherwise if this <?php echo $table->getPhpName() ?> has previously

 887    * been saved, it will retrieve related ${relCol} from storage.

 888    * If this <?php echo $table->getPhpName() ?> is new, it will return

 889    * an empty collection or the current collection, the criteria

 890    * is ignored on a new object.

 891    *

 892    * @param Criteria $criteria

 893    * @throws PropelException

 894    */
 895    function & get<?php echo $relCol ?>($criteria = null)
 896    {
 897      // include the Peer class

 898      include_once '<?php echo $tblFKPackagePath . $className ?>Peer.php';
 899  
 900      if ($criteria === null) {
 901        $criteria = new Criteria();
 902      }
 903  
 904      if ($this-><?php echo $collName ?> === null)
 905      {
 906        if ($this->isNew()) {
 907          $this-><?php echo $collName ?> = array();
 908        } else {
 909  <?php
 910      foreach ($fk->getForeignColumns() as $columnName)
 911      {
 912        $column = $table->getColumn($columnName);
 913        // used to be getLocalForeignMapping() but that didn't seem to work

 914        // (maybe a problem in translation of HashTable code to PHP).

 915        $flmap = $fk->getForeignLocalMapping();
 916        $colFKName = $flmap[$columnName];
 917        $colFK = $tblFK->getColumn($colFKName);
 918  ?>
 919          $criteria->add(<?php echo PeerBuilder::getColumnName($colFK, $className) ?>(), $this->get<?php echo $column->getPhpName() ?>() );
 920  <?php 
 921      } /* end foreach ($fk->getForeignColumns()) */
 922  ?>
 923  
 924          $<?php echo $collName ?> =& <?php echo $className ?>Peer::doSelect($criteria);
 925          if (Propel::isError($<?php echo $collName ?>)) { return $<?php echo $collName ?>; }
 926  
 927          $this-><?php echo $collName ?> =& $<?php echo $collName ?>;
 928        }
 929      } else {
 930        // criteria has no effect for a new object

 931        if (!$this->isNew())
 932        {
 933          // the following code is to determine if a new query is

 934          // called for.  If the criteria is the same as the last

 935          // one, just return the collection.

 936  <?php
 937      foreach ($fk->getForeignColumns() as $columnName)
 938      {
 939        $column = $table->getColumn($columnName);
 940        $flmap = $fk->getForeignLocalMapping();
 941        $colFKName = $flmap[$columnName];
 942        $colFK = $tblFK->getColumn($colFKName);
 943  ?>
 944          $criteria->add(<?php echo PeerBuilder::getColumnName($colFK, $className) ?>(), $this->get<?php echo $column->getPhpName() ?>());
 945  
 946  <?php 
 947      } /* end foreach ($fk->getForeignColumns()) */
 948  ?>
 949          if (!isset($this->last<?php echo $relCol ?>Criteria) || !$this->last<?php echo $relCol ?>Criteria->equals($criteria))
 950          {
 951            $<?php echo $collName ?> =& <?php echo $className ?>Peer::doSelect($criteria);
 952            if (Propel::isError($<?php echo $collName ?>)) { return $<?php echo $collName ?>; }
 953  
 954            $this-><?php echo $collName ?> =& $<?php echo $collName ?>;
 955          }
 956        }
 957      }
 958  
 959      $this->last<?php echo $relCol ?>Criteria = $criteria;
 960  
 961      return $this-><?php echo $collName ?>;
 962    }
 963  
 964  <?php
 965      $countFK = 0;
 966      foreach ($tblFK->getForeignKeys() as $dummyFK) {
 967        $countFK = $countFK + 1;
 968      }
 969  
 970  // ------------------------------------------------------------

 971  //

 972      if ($countFK >= 1)
 973      {
 974        $lastTable = "";
 975        foreach ($tblFK->getForeignKeys() as $fk2)
 976        {
 977          // Add join methods if the fk2 table is not this table or

 978          // the fk2 table references this table multiple times.

 979  
 980          $doJoinGet = true;
 981          if ( $fk2->getForeignTableName() == $table->getName() ) {
 982            $doJoinGet = false;
 983          }
 984  
 985          foreach ($fk2->getLocalColumns() as $columnName) {
 986            $column = $tblFK->getColumn($columnName);
 987            if ($column->isMultipleFK()) {
 988              $doJoinGet = true;
 989            }
 990          }
 991  
 992          $tblFK2 = $table->getDatabase()->getTable($fk2->getForeignTableName());
 993          $doJoinGet = !$tblFK2->isForReferenceOnly();
 994          $relatedByCol2 = "";
 995          foreach ($fk2->getLocalColumns() as $columnName) {
 996            $column = $tblFK->getColumn($columnName);
 997            if ($column->isMultipleFK()) {
 998              $relatedByCol2 .= $column->getPhpName();
 999            }
1000          }
1001  
1002          $fkClassName = $tblFK2->getPhpName();
1003  
1004          // do not generate code for self-referencing fk's, it would be

1005          // good to do, but it is just not implemented yet.

1006          if ($className == $fkClassName) {
1007            // $doJoinGet = false;  -- SELF REFERENCING FKs UNDER TESTING

1008          }
1009  
1010          if ($relatedByCol2 == "") {
1011            $relCol2 = $fkClassName;
1012          } else {
1013            $relCol2 = $fkClassName . "RelatedBy". $relatedByCol2;
1014          }
1015  
1016          if ( $relatedByCol == "") {
1017            // nothing?

1018          } else {
1019            if ( $relatedByCol == $relatedByCol2 ) {
1020              $doJoinGet = false;
1021            }
1022          }
1023  
1024          if ($doJoinGet)
1025          {
1026  ?>
1027    /**

1028    * If this collection has already been initialized with

1029    * an identical criteria, it returns the collection.

1030    * Otherwise if this <?php echo $table->getPhpName() ?> is new, it will return

1031    * an empty collection; or if this <?php echo $table->getPhpName() ?> has previously

1032    * been saved, it will retrieve related <?php echo $relCol ?> from storage.

1033    *

1034    * This method is protected by default in order to keep the public

1035    * api reasonable.  You can provide public methods for those you

1036    * actually need in <?php echo $table->getPhpName() ?>.

1037    */
1038    function & get<?php echo $relCol ?>Join<?php echo $relCol2 ?>($criteria = null)
1039    {
1040      // include the Peer class

1041      include_once '<?php echo $tblFKPackagePath . $className ?>Peer.php';
1042  
1043      if ($criteria === null) {
1044        $criteria = new Criteria();
1045      }
1046      
1047      if ($this-><?php echo $collName ?> === null) {
1048        if ($this->isNew()) {
1049           $this-><?php echo $collName ?> = array();
1050        } else {
1051  <?php 
1052            foreach ($fk->getForeignColumns() as $columnName)
1053            {
1054              $column = $table->getColumn($columnName);
1055              $flMap = $fk->getForeignLocalMapping();
1056              $colFKName = $flMap[$columnName];
1057              $colFK = $tblFK->getColumn($colFKName);
1058  ?>
1059          $criteria->add(<?php echo PeerBuilder::getColumnName($colFK, $className) ?>(), $this->get<?php echo $column->getPhpName() ?>());
1060  <?php 
1061            } /* end foreach ($fk->getForeignColumns()) */
1062  ?>
1063  
1064          $<?php echo $collName ?> =& <?php echo $className ?>Peer::doSelectJoin<?php echo $relCol2 ?>($criteria);
1065          if (Propel::isError($<?php echo $collName ?>)) { return $<?php echo $collName ?>; }
1066  
1067          $this-><?php echo $collName ?> =& $<?php echo $collName ?>;
1068        }
1069      } else {
1070        // the following code is to determine if a new query is

1071        // called for.  If the criteria is the same as the last

1072        // one, just return the collection.

1073  <?php
1074            foreach ($fk->getForeignColumns() as $columnName)
1075            {
1076              $column = $table->getColumn($columnName);
1077              $flMap = $fk->getForeignLocalMapping();
1078              $colFKName = $flMap[$columnName];
1079              $colFK = $tblFK->getColumn($colFKName);
1080  ?>
1081        $criteria->add(<?php echo PeerBuilder::getColumnName($colFK, $className) ?>(), $this->get<?php echo $column->getPhpName() ?>());
1082  
1083  <?php 
1084            } /* end foreach ($fk->getForeignColumns()) */
1085  ?>
1086        if (!isset($this->last<?php echo $relCol ?>Criteria) || !$this->last<?php echo $relCol ?>Criteria->equals($criteria))
1087        {
1088          $<?php echo $collName ?> =& <?php echo $className ?>Peer::doSelectJoin<?php echo $relCol2 ?>($criteria);
1089          if (Propel::isError($<?php echo $collName ?>)) { return $<?php echo $collName ?>; }
1090  
1091          $this-><?php echo $collName ?> =& $<?php echo $collName ?>;
1092        }
1093      }
1094      $this->last<?php echo $relCol ?>Criteria = $criteria;
1095  
1096      return $this-><?php echo $collName ?>;
1097    }
1098    
1099  <?php 
1100          } /* end if($doJoinGet) */
1101        } /* end foreach ($tblFK->getForeignKeys() as $fk2) {*/
1102      } /* if countFK >= 1 */
1103    } /*ends foreach over table->getReferrers() */
1104  } /* the if(complexObjectModel) */
1105  
1106  //

1107  // add GenericAccessors or GenericMutators?

1108  //

1109  if (!$table->isAlias() && ($addGenericAccessors || ($addGenericMutators && !$table->isReadOnly())))
1110  {
1111      $tableColumns = $table->getColumns();
1112      $tablePhpname = $table->getPhpName();
1113  ?>
1114    /**

1115     * Generate a list of field names.

1116     *

1117     * @return array A list of field names

1118     */
1119    function & getFieldNames($type = TYPE_FIELDNAME)
1120    {
1121      static $fieldNames = array(
1122        TYPE_PHPNAME => array (<?php foreach ($tableColumns as $col) { ?>'<?php echo $col->getPhpName(); ?>', <?php } ?>),
1123        TYPE_COLNAME => array (<?php foreach ($tableColumns as $col) { ?>'<?php echo $table->getName() . '.' . strtoupper($col->getName()) ?>', <?php } ?>),
1124        TYPE_FIELDNAME => array (<?php foreach ($tableColumns as $col) { ?>'<?php echo $col->getName(); ?>', <?php } ?>),
1125        TYPE_NUM => array (<?php foreach ($tableColumns as $num => $col) { echo $num; ?>, <?php } ?>)
1126      );
1127      
1128      if (!isset($fieldNames[$type])) {
1129        return 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.');
1130      }
1131      
1132      return $fieldNames[$type];
1133    }
1134    
1135    /**

1136     * Translates a fieldname to another type

1137     *

1138     * @param string $name field name

1139     * @param string $fromType One of the class type constants TYPE_PHPNAME,

1140     *                         TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM

1141     * @param string $toType   One of the class type constants

1142     * @return string translated name of the field.

1143     */
1144    function translateFieldName($name, $fromType, $toType)
1145    {
1146      static $fieldKeys = array (
1147        TYPE_PHPNAME => array (<?php foreach ($tableColumns as $num => $col) { ?>'<?php echo $col->getPhpName(); ?>' => <?php echo $num; ?>, <?php } ?>),
1148        TYPE_COLNAME => array (<?php foreach ($tableColumns as $num => $col) { ?>'<?php echo $table->getName() . '.' . strtoupper($col->getName()) ?>' => <?php echo $num; ?>, <?php } ?>),
1149        TYPE_FIELDNAME => array (<?php foreach ($tableColumns as $num => $col) { ?>'<?php echo $col->getName(); ?>' => <?php echo $num; ?>, <?php } ?>),
1150        TYPE_NUM => array (<?php foreach ($tableColumns as $num => $col) { echo $num; ?>, <?php } ?>)
1151      );
1152  
1153      $toNames =& $this->getFieldNames($toType);
1154      $key = $fieldKeys[$fromType][$name];
1155      
1156      if ($key === false) {
1157        return new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r($fromNames, true));
1158      }
1159      
1160      return $toNames[$key];
1161    }
1162  <?php if ($addGenericAccessors) { ?>
1163  
1164    /**

1165     * Retrieves a field from the object by name passed in as a string.

1166     *

1167     * @param string $name name

1168     * @param string $type The type of fieldname the $name is of:

1169     *                     one of the class type constants TYPE_PHPNAME,

1170     *                     TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM

1171     * @return mixed Value of field.

1172     */
1173    function & getByName($name, $type = TYPE_COLNAME)
1174    {
1175      $pos = $this->translateFieldName($name, $type, TYPE_NUM);
1176      return $this->getByPosition($pos);
1177    }
1178  
1179    /**

1180     * Retrieves a field from the object by Position as specified

1181     * in the xml schema.  Zero-based.

1182     *

1183     * @param int $pos position in xml schema

1184     * @return mixed Value of field at $pos

1185     */
1186    function & getByPosition($pos)
1187    {
1188      switch($pos) 
1189      {
1190  <?php
1191        $i = 0;
1192        foreach ($table->getColumns() as $col) 
1193        {
1194          $cfc = $col->getPhpName();
1195          $cptype = $col->getPhpNative();// not safe to use it because some methods may return objects (Blob)

1196  ?>
1197        case <?php echo $i ?>:
1198          return $this->get<?php echo $cfc ?>();
1199          break;
1200  <?php
1201          $i++;
1202        } /* foreach */
1203  ?>
1204        default:
1205          return null;
1206      } // switch()

1207    }
1208  
1209    /**

1210     * Exports the object as an array.

1211     *

1212     * You can specify the key type of the array by passing one of the class

1213     * type constants.

1214     *

1215     * @param string $keyType One of the class type constants TYPE_PHPNAME,

1216     *                        TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM

1217     * @return an associative array containing the field names (as keys) and field values

1218     */
1219    function & toArray($keyType = TYPE_PHPNAME)
1220    {
1221      $keys =& $this->getFieldNames($keyType);
1222      $result = array(
1223  <?php
1224        foreach ($table->getColumns() as $num => $col) {
1225  ?>
1226        $keys[<?php echo $num ?>] => $this->get<?php echo $col->getPhpName() ?>(),
1227  <?php
1228        } /* foreach */
1229  ?>
1230      );
1231      return $result;
1232    }
1233  
1234  <?php } /* ends the if($addGenericAccessors) */ ?>
1235  
1236  
1237  <?php if ($addGenericMutators && !$table->isReadOnly()) { ?>
1238  
1239    /**

1240     * Sets a field value from the object by name passed in as a string.

1241     *

1242     * @param string $name peer name

1243     * @param mixed $value field value

1244     * @param string $type The type of fieldname the $name is of:

1245     *                     one of the class type constants TYPE_PHPNAME,

1246     *                     TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM

1247     * @return void

1248     */
1249    function setByName($name, &$value, $type = TYPE_COLNAME)
1250    {
1251      $names =& $this->getFieldnames($type);
1252      $pos = array_search($name, $names);
1253      return $this->setByPosition($pos, $value);
1254    }
1255    
1256    /**

1257     * Sets a field from the object by Position as specified

1258     * in the xml schema.  Zero-based.

1259     *

1260     * @param int $pos position in xml schema

1261     * @param mixed $value field value

1262     * @return void

1263     */
1264    function setByPosition($pos, &$value)
1265    {
1266      switch($pos) 
1267      {
1268  <?php
1269      $i = 0;
1270      foreach ($table->getColumns() as $col) 
1271      {
1272        $cfc = $col->getPhpName();
1273        $cptype = $col->getPhpNative();
1274  ?>
1275        case <?php echo $i ?>:
1276            $this->set<?php echo $cfc ?>($value);
1277            break;
1278  <?php
1279        $i++;
1280      } /* foreach */
1281  ?>
1282      } // switch()

1283    }
1284  
1285    /**

1286     * Populates the object using an array.

1287     *

1288     * This is particularly useful when populating an object from one of the

1289     * request arrays (e.g. $_POST).  This method goes through the column

1290     * names, checking to see whether a matching key exists in populated

1291     * array. If so the setByName() method is called for that column.

1292     *

1293     * You can specify the key type of the array by additionally passing one

1294     * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,

1295     * TYPE_NUM. The default key type is the (peer) column name (e.g.

1296     * 'book.AUTHOR_ID')

1297     *

1298     * @param array  $arr     An array to populate the object from.

1299     * @param string $keyType The type of keys the array uses.

1300     * @return void

1301     */
1302    function fromArray(&$arr, $keyType = TYPE_COLNAME)
1303    {
1304      $keys =& $this->getFieldNames($keyType);
1305  <?php
1306      foreach ($table->getColumns() as $num => $col) {
1307        $cfc = $col->getPhpName();
1308        $cptype = $col->getPhpNative();
1309  ?>
1310      if (array_key_exists($keys[<?php echo $num ?>], $arr)) $this->set<?php echo $cfc ?>($arr[$keys[<?php echo $num ?>]]);
1311  <?php
1312      } /* foreach */
1313  ?>
1314    }
1315  
1316  <?php } /* ends the if($addGenericMutators) */
1317      } /* ends the if($addGenericAccessors || $addGenericMutators) */
1318  ?>
1319  
1320  <?php if (! $table->isAlias() && isset($addSaveMethod) && $addSaveMethod && ! $table->isReadOnly()) { ?>
1321  
1322    /**

1323    * Removes this object from datastore and sets delete attribute.

1324    *

1325    * @return mixed TRUE on success, PropelException on failure.

1326    * @throws PropelException

1327    * @see BaseObject::setDeleted()

1328    * @see BaseObject::isDeleted()

1329    */
1330    function delete()
1331    {
1332      if ($this->isDeleted()) {
1333        return new PropelException(PROPEL_ERROR, "This object has already been deleted.");
1334      }
1335  
1336      $con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
1337      if (Propel::isError($con)) { return $con; }
1338  
1339      $e = $con->begin();
1340      if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
1341  
1342      $e = <?php echo $table->getPhpName() ?>Peer::doDelete($this, Param::set($con));
1343      if (Propel::isError($e)) { $con->rollback(); return $e; }
1344  
1345      $this->setDeleted(true);
1346  
1347      $e = $con->commit();
1348      if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
1349  
1350      return true;
1351    }
1352  
1353  <?php
1354    if ($complexObjectModel) 
1355    { 
1356  ?>
1357  
1358    /**

1359    * flag to prevent endless save loop, if this object is referenced

1360    * by another object which falls in this transaction.

1361    * @var boolean

1362    */
1363    var $alreadyInSave = false;
1364  
1365    /**

1366    * Stores the object in the database.  If the object is new,

1367    * it inserts it; otherwise an update is performed.  This method

1368    * wraps the doSave() worker method in a transaction.

1369    *

1370    * @return mixed TRUE on success, PropelException on failure.

1371    */
1372    function save()
1373    {
1374      if ($this->isDeleted()) {
1375        return new PropelException(PROPEL_ERROR, "You cannot save an object that has been deleted.");
1376      }
1377  
1378      $con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
1379      if (Propel::isError($con)) { return $con; }
1380  
1381      $e = $con->begin();
1382      if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
1383  
1384      $e = $this->doSave(Param::set($con));
1385      if (Propel::isError($e)) { $con->rollback(); return $e; }
1386  
1387      $e = $con->commit();
1388      if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
1389  
1390      return true;
1391    }
1392  <?php 
1393    } /* if($complexObjectModel) */ 
1394  ?>
1395  
1396    /**

1397    * Stores the object in the database.  If the object is new,

1398    * it inserts it; otherwise an update is performed.

1399    *

1400    * @return void

1401    * @throws PropelException

1402    */
1403  <?php 
1404    if ($complexObjectModel) 
1405    { 
1406  ?>
1407    function doSave($con = null)
1408  <?php 
1409    } else { 
1410  ?>
1411    function save()
1412  <?php 
1413    }
1414  ?>
1415    {
1416  <?php 
1417    if(! $complexObjectModel) 
1418    { 
1419  ?>    if ($this->isDeleted()) {
1420        return new PropelException(PROPEL_ERROR, "You cannot save an object that has been deleted.");
1421      }
1422  
1423      $con =& Propel::getConnection(<?php echo $basePrefix . $table->getPhpName() ?>Peer::DATABASE_NAME());
1424      if (Propel::isError($con)) { return $con; }
1425  
1426  <?php 
1427    }
1428  
1429    if ($complexObjectModel) 
1430    { 
1431  ?>
1432      /* [MA] temporarily check */

1433      Propel::assertParam($con, '<?php echo $table->getPhpName(); ?>', 'save', 1);
1434  
1435      if (! $this->alreadyInSave) {
1436        $this->alreadyInSave = true;
1437  
1438  <?php 
1439      if ( ! empty($pVars)) 
1440      { 
1441  ?>
1442        // We call the save method on the following object(s) if they

1443        // were passed to this object by their coresponding set

1444        // method.  This object relates to these object(s) by a

1445        // foreign key reference.

1446  <?php
1447        for($i=0,$_i=count($aVars); $i < $_i; $i++) 
1448        {
1449          $aVarName = $aVars[$i];
1450  ?>
1451        if ($this-><?php echo $aVarName ?> !== null) {
1452          if ($this-><?php echo $aVarName ?>->isModified()) {
1453            if (Propel::isError($e = $this-><?php echo $aVarName ?>->save())) {
1454                return $e;
1455            }
1456          }
1457          $this->set<?php echo $pVars[$i] ?>($this-><?php echo $aVarName ?>);
1458        }
1459  
1460  <?php 
1461        } /* foreach */ 
1462      } /* if count(pVars) */ 
1463    } /* if complexObjectMode */ 
1464  ?>
1465        // If this object has been modified, then save it to the database.

1466        if ($this->isModified()) {
1467          if ($this->isNew()) {
1468            $pk = <?php echo $table->getPhpName() ?>Peer::doInsert($this, <?php if($complexObjectModel) {?>$con<?php } else { ?>Param::set($con)<?php } ?>);
1469            if (Propel::isError($pk)) { return $pk; }
1470  <?php 
1471    if ($table->getIdMethod() != "none") {
1472      if (count($pks = $table->getPrimaryKey())) {
1473        foreach ($pks as $pk) {
1474          if ($pk->isAutoIncrement()) {
1475  ?>
1476            $this->set<?php echo $pk->getPhpName();?>( $pk );  //[IMV] update autoincrement primary key

1477  <?php
1478          }
1479        }
1480      }
1481    }
1482  ?>
1483            $this->setNew(false);
1484          }
1485          else {
1486            $e = <?php echo $table->getPhpName() ?>Peer::doUpdate($this, <?php if($complexObjectModel) {?>$con<?php } else { ?>Param::set($con)<?php } ?>);
1487            if (Propel::isError($e)) { return $e; }
1488          }
1489          $this->resetModified(); // [HL] After being saved an object is no longer 'modified'

1490        }
1491  
1492  <?php
1493    if ($complexObjectModel) 
1494    {
1495      foreach ($table->getReferrers() as $fk) 
1496      {
1497        $tblFK = $fk->getTable();
1498        if ( $tblFK->getName() != $table->getName() ) 
1499        {
1500          $className = $tblFK->getPhpName();
1501          $relCol = "";
1502          foreach ($fk->getLocalColumns() as $columnName) {
1503            $column = $tblFK->getColumn($columnName);
1504            if ($column->isMultipleFK()) {
1505              $relCol .= $column->getPhpName();
1506            }
1507          }
1508    
1509          if ($relCol == "") {
1510            $relCol = $className . "s";
1511          } else {
1512            $relCol = $className . "sRelatedBy" . $relCol;
1513          }
1514    
1515          $collName = "coll" . $relCol;
1516  ?>
1517        if ($this-><?php echo $collName ?> !== null) {
1518          for ($i=0,$size=count($this-><?php echo $collName ?>); $i < $size; $i++) {
1519            if (Propel::isError($e = $this-><?php echo $collName ?>[$i]->save())) {
1520              return $e;
1521            }
1522          }
1523        }
1524  
1525  <?php
1526        } /* if tableFK !+ table */
1527      } /* foreach getReferrers() */
1528    } /* if complexObjectModel */
1529  
1530    if ($complexObjectModel) 
1531    { 
1532  ?>
1533        $this->alreadyInSave = false;
1534      }
1535  
1536  <?php 
1537    } /* if ($complexObjectModel) */
1538  ?>
1539      return true;
1540    }
1541  
1542  <?php 
1543  } /* if !table->isAlias && isset .... */ 
1544  
1545  if (! $table->isAlias() && ! $table->isReadOnly()) 
1546  { 
1547  ?>
1548    /**

1549    * Validates the objects modified field values.

1550  <?php 

1551    if ($complexObjectModel) 

1552    {

1553  ?>

1554    * This includes all objects related to this table.

1555  <?php 

1556    } /* if ($complexObjectModel) */
1557  ?>
1558    *
1559    * If $columns is either a column name or an array of column names
1560    * only those columns are validated.
1561    *
1562    * @param mixed $columns Column name or an array of column names.
1563    *
1564    * @return mixed <code>true</code> if all columns pass validation
1565    *               or an array of <code>ValidationFailed</code> objects for columns that fail.
1566    */
1567    function & validate($columns = null)
1568    {
1569      if ($columns)
1570      {
1571        return <?php echo $table->getPhpName()?>Peer::doValidate($this, $columns);
1572      }
1573  
1574  <?php 
1575    if (! $complexObjectModel) 
1576    { 
1577  ?>
1578      return <?php echo $table->getPhpName()?>Peer::doValidate($this);
1579  <?php 
1580    } else { 
1581  ?>
1582      return $this->doValidate();
1583  <?php 
1584    } /* if (! $complexObjectModel) */ 
1585  ?>
1586    }
1587  
1588  <?php   
1589    if ($complexObjectModel) 
1590    { 
1591  ?>
1592    /**

1593    * flag to prevent endless validation loop, if this object is referenced

1594    * by another object which falls in this transaction.

1595    * @var boolean

1596    */
1597    var $alreadyInValidation = false;
1598  
1599    /**

1600    * This function performs the validation work for complex object models.

1601    *

1602    * In addition to checking the current object, all related objects will

1603    * also be validated.  If all pass then <code>true</code> is returned; otherwise

1604    * an aggreagated array of ValidationFailed objects will be returned.

1605    *

1606    * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.

1607    */
1608    function & doValidate()
1609    {
1610      if (! $this->alreadyInValidation)
1611      {
1612        $this->alreadyInValidation = true;
1613        $retval = null;
1614        $failureMap = array();
1615  
1616  <?php 
1617      if (count($pVars) != 0) 
1618      { 
1619  ?>
1620        // We call the validate method on the following object(s) if they

1621        // were passed to this object by their coresponding set

1622        // method.  This object relates to these object(s) by a

1623        // foreign key reference.

1624  <?php
1625        for($i=0,$_i=count($aVars); $i < $_i; $i++) 
1626        {
1627          $aVarName = $aVars[$i];
1628  ?>
1629        if ($this-><?php echo $aVarName ?> !== null) {
1630          if (($retval = $this-><?php echo $aVarName ?>->validate()) !== true) {
1631            $failureMap = array_merge($failureMap, $retval);
1632          }
1633        }
1634  <?php   
1635        } /* for */ 
1636      } /* if count(pVars) */ 
1637  ?>
1638  
1639        if (($retval = <?php echo $table->getPhpName()?>Peer::doValidate($this)) !== true) {
1640          $failureMap = array_merge($failureMap, $retval);
1641        }
1642  
1643  <?php
1644      foreach ($table->getReferrers() as $fk) 
1645      {
1646        $tblFK = $fk->getTable();
1647        if ( $tblFK->getName() != $table->getName() ) 
1648        {
1649          $className = $tblFK->getPhpName();
1650          $relCol = "";
1651          foreach ($fk->getLocalColumns() as $columnName) {
1652            $column = $tblFK->getColumn($columnName);
1653            if ($column->isMultipleFK()) {
1654                $relCol .= $column->getPhpName();
1655            }
1656          }
1657  
1658          if ($relCol == "") {
1659            $relCol = $className . "s";
1660          } else {
1661            $relCol = $className . "sRelatedBy" . $relCol;
1662          }
1663  
1664          $collName = "coll" . $relCol;
1665  ?>
1666        if ($this-><?php echo $collName ?> !== null) {
1667          for ($i=0,$size=count($this-><?php echo $collName ?>); $i < $size; $i++) {
1668            if (($retval = $this-><?php echo $collName ?>[$i]->validate()) !== true) {
1669              $failureMap = array_merge($failureMap, $retval);
1670            }
1671          }
1672        }
1673  <?php    
1674        } /* if tableFK !+ table */
1675      } /* foreach getReferrers() */
1676  ?>
1677  
1678        $this->alreadyInValidation = false;
1679        return (!empty($failureMap) ? $failureMap : true);
1680      }
1681  
1682      return true;
1683    }
1684  
1685  <?php   
1686    } /* complexObjectModel */ 
1687  } /* ! isAlias */ 
1688  
1689  // PrimaryKey methods

1690  if (!$table->isAlias()) 
1691  {
1692    if (! $table->isReadOnly())
1693    {
1694      $throwsClause = "@throws PropelException";
1695      if (count($table->getPrimaryKey()) == 1) 
1696      {
1697        $pkeys = $table->getPrimaryKey();
1698        $col = $pkeys[0];
1699        $clo=strtolower($col->getName());
1700        $cptype= $col->getPhpNative();
1701  ?>
1702    /**

1703    * Set the PrimaryKey.

1704    *

1705    * @param mixed <?php echo $clo ?> Primary key.

1706    * @return void

1707    * <?php echo $throwsClause ?>

1708    */
1709    function setPrimaryKey($key)
1710    {
1711      $this->set<?php echo $col->getPhpName() ?>($key);
1712    }
1713  
1714  <?php     
1715      } 
1716      elseif (count($table->getPrimaryKey()) > 1) 
1717      { 
1718  ?>
1719    var $pks = array();
1720  
1721    /**

1722    * Set the PrimaryKey.

1723    *

1724    * @param array $keys The elements of the composite key (order must match the order in XML file).

1725    * @return void

1726    * @throws PropelException

1727    */
1728    function setPrimaryKey($keys)
1729    {
1730  <?php
1731        $i = 0;
1732        foreach ($table->getPrimaryKey() as $pk) 
1733        {
1734          $pktype = $pk->getPhpNative(); 
1735  ?>
1736      $this->set<?php echo $pk->getPhpName() ?>($keys[<?php echo $i ?>]);
1737  <?php
1738          $i++;
1739        } /* foreach ($table->getPrimaryKey() as $pk) */
1740  ?>
1741    }
1742  
1743  <?php 
1744      } else { /* if (count($table->getPrimaryKey()) == 1) */ 
1745  ?>
1746  
1747    /**

1748    * Dummy primary key setter.

1749    * For now this function needs to exist because it's mandated in the Persistent

1750    * interface, and because other methods will attempt to set the primary key.

1751    *

1752    * This should be removed in favor of more complex template work.

1753    */
1754    function setPrimaryKey($pk)
1755    {
1756      // do nothing, because this doesn't support primary keys

1757    }
1758  <?php 
1759      } /* if (count($table->getPrimaryKey()) == 1) */
1760    } /* if ! $table->isReadOnly() */
1761  ?>
1762  
1763    /**

1764    * Returns an id that differentiates this object from others

1765    * of its class.

1766    * @return <?php if (count($table->getPrimaryKey()) === 0) { echo "null"; } elseif (count($table->getPrimaryKey()) > 1) { echo "array"; } else { $pkeys = $table->getPrimaryKey(); echo $pkeys[0]->getPhpType(); } ?>

1767    */
1768    function getPrimaryKey()
1769    {
1770  <?php 
1771    if (count($table->getPrimaryKey()) == 1) { 
1772  ?>
1773      return $this->get<?php $pkeys = $table->getPrimaryKey(); echo $pkeys[0]->getPhpName()?>();
1774  <?php 
1775    } 
1776    elseif (count($table->getPrimaryKey()) > 1) {
1777      $i = 0;
1778      foreach ($table->getPrimaryKey() as $pk) { 
1779  ?>
1780      $this->pks[<?php echo $i ?>] = $this->get<?php echo $pk->getPhpName() ?>();
1781  <?php
1782        $i++;
1783      } /* foreach ($table->getPrimaryKey() as $pk) */
1784  ?>
1785      return $this->pks;
1786  <?php 
1787    } else { 
1788  ?>
1789  
1790      return null;
1791  <?php 
1792    } 
1793  ?>
1794    }
1795  
1796  <?php 
1797    if (! $table->isAbstract()) 
1798    { 
1799  ?>
1800    /**

1801    * Makes a copy of this object.

1802    * It creates a new object filling in the simple attributes, but skipping any primary

1803    * keys that are defined for the table.

1804    * 

1805  <?php 

1806      if ($complexObjectModel) 

1807      { 

1808  ?>

1809    * If desired, this method can also make copies of all associated (fkey referrers)

1810    * objects.

1811    *

1812    * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.

1813    * 

1814  <?php 

1815      } 

1816  ?>

1817    * @return <?php echo $table->getPhpName() ?> Clone of current object.

1818    * @throws PropelException

1819    */
1820    function copy(<?php if ($complexObjectModel) { ?>$deepCopy = false<?php } ?>) 
1821    {
1822      $copyObj = new <?php echo $table->getPhpName() ?>();
1823  <?php
1824  
1825      $pkcols = array();
1826      foreach ($table->getColumns() as $pkcol) {
1827        if ($pkcol->isPrimaryKey()) { 
1828          $pkcols[] = $pkcol->getName(); 
1829        }
1830      }
1831  
1832      foreach ($table->getColumns() as $col) 
1833      {
1834        if (!in_array($col->getName(), $pkcols)) {
1835  ?>
1836      $copyObj->set<?php echo $col->getPhpName()?>($this-><?php echo strtolower($col->getName()) ?>);
1837  <?php
1838        }
1839      }
1840  
1841      if ($complexObjectModel) 
1842      {
1843        // Avoid useless code by checking to see if there are any referrers

1844        // to this table:

1845        if (count($table->getReferrers()) > 0) 
1846        {
1847  ?>
1848  
1849      if ($deepCopy) {        
1850        // important: setNew(false) because this affects the behavior of

1851        // the getter/setter methods for fkey referrer objects.

1852        $copyObj->setNew(false);
1853  <?php
1854          foreach ($table->getReferrers() as $fk) 
1855          {
1856            $tblFK = $fk->getTable();
1857            if ( $tblFK->getName() != $table->getName() ) 
1858            {
1859              $className = $tblFK->getPhpName();
1860              $relCol = "";
1861              foreach ($fk->getLocalColumns() as $columnName) {
1862                $column = $tblFK->getColumn($columnName);
1863                if ($column->isMultipleFK()) {
1864                  $relCol .= $column->getPhpName();
1865                }
1866              }
1867  
1868              if ($relCol == "") {
1869                $pCollName = $className . "s";
1870                $pCollNameNoS = $className;
1871              } else {
1872                $pCollName = $className . "sRelatedBy".$relCol;
1873                $pCollNameNoS = $className . "RelatedBy".$relCol;
1874              }
1875  ?>
1876  
1877        foreach($this->get<?php echo $pCollName ?>() as $relObj) {
1878          $copyObj->add<?php echo $pCollNameNoS ?>($relObj->copy());
1879        }
1880  <?php
1881            } /* if tblFK != table */
1882          } /* foreach */ 
1883  ?>
1884      } /* if ($deepCopy) */
1885  <?php            
1886        } /* if (count referrers > 0 ) */
1887  ?>
1888      
1889      $copyObj->setNew(true);
1890  <?php 
1891      } /* if complex object model */
1892  
1893      // this is a little redundant, but it's clearer than re-using

1894      // the $pkcols array  we created above

1895      foreach ($table->getColumns() as $col) 
1896      {
1897        if ($col->isPrimaryKey()) 
1898        {
1899          $coldefval = $col->getDefaultValue();
1900          // This seems to work pretty well for getting

1901          // the right value (including NULL)

1902          $coldefval = var_export($coldefval, true);
1903  ?>
1904      $copyObj->set<?php echo $col->getPhpName()?>(<?php echo $coldefval ?>); // this is a pkey column, so set to default value

1905  <?php
1906        } // if col->isPrimaryKey

1907      } // foreach

1908  ?>
1909  
1910      return $copyObj;
1911    }
1912  
1913  <?php 
1914    } /* if (! $table->isAbstract()) */ 
1915  ?>
1916    /**

1917    * Returns a peer instance associated with this om.  Since Peer classes

1918    * are not to have any instance attributes, this method returns the

1919    * same instance for all member of this class. The method could therefore

1920    * be static, but this would prevent one from overriding the behavior.

1921    *

1922    * @return <?php echo $table->getPhpName() ?>Peer

1923    */
1924    function & getPeer()
1925    {
1926      static $instance;
1927  
1928      if ($instance === null) {
1929        $instance = new <?php echo $table->getPhpName()?>Peer();
1930      }
1931  
1932      return $instance;
1933    }
1934  <?php 
1935  } /* if !table->isAlias */ 
1936  ?>
1937  
1938  }


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