[geeklog-cvs] Geeklog_Generator/engine/builder/om/php5 PHP5ExtendComplexObjectBuilder.php, NONE, 1.1 PHP5BaseDTOObjectBuilder.php, 1.1.1.1, 1.2 PHP5BaseManagerObjectBuilder.php, 1.1.1.1, 1.2
Tony Bibbs
tony at qs1489.pair.com
Thu Jul 26 09:40:19 EDT 2007
Update of /cvsroot/geeklog2/Geeklog_Generator/engine/builder/om/php5
In directory qs1489.pair.com:/tmp/cvs-serv17482
Modified Files:
PHP5BaseDTOObjectBuilder.php PHP5BaseManagerObjectBuilder.php
Added Files:
PHP5ExtendComplexObjectBuilder.php
Log Message:
Fixes/Updates for 1.0.4 release
Index: PHP5BaseDTOObjectBuilder.php
===================================================================
RCS file: /cvsroot/geeklog2/Geeklog_Generator/engine/builder/om/php5/PHP5BaseDTOObjectBuilder.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PHP5BaseDTOObjectBuilder.php 31 May 2007 20:11:47 -0000 1.1.1.1
--- PHP5BaseDTOObjectBuilder.php 26 Jul 2007 13:40:16 -0000 1.2
***************
*** 1,14 ****
<?php
! require_once 'propel/engine/builder/om/ObjectBuilder.php';
/**
* Generates a PHP5 DTO object class with public attributes.
! *
* @author Jana Dohman <jana.dohman at iowa.gov>
* @package propel.engine.builder.om.php5
*/
! class PHP5BaseDTOObjectBuilder extends ObjectBuilder {
!
/**
* Gets the package for the [base] object classes.
--- 1,14 ----
<?php
! require_once 'propel/engine/builder/om/php5/PHP5ComplexObjectBuilder.php';
/**
* Generates a PHP5 DTO object class with public attributes.
! *
* @author Jana Dohman <jana.dohman at iowa.gov>
* @package propel.engine.builder.om.php5
*/
! class PHP5BaseDTOObjectBuilder extends PHP5ComplexObjectBuilder {
!
/**
* Gets the package for the [base] object classes.
***************
*** 17,21 ****
public function getPackage()
{
! return parent::getPackage() . ".dto.base";
}
--- 17,51 ----
public function getPackage()
{
! $pkg = ($this->getTable()->getPackage() ? $this->getTable()->getPackage() : $this->getDatabase()->getPackage());
! if (!$pkg) {
! $pkg = $this->getBuildProperty('targetPackage');
! }
! return $pkg . ".dto.base";
! }
!
! /**
! * Gets the package for the [base] object classes.
! * @return string
! */
! protected function getParentPackage()
! {
! $pkg = ($this->getTable()->getPackage() ? $this->getTable()->getPackage() : $this->getDatabase()->getPackage());
! if (!$pkg) {
! $pkg = $this->getBuildProperty('targetPackage');
! }
! return $pkg . ".dto";
! }
!
! /**
! * Gets the package for the [base] object classes.
! * @return string
! */
! protected function getRootPackage()
! {
! $pkg = ($this->getTable()->getPackage() ? $this->getTable()->getPackage() : $this->getDatabase()->getPackage());
! if (!$pkg) {
! $pkg = $this->getBuildProperty('targetPackage');
! }
! return $pkg;
}
***************
*** 36,40 ****
{
// Do nothing at this point as class stands alone.
! }
/**
--- 66,70 ----
{
// Do nothing at this point as class stands alone.
! }
/**
***************
*** 62,66 ****
* @package ".$this->getPackage()."
*/
! require_once '".$this->getStubObjectBuilder()->getClassFilePath()."';
abstract class ".$this->getClassname()." ";
--- 92,96 ----
* @package ".$this->getPackage()."
*/
! include_once '".$this->getStubObjectBuilder()->getClassFilePath()."';
abstract class ".$this->getClassname()." ";
***************
*** 69,75 ****
";
}
!
/**
! * Specifies the public attributes that are added as part of the DTO
* OM class.
* @param string &$script The script will be modified in this method.
--- 99,105 ----
";
}
!
/**
! * Specifies the public attributes that are added as part of the DTO
* OM class.
* @param string &$script The script will be modified in this method.
***************
*** 81,101 ****
$this->addConstantsAndAttributes($script);
}
!
$this->addColumnAccessorMethods($script);
$this->addColumnMutatorMethods($script);
- $this->addPropelClassAccessor($script);
- $this->addPropelClassConstructor($script);
- }
! /**
! * Closes class.
! * @param string &$script The script will be modified in this method.
! */
! protected function addClassClose(&$script)
! {
! $script .= "
!
! } // " . $this->getClassname() . "
! ";
}
--- 111,124 ----
$this->addConstantsAndAttributes($script);
}
!
! $this->addCommonMethods($script);
$this->addColumnAccessorMethods($script);
$this->addColumnMutatorMethods($script);
! $this->addHydrate($script);
!
! $this->addFKMethods($script);
! $this->addRefFKMethods($script);
! $this->addPropelClassAccessor($script);
}
***************
*** 106,109 ****
--- 129,134 ----
{
if (!$this->getTable()->isAlias()) {
+ $this->addColumnNameConstants($script);
+ $this->addCommonAttributes($script);
$this->addColumnAttributes($script);
}
***************
*** 111,114 ****
--- 136,173 ----
/**
+ * Adds the COLUMN_NAME contants to the class definition.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addColumnNameConstants(&$script)
+ {
+ foreach ($this->getTable()->getColumns() as $col) {
+
+ $script .= "
+ /** the column name for the ".strtoupper($col->getName()) ." field */
+ const ".$this->getColumnConstant($col) ." = '".$this->getTable()->getName().".".strtoupper($col->getName())."';
+ ";
+ } // foreach
+ }
+
+ protected function addCommonAttributes(&$script)
+ {
+ $script .= "
+
+ /**
+ * attribute to determine if this object has previously been saved.
+ * @var boolean
+ */
+ private \$_new = true;
+
+ /**
+ * The columns that have been modified in current object.
+ * Tracking modified columns allows us to only update modified columns.
+ * @var array
+ */
+ protected \$modifiedColumns = array();
+ ";
+ }
+
+ /**
* Adds variables that store column values.
* @param string &$script The script will be modified in this method.
***************
*** 120,124 ****
foreach ($table->getColumns() as $col) {
! $cptype = $col->getPhpNative();
$clo=$col->getName();
$defVal = "";
--- 179,183 ----
foreach ($table->getColumns() as $col) {
! $cptype = trim($col->getPhpNative());
$clo=$col->getName();
$defVal = "";
***************
*** 140,145 ****
--- 199,329 ----
} // foreach col
+ foreach ($table->getForeignKeys() as $fk) {
+ $this->addFKAttributes($script, $fk);
+ }
+
+ foreach($table->getReferrers() as $refFK) {
+ $this->addRefFKAttributes($script, $refFK);
+ }
+
} // addColumnAttributes()
+ public function getColumnConstant(Column $col, $phpName = null) {
+ // was it overridden in schema.xml ?
+ if ($col->getPeerName()) {
+ $const = strtoupper($col->getPeerName());
+ } else {
+ $const = strtoupper($col->getName());
+ }
+ if ($phpName !== null) {
+ return $phpName . '::' . $const;
+ } else {
+ return $const;
+ }
+ }
+
+ protected function addCommonMethods(&$script) {
+ $script .= "
+
+ /**
+ * Returns whether the object has ever been saved. This will
+ * be false, if the object was retrieved from storage or was created
+ * and then saved.
+ *
+ * @return true, if the object has never been persisted.
+ */
+ public function isNew()
+ {
+ return \$this->_new;
+ }
+
+ /**
+ * Setter for the isNew attribute. This method will be called
+ * by Propel-generated children and Peers.
+ *
+ * @param boolean \$b the state of the object.
+ */
+ public function setNew(\$b)
+ {
+ \$this->_new = (boolean) \$b;
+ }
+
+ /**
+ * Returns whether the object has been modified.
+ *
+ * @return boolean True if the object has been modified.
+ */
+ public function isModified()
+ {
+ return !empty(\$this->modifiedColumns);
+ }
+
+ /**
+ * Sets the modified state for the object to be false.
+ * @param string \$col If supplied, only the specified column is reset.
+ * @return void
+ */
+ public function resetModified(\$col = null)
+ {
+ if (\$col !== null)
+ {
+ while ((\$offset = array_search(\$col, \$this->modifiedColumns)) !== false)
+ array_splice(\$this->modifiedColumns, \$offset, 1);
+ }
+ else
+ {
+ \$this->modifiedColumns = array();
+ }
+ }
+
+ /**
+ * Has specified column been modified?
+ *
+ * @param string \$col
+ * @return boolean True if $col has been modified.
+ */
+ public function isColumnModified(\$col)
+ {
+ return in_array(\$col, \$this->modifiedColumns);
+ }
+ ";
+ }
+
+ /**
+ * Adds the class attributes that are needed to store fkey related objects.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addFKAttributes(&$script, ForeignKey $fk)
+ {
+ $className = $this->getForeignTable($fk)->getPhpName() . 'DTO';
+ $varName = $this->getFKVarName($fk);
+
+ $script .= "
+ /**
+ * @var $className
+ */
+ public $".$varName.";
+ ";
+ }
+
+ /**
+ * Adds the attributes used to store objects that have referrer fkey relationships to this object.
+ * <code>protected collVarName;</code>
+ * <code>private lastVarNameCriteria = null;</code>
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addRefFKAttributes(&$script, ForeignKey $refFK)
+ {
+ $collName = $this->getRefFKCollVarName($refFK);
+
+ $script .= "
+ /**
+ * Collection to store aggregation of $collName.
+ * @var array
+ */
+ public $".$collName.";
+ ";
+ }
+
/**
* Adds the getter methods for the column values.
***************
*** 149,153 ****
{
$table = $this->getTable();
!
foreach ($table->getColumns() as $col) {
--- 333,337 ----
{
$table = $this->getTable();
!
foreach ($table->getColumns() as $col) {
***************
*** 156,281 ****
/**
* Get the [".$col->getName()."] column value.
! *
! * @return string
*/
public function get".ucfirst($col->getPhpName())."() {
return \$this->".$col->getName().";
! }
";
}
} // addColumnAccessorMethods()
!
/**
! * Adds the mutator (setter) methods for setting column values.
! * @param string &$script The script will be modified in this method.
*/
! protected function addColumnMutatorMethods(&$script)
{
! $table = $this->getTable();
!
! foreach ($table->getColumns() as $col) {
!
! $script .= '
/**
! * Set the value of ['.$col->getName().'] column.
! *
! * @param string $v new value
! * @return void
*/
! public function set'.ucfirst($col->getPhpName()).'($v) {
! $this->'.$col->getName().' = $v;
! }
! ';
}
! } // addColumnMutatorMethods()
!
!
/**
! * Adds the accessor method which returns the Propel class.
! * @param string &$script The script will be modified in this method.
*/
! protected function addPropelClassAccessor(&$script)
{
! $table = $this->getTable();
!
$script .= "
-
/**
! * Returns a ".$this->getStubObjectBuilder()->getClassname()." object populated with values from this class.
! * NOTE: This method does not copy the collections associated with
! * this ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')." to the new ".$this->getStubObjectBuilder()->getClassname().".
! * @return ".$this->getStubObjectBuilder()->getClassname()."
*/
! public function &to".$this->getStubObjectBuilder()->getClassname()."() {
! require_once '".$this->getStubObjectBuilder()->getClassFilePath()."';
!
! \$associatedClass = new ".$this->getStubObjectBuilder()->getClassname()."();
";
! foreach($table->getColumns() as $col) {
! $cfc=ucfirst($col->getPhpName());
! $clo='get'.ucfirst($col->getPhpName()).'()';
$script .= "
! \$associatedClass->set".$cfc."(\$this->$clo);";
}
!
$script .= "
!
! return \$associatedClass;
}
";
! }
!
! /**
! * Adds the factory method which returns the DTO class from the specified Propel class.
! * @param string &$script The script will be modified in this method.
*/
! protected function addPropelClassConstructor(&$script)
{
! $table = $this->getTable();
!
$script .= "
-
/**
! * Returns a ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')." object populated with values from
! * the provided ".$this->getStubObjectBuilder()->getClassname()." object.
! * NOTE: This method does not copy the collections associated with
! * the ".$this->getStubObjectBuilder()->getClassname()." to the new ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix').".
! * @param ".$this->getStubObjectBuilder()->getClassname()." $omObject The class to map a DTO object from.
! * @return ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')."
*/
! public static function &from".$this->getStubObjectBuilder()->getClassname()."(".$this->getStubObjectBuilder()->getClassname()." \$omObject) {
! \$ret = new ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')."();
! ";
! foreach($table->getColumns() as $col) {
! $cfc=ucfirst($col->getPhpName());
! $clo='set'.ucfirst($col->getPhpName()).'(';
! $script .= "
! \$ret->$clo\$omObject->get".$cfc."());";
}
!
$script .= "
!
! return \$ret;
}
";
}
! /**
! * Adds the close of the mutator (setter) method for a column.
! * This can be overridden (e.g. by PHP5ComplexObjectBuilder) if additional functionality is needed.
* @param string &$script The script will be modified in this method.
- * @param Column $col The current column.
*/
! protected function addMutatorClose(&$script, Column $col)
{
$script .= "
! } // set".$col->getPhpName()."()
";
}
!
} // PHP5DTOObjectBuilder
--- 340,752 ----
/**
* Get the [".$col->getName()."] column value.
! *
! * @return ".$col->getPhpNative()."
*/
public function get".ucfirst($col->getPhpName())."() {
return \$this->".$col->getName().";
! }
";
}
} // addColumnAccessorMethods()
!
/**
! * Adds a setter method for date/time/timestamp columns.
! * @param string &$script The script will be modified in this method.
! * @param Column $col The current column.
! * @see parent::addColumnMutators()
*/
! protected function addTemporalMutator(&$script, Column $col)
{
! $this->addDefaultMutator($script, $col);
! }
/**
! * Adds setter method for "normal" columns.
! * @param string &$script The script will be modified in this method.
! * @param Column $col The current column.
! * @see parent::addColumnMutators()
*/
! protected function addDefaultMutator(&$script, Column $col)
! {
! $clo = strtolower($col->getName());
!
! $defaultValue = null;
! if (($val = $col->getPhpDefaultValue()) !== null) {
! settype($val, $col->getPhpNative());
! $defaultValue = var_export($val, true);
}
!
! $this->addMutatorOpen($script, $col);
!
! $script .= "
! if (\$this->$clo !== \$v";
! if ($defaultValue !== null) {
! $script .= " || \$v === $defaultValue";
! }
! $script .= ") {
! \$this->$clo = \$v;
! \$this->modifiedColumns[] = ".$this->getColumnConstant($col,
! $this->getBuildProperty('dtoPrefix')
! . $this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')).";
! }
! ";
! $this->addMutatorClose($script, $col);
! }
!
/**
! * Adds the open of the mutator (setter) method for a column.
! * @param string &$script The script will be modified in this method.
! * @param Column $col The current column.
*/
! protected function addMutatorOpen(&$script, Column $col)
{
! $cfc=$col->getPhpName();
! $clo=strtolower($col->getName());
!
$script .= "
/**
! * Set the value of [$clo] column.
! * ".$col->getDescription()."
! * @param ".$col->getPhpNative()." \$v new value
! * @return void
*/
! public function set$cfc(\$v)
! {
";
!
! }
!
! /**
! * Adds the mutator (setter) method for setting an fkey related object.
! * @param string &$script The script will be modified in this method.
! */
! protected function addFKMutator(&$script, ForeignKey $fk)
! {
! $table = $this->getTable();
! $tblFK = $this->getForeignTable($fk);
! $className = $this->getForeignTable($fk)->getPhpName(). 'DTO';
! $varName = $this->getFKVarName($fk);
!
! $script .= "
! /**
! * Declares an association between this object and a $className object.
! *
! * @param $className \$v
! * @return void
! */
! public function set".$this->getFKPhpNameAffix($fk, $plural = false)."(\$v)
! {
! "; foreach ($fk->getLocalColumns() as $columnName) {
! $column = $table->getColumn($columnName);
! $lfmap = $fk->getLocalForeignMapping();
! $colFKName = $lfmap[$columnName];
! $colFK = $tblFK->getColumn($colFKName);
! $script .= "
! if (\$v === null) {
! \$this->set".$column->getPhpName()."(".var_export($column->getDefaultValue(), true).");
! } else {
! \$this->set".$column->getPhpName()."(\$v->get".$colFK->getPhpName()."());
! }
! ";
!
! } /* foreach local col */
!
$script .= "
!
! \$this->$varName = \$v;
! }
! ";
! }
!
! /**
! * Adds the accessor (getter) method for getting an fkey related object.
! * @param string &$script The script will be modified in this method.
! */
! protected function addFKAccessor(&$script, ForeignKey $fk)
! {
! $table = $this->getTable();
!
! $className = $this->getForeignTable($fk)->getPhpName() . 'DTO';
! $varName = $this->getFKVarName($fk);
!
! $and = "";
! $comma = "";
! $conditional = "";
! $arglist = "";
! $argsize = 0;
! foreach ($fk->getLocalColumns() as $columnName) {
! $column = $table->getColumn($columnName);
! $cptype = $column->getPhpNative();
! $clo = strtolower($column->getName());
!
! // FIXME: is this correct? what about negative numbers?
! if ($cptype == "integer" || $cptype == "float" || $cptype == "double") {
! $conditional .= $and . "\$this->". $clo ." > 0";
! } elseif($cptype == "string") {
! $conditional .= $and . "(\$this->" . $clo ." !== \"\" && \$this->".$clo." !== null)";
! } else {
! $conditional .= $and . "\$this->" . $clo ." !== null";
! }
! $arglist .= $comma . "\$this->" . $clo;
! $and = " && ";
! $comma = ", ";
! $argsize = $argsize + 1;
}
!
! $pCollName = $this->getFKPhpNameAffix($fk, $plural = true);
!
! $fkPeerBuilder = OMBuilder::getNewPeerBuilder($this->getForeignTable($fk));
!
$script .= "
!
! /**
! * Get the associated $className object
! *
! * @return $className The associated $className object.
! */
! public function get".$this->getFKPhpNameAffix($fk, $plural = false)."()
! {
! if (\$this->$varName === null && ($conditional)) {
! ";
! $script .= "
! \$obj = \$this->toOMObject->get".$this->getFKPhpNameAffix($fk, $plural = false)."();
! \$this->$varName = \$obj->toDTO();
! }
! return \$this->$varName;
}
";
! } // addFKAccessor
! /**
! * Adds the method that initializes the referrer fkey collection.
! * @param string &$script The script will be modified in this method.
*/
! protected function addRefFKInit(&$script, ForeignKey $refFK) {
!
! // Do nothing for this object type.
!
! } // addRefererInit()
!
! /**
! * Adds the method that returns the referrer fkey collection.
! * @param string &$script The script will be modified in this method.
! */
! protected function addRefFKGet(&$script, ForeignKey $refFK)
{
! $table = $this->getTable();
! $tblFK = $refFK->getTable();
!
! $fkObjectBuilder = OMBuilder::getNewObjectBuilder($refFK->getTable());
! $fkPeerBuilder = OMBuilder::getNewPeerBuilder($refFK->getTable());
! $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
!
! $collName = $this->getRefFKCollVarName($refFK);
!
$script .= "
/**
! * If this collection has already been initialized, it returns
! * the collection. Otherwise if this ".$table->getPhpName()."
! * has previously been saved, it will retrieve related $relCol
! * from storage.
! * If this ".$table->getPhpName()." is new, it will return
! * an empty collection or the current collection.
*/
! public function get$relCol()
! {
! if (\$this->$collName === null) {
! \$this->$collName = array();
! \$v = \$this->toOMObject();
! foreach (\$v->get$relCol() as \$obj) {
! \$this->".$collName."[] = \$obj->toDTO();
! }
}
! return \$this->$collName;
! }
! ";
! } // addRefererGet()
!
! /**
! * Adds the method that returns the size of the referrer fkey collection.
! * @param string &$script The script will be modified in this method.
! */
! protected function addRefFKCount(&$script, ForeignKey $refFK)
! {
!
! // Do nothing for this object type.
!
! } // addRefererCount
!
! /**
! * Adds the method that adds an object into the referrer fkey collection.
! * @param string &$script The script will be modified in this method.
! */
! protected function addRefFKAdd(&$script, ForeignKey $refFK)
! {
! $tblFK = $refFK->getTable();
! $className = $refFK->getTable()->getPhpName().'DTO';
!
! $joinedTableObjectBuilder = OMBuilder::getNewObjectBuilder($refFK->getTable());
!
$script .= "
! /**
! * Method called to associate a ".$tblFK->getPhpName()." object to this object
! * through the $className foreign key attribute
! *
! * @param $className \$l $className
! * @return void
! * @throws PropelException
! */
! public function add".$this->getRefFKPhpNameAffix($refFK, $plural = false)."($className \$l)
! {
! \$this->coll".$this->getRefFKPhpNameAffix($refFK, $plural = true)."[] = \$l;
! \$l->set".$this->getFKPhpNameAffix($refFK, $plural = false)."(\$this);
}
";
+ } // addRefererAdd
+
+ /**
+ * Adds the method that fetches fkey-related (referencing) objects but also joins in data from another table.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK)
+ {
+
+ // Do nothing for this object type.
}
! /**
! * Adds the accessor method which returns the Propel class.
* @param string &$script The script will be modified in this method.
*/
! protected function addPropelClassAccessor(&$script)
{
+ $table = $this->getTable();
+ $objectType = $this->getStubObjectBuilder()->getClassname();
+ $managerName = $objectType . $this->getBuildProperty('managerSuffix');
+
+ $script .= "
+
+ /**
+ * Returns a ".$this->getStubObjectBuilder()->getClassname()." object populated with values from this class.
+ * @param boolean true if the conversion to ".$this->getStubObjectBuilder()->getClassname()." should
+ * include collections and associated objects.
+ * @return ".$this->getStubObjectBuilder()->getClassname()."
+ */
+ public function &toOMObject(\$deepConversion=false)
+ {
+ ";
+ $isNew = false;
+ $keys = array();
+ $phpParams = array();
+ foreach ($table->getPrimaryKey() as $keyCol) {
+ $keys[$keyCol->getName()] = $keyCol;
+ $phpParams[] = '$this->'.$keyCol->getName();
+ }
+
+ $params = implode(',',$phpParams);
+
+ foreach ($phpParams as $key => $param) {
+ $phpParams[$key] = $param . ' === null';
+ }
+
+ $nullChecks = implode(' || ', $phpParams);
+
+ $script .= "
+ if (" . trim($nullChecks) . ") {
+ \$associatedClass = new ".$this->getStubObjectBuilder()->getClassname()."();";
+
+ foreach($table->getPrimaryKey() as $keyCol) {
+ $cfc=ucfirst($keyCol->getPhpName());
+ $clo=$keyCol->getName();
+ $const=$this->getColumnConstant($keyCol,
+ $this->getBuildProperty('dtoPrefix')
+ . $this->getStubObjectBuilder()->getClassname()
+ . $this->getBuildProperty('dtoSuffix'));
+ $script .= "
+ if (\$this->isColumnModified($const))
+ \$associatedClass->set".$cfc."(
+ \$this->$clo);";
+ }
+
+ $script .= "
+ } else {
+ \$associatedClass = " . $this->getStubObjectBuilder()->getClassname() . "Peer::retrieveByPK(
+ ". trim($params) . ");
+ if (\$associatedClass === null) {
+ \$associatedClass = new ".$this->getStubObjectBuilder()->getClassname()."();";
+ foreach($table->getPrimaryKey() as $keyCol) {
+ $cfc=ucfirst($keyCol->getPhpName());
+ $clo=$keyCol->getName();
+ $const=$this->getColumnConstant($keyCol,
+ $this->getBuildProperty('dtoPrefix')
+ . $this->getStubObjectBuilder()->getClassname()
+ . $this->getBuildProperty('dtoSuffix'));
$script .= "
! if (\$this->isColumnModified($const))
! \$associatedClass->set".$cfc."(
! \$this->$clo);";
! }
! $script .= "
! }
! }
! ";
!
! foreach($table->getColumns() as $col) {
! if (!array_key_exists($col->getName(),$keys) || $isNew) {
! $cfc=ucfirst($col->getPhpName());
! $clo=$col->getName();
! $const=$this->getColumnConstant($col,
! $this->getBuildProperty('dtoPrefix')
! . $this->getStubObjectBuilder()->getClassname()
! . $this->getBuildProperty('dtoSuffix'));
! $script .= "
! if (\$this->isColumnModified($const))
! \$associatedClass->set".$cfc."(\$this->$clo);";
! }
! }
!
! $script .= "
!
! if (\$deepConversion) {
! ";
! foreach ($this->getTable()->getForeignKeys() as $fk) {
! $collName = $this->getFKVarName($fk);
! $className = $this->getForeignTable($fk)->getPhpName();
! $dtoClassName = $className. $this->getBuildProperty('dtoSuffix');
! $varName = $this->getFKPhpNameAffix($fk, $plural = false);
! $script .= "
! if (isset(\$this->$collName)) {
! \$associatedClass->set".$varName."(
! \$this->".$collName."->toOMObject(\$deepConversion));
! }
! ";
! } // foreach fk
!
! foreach($this->getTable()->getReferrers() as $refFK) {
! $collName = $this->getRefFKCollVarName($refFK);
! $className = OMBuilder::getNewObjectBuilder($refFK->getTable())->getObjectClassname();
! $dtoClassName = $className . $this->getBuildProperty('dtoSuffix');
! $varName = $this->getRefFKPhpNameAffix($refFK, $plural = true);
! $script .= "
! if (isset(\$this->$collName)) {
! \$associatedClass->init$varName();
! foreach (\$this->$collName as \$v) {
! \$associatedClass->add".$className."(\$v->toOMObject(\$deepConversion));
! }
! }
! ";
! } // foreach fk
!
! $script .= "
! }
!
! return \$associatedClass;
! }
";
+
}
!
} // PHP5DTOObjectBuilder
--- NEW FILE: PHP5ExtendComplexObjectBuilder.php ---
<?php
require_once 'propel/engine/builder/om/php5/PHP5ComplexObjectBuilder.php';
/**
* Generates a PHP5 Base object class with method that converts object to DTO.
*
* @author Jana Dohman <jana.dohman at iowa.gov>
* @package propel.engine.builder.om.php5
*/
class PHP5ExtendComplexObjectBuilder extends PHP5ComplexObjectBuilder {
/**
* Specifies the methods that are added as part of the basic OM class.
* This can be overridden by subclasses that wish to add more methods.
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
parent::addClassBody($script);
$this->addPropelClassConstructor($script);
}
/**
* Gets the package for the [base] object classes.
* @return string
*/
protected function getRootPackage()
{
$pkg = ($this->getTable()->getPackage() ? $this->getTable()->getPackage() : $this->getDatabase()->getPackage());
if (!$pkg) {
$pkg = $this->getBuildProperty('targetPackage');
}
return $pkg;
}
/**
* Adds the factory method which returns the DTO class from the specified Propel class.
* @param string &$script The script will be modified in this method.
*/
protected function addPropelClassConstructor(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Returns a ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')." object populated with values from
* the provided ".$this->getStubObjectBuilder()->getClassname()." object.
* @param ".$this->getStubObjectBuilder()->getClassname()." $omObject The class to map a DTO object from.
* @param boolean true if the conversion to ".$this->getStubObjectBuilder()->getClassname()." should
* include collections and associated objects.
* @return ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')."
*/
public function &toDTO(\$deepConversion=false)
{
include_once '". DataModelBuilder::getFilePath($this->getRootPackage(), null, '') . "/dto/" . $this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix') . ".php';
\$ret = new ".$this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix')."();
";
foreach($table->getColumns() as $col) {
$cfc=ucfirst($col->getPhpName());
$clo='set'.ucfirst($col->getPhpName()).'(';
$script .= "
\$ret->$clo\$this->get".$cfc."());";
}
$script .= "
\$ret->setNew(\$this->isNew());
if (\$deepConversion) {
";
foreach ($this->getTable()->getForeignKeys() as $fk) {
$collName = $this->getFKVarName($fk);
$className = $this->getForeignTable($fk)->getPhpName();
$dtoClassName = $className. $this->getBuildProperty('dtoSuffix');
$varName = $this->getFKPhpNameAffix($fk, $plural = false);
$script .= "
if (isset(\$this->$collName)) {
\$ret->set".$varName."(
\$this->".$collName."->toDTO(\$deepConversion));
}
";
} // foreach fk
foreach($this->getTable()->getReferrers() as $refFK) {
$collName = $this->getRefFKCollVarName($refFK);
$className = OMBuilder::getNewObjectBuilder($refFK->getTable())->getObjectClassname();
$dtoClassName = $className . $this->getBuildProperty('dtoSuffix');
$varName = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$script .= "
if (isset(\$this->$collName)) {
\$tempV = array();
foreach (\$this->$collName as \$v) {
\$tempV[] = \$v->toDTO(\$deepConversion);
}
\$ret->set$varName(\$tempV);
}
";
} // foreach fk
$script .= "
}
\$ret->resetModified();
return \$ret;
}
";
}
} // PHP5ExtendComplexObjectBuilder
Index: PHP5BaseManagerObjectBuilder.php
===================================================================
RCS file: /cvsroot/geeklog2/Geeklog_Generator/engine/builder/om/php5/PHP5BaseManagerObjectBuilder.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PHP5BaseManagerObjectBuilder.php 31 May 2007 20:11:47 -0000 1.1.1.1
--- PHP5BaseManagerObjectBuilder.php 26 Jul 2007 13:40:16 -0000 1.2
***************
*** 5,18 ****
/**
! * Generates a PHP5 base manager component class
! * with automatically generated named query methods and
* CRUD functions.
! *
* @author Jana Dohman <jana.dohman at iowa.gov>
* @package propel.engine.builder.om.php5
*/
! class PHP5BaseManagerObjectBuilder extends ObjectBuilder {
!
!
/**
* Gets the package for the [base] object classes.
--- 5,18 ----
/**
! * Generates a PHP5 base manager component class
! * with automatically generated named query methods and
* CRUD functions.
! *
* @author Jana Dohman <jana.dohman at iowa.gov>
* @package propel.engine.builder.om.php5
*/
! class PHP5BaseManagerObjectBuilder extends ObjectBuilder {
!
!
/**
* Gets the package for the [base] object classes.
***************
*** 40,44 ****
{
// Do nothing at this point as class stands alone.
! }
/**
--- 40,44 ----
{
// Do nothing at this point as class stands alone.
! }
/**
***************
*** 52,56 ****
$script .= "
! require_once '".$this->getStubObjectBuilder()->getClassFilePath()."';
require_once '".DataModelBuilder::getFilePath($this->getBuildProperty('daoFactoryDir'),null, '.php')."';
--- 52,56 ----
$script .= "
! require_once '". DataModelBuilder::getFilePath(parent::getPackage(), null, '') . "/dto/" . $this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix') . ".php';
require_once '".DataModelBuilder::getFilePath($this->getBuildProperty('daoFactoryDir'),null, '.php')."';
***************
*** 74,80 ****
";
}
!
/**
! * Specifies the public attributes that are added as part of the DTO
* OM class.
* @param string &$script The script will be modified in this method.
--- 74,80 ----
";
}
!
/**
! * Specifies the public attributes that are added as part of the DTO
* OM class.
* @param string &$script The script will be modified in this method.
***************
*** 97,101 ****
$paramList = '';
$typeCheckList = '';
!
foreach ($table->getPrimaryKey() as $keyCol) {
$phpName = '$' . strtolower(substr($keyCol->getPhpName(),0,1)) .
--- 97,101 ----
$paramList = '';
$typeCheckList = '';
!
foreach ($table->getPrimaryKey() as $keyCol) {
$phpName = '$' . strtolower(substr($keyCol->getPhpName(),0,1)) .
***************
*** 110,118 ****
if (is_null(' . $phpName . ')) {
throw new Exception(\'The parameter, ' . $phpName . ', to the call to the get' . $this->getStubObjectBuilder()->getClassname() . '() method of the ' . $this->getClassname() . ' class was null.\');
- }
- if (!is_' . $keyCol->getPhpType() . '(' . $phpName . ')) {
- throw new Exception(\'The parameter, ' . $phpName . ', to the call to the get' . $this->getStubObjectBuilder()->getClassname() . '() method of the ' . $this->getClassname() . ' class was not of the expected type, ' . $keyCol->getPhpType() . '.\');
}';
! }
$script .= "
--- 110,115 ----
if (is_null(' . $phpName . ')) {
throw new Exception(\'The parameter, ' . $phpName . ', to the call to the get' . $this->getStubObjectBuilder()->getClassname() . '() method of the ' . $this->getClassname() . ' class was null.\');
}';
! }
$script .= "
***************
*** 125,145 ****
public static function &get".$this->getStubObjectBuilder()->getClassname()."(" . $paramList . ") {" . $typeCheckList . "
\$associatedClass = new ".$this->getStubObjectBuilder()->getClassname()."();";
!
foreach ($table->getPrimaryKey() as $keyCol) {
! $phpName = '$' . strtolower(substr($keyCol->getPhpName(),0,1)) .
substr($keyCol->getPhpName(),1);
$script .= "
\$associatedClass->set".ucfirst($keyCol->getPhpName())."(".$phpName.");";
! }
!
$daoFactoryClass = $this->getBuildProperty('daoFactoryClass');
!
$script .= "
\$dao = ".$daoFactoryClass."::createDAO();
return \$dao->get(\$associatedClass);
! }
";
! }
/**
--- 122,142 ----
public static function &get".$this->getStubObjectBuilder()->getClassname()."(" . $paramList . ") {" . $typeCheckList . "
\$associatedClass = new ".$this->getStubObjectBuilder()->getClassname()."();";
!
foreach ($table->getPrimaryKey() as $keyCol) {
! $phpName = '(' . $keyCol->getPhpType() . ') $' . strtolower(substr($keyCol->getPhpName(),0,1)) .
substr($keyCol->getPhpName(),1);
$script .= "
\$associatedClass->set".ucfirst($keyCol->getPhpName())."(".$phpName.");";
! }
!
$daoFactoryClass = $this->getBuildProperty('daoFactoryClass');
!
$script .= "
\$dao = ".$daoFactoryClass."::createDAO();
return \$dao->get(\$associatedClass);
! }
";
! }
/**
***************
*** 149,153 ****
protected function addSaveMethod(&$script)
{
! $paramName = '$' .
strtolower(substr($this->getStubObjectBuilder()->getClassname(),0,1)) .
substr($this->getStubObjectBuilder()->getClassname(),1);
--- 146,150 ----
protected function addSaveMethod(&$script)
{
! $paramName = '$' .
strtolower(substr($this->getStubObjectBuilder()->getClassname(),0,1)) .
substr($this->getStubObjectBuilder()->getClassname(),1);
***************
*** 159,178 ****
* @param ".$this->getStubObjectBuilder()->getClassname()." " . $paramName . "
*/
! public static function save".$this->getStubObjectBuilder()->getClassname()."(".$this->getStubObjectBuilder()->getClassname()." &" . $paramName . ") {";
$daoFactoryClasspath = $this->getBuildProperty('daoFactoryClass');
!
$lastdotpos = strrpos($daoFactoryClasspath, '.');
! if ($lastdotpos)
$daoFactoryClasspath = ucfirst(substr($daoFactoryClasspath, $lastdotpos+1));
! else
$daoFactoryClasspath = ucfirst($daoFactoryClasspath);
$script .= "
! \$dao = ".$daoFactoryClasspath."::createDAO();
! return \$dao->save(".$paramName.");
! }
";
! }
!
/**
* Adds the delete method
--- 156,179 ----
* @param ".$this->getStubObjectBuilder()->getClassname()." " . $paramName . "
*/
! public static function save".$this->getStubObjectBuilder()->getClassname()."(&" . $paramName . ") {";
$daoFactoryClasspath = $this->getBuildProperty('daoFactoryClass');
!
$lastdotpos = strrpos($daoFactoryClasspath, '.');
! if ($lastdotpos)
$daoFactoryClasspath = ucfirst(substr($daoFactoryClasspath, $lastdotpos+1));
! else
$daoFactoryClasspath = ucfirst($daoFactoryClasspath);
$script .= "
! if (" . $paramName . " instanceof " . $this->getStubObjectBuilder()->getClassname() . " ||
! " . $paramName . " instanceof " . $this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix') . ") {
! \$dao = ".$daoFactoryClasspath."::createDAO();
! return \$dao->save(".$paramName.");
! }
! throw new Exception(\"The parameter was not an instance of either type " . $this->getStubObjectBuilder()->getClassname() . " or " . $this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix') . ".\");
! }
";
! }
!
/**
* Adds the delete method
***************
*** 181,185 ****
protected function addDeleteMethod(&$script)
{
! $paramName = '$' .
strtolower(substr($this->getStubObjectBuilder()->getClassname(),0,1)) .
substr($this->getStubObjectBuilder()->getClassname(),1);
--- 182,186 ----
protected function addDeleteMethod(&$script)
{
! $paramName = '$' .
strtolower(substr($this->getStubObjectBuilder()->getClassname(),0,1)) .
substr($this->getStubObjectBuilder()->getClassname(),1);
***************
*** 191,209 ****
* @param ".$this->getStubObjectBuilder()->getClassname()." " . $paramName . "
*/
! public static function delete".$this->getStubObjectBuilder()->getClassname()."(".$this->getStubObjectBuilder()->getClassname()." &" . $paramName . ") {";
$daoFactoryClasspath = $this->getBuildProperty('daoFactoryClass');
!
$lastdotpos = strrpos($daoFactoryClasspath, '.');
! if ($lastdotpos)
$daoFactoryClasspath = ucfirst(substr($daoFactoryClasspath, $lastdotpos+1));
! else
$daoFactoryClasspath = ucfirst($daoFactoryClasspath);
$script .= "
! \$dao = ".$daoFactoryClasspath."::createDAO();
! return \$dao->delete(".$paramName.");
! }
";
! }
/**
--- 192,215 ----
* @param ".$this->getStubObjectBuilder()->getClassname()." " . $paramName . "
*/
! public static function delete".$this->getStubObjectBuilder()->getClassname()."(&" . $paramName . ") {";
$daoFactoryClasspath = $this->getBuildProperty('daoFactoryClass');
!
$lastdotpos = strrpos($daoFactoryClasspath, '.');
! if ($lastdotpos)
$daoFactoryClasspath = ucfirst(substr($daoFactoryClasspath, $lastdotpos+1));
! else
$daoFactoryClasspath = ucfirst($daoFactoryClasspath);
$script .= "
!
! if (" . $paramName . " instanceof " . $this->getStubObjectBuilder()->getClassname() . " ||
! " . $paramName . " instanceof " . $this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix') . ") {
! \$dao = ".$daoFactoryClasspath."::createDAO();
! return \$dao->delete(".$paramName.");
! }
! throw new Exception(\"The parameter was not an instance of either type " . $this->getStubObjectBuilder()->getClassname() . " or " . $this->getStubObjectBuilder()->getClassname() . $this->getBuildProperty('dtoSuffix') . ".\");
! }
";
! }
/**
***************
*** 217,220 ****
";
}
!
} // PHP5BaseManagerObjectBuilder
--- 223,226 ----
";
}
!
} // PHP5BaseManagerObjectBuilder
More information about the geeklog-cvs
mailing list