CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,120 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Tools to support class & package inclusion and referencing.
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 1612 $
* @package propel.generator.builder.om
*/
class ClassTools
{
/**
* Gets just classname, given a dot-path to class.
* @param string $qualifiedName
* @return string
*/
public static function classname($qualifiedName)
{
$pos = strrpos($qualifiedName, '.');
if ($pos === false) {
return $qualifiedName; // there is no '.' in the qualifed name
} else {
return substr($qualifiedName, $pos + 1); // start just after '.'
}
}
/**
* Gets the path to be used in include()/require() statement.
*
* Supports multiple function signatures:
*
* (1) getFilePath($dotPathClass);
* (2) getFilePath($dotPathPrefix, $className);
* (3) getFilePath($dotPathPrefix, $className, $extension);
*
* @param string $path dot-path to class or to package prefix.
* @param string $classname class name
* @param string $extension The extension to use on the file.
* @return string The constructed file path.
*/
public static function getFilePath($path, $classname = null, $extension = '.php')
{
$path = strtr(ltrim($path, '.'), '.', '/');
if ($classname !== null) {
if ($path !== "") { $path .= '/'; }
return $path . $classname . $extension;
} else {
return $path . $extension;
}
}
/**
* Gets the basePeer path if specified for table/db.
* If not, will return 'propel.util.BasePeer'
* @return string
*/
public static function getBasePeer(Table $table) {
$class = $table->getBasePeer();
if ($class === null) {
$class = "propel.util.BasePeer";
}
return $class;
}
/**
* Gets the baseClass path if specified for table/db.
* If not, will return 'propel.om.BaseObject'
* @return string
*/
public static function getBaseClass(Table $table) {
$class = $table->getBaseClass();
if ($class === null) {
$class = "propel.om.BaseObject";
}
return $class;
}
/**
* Gets the interface path if specified for table.
* If not, will return 'propel.om.Persistent'.
* @return string
*/
public static function getInterface(Table $table) {
$interface = $table->getInterface();
if ($interface === null && !$table->isReadOnly()) {
$interface = "propel.om.Persistent";
}
return $interface;
}
/**
* Gets a list of PHP reserved words.
*
* @return array string[]
*/
public static function getPhpReservedWords()
{
return array(
'and', 'or', 'xor', 'exception', '__FILE__', '__LINE__',
'array', 'as', 'break', 'case', 'class', 'const', 'continue',
'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty',
'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile',
'eval', 'exit', 'extends', 'for', 'foreach', 'function', 'global',
'if', 'include', 'include_once', 'isset', 'list', 'new', 'print', 'require',
'require_once', 'return', 'static', 'switch', 'unset', 'use', 'var', 'while',
'__FUNCTION__', '__CLASS__', '__METHOD__', 'final', 'php_user_filter', 'interface',
'implements', 'extends', 'public', 'protected', 'private', 'abstract', 'clone', 'try', 'catch',
'throw', 'this', 'namespace'
);
}
}

View file

@ -0,0 +1,139 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/OMBuilder.php';
/**
* Generates the empty PHP5 stub class for object query
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
* @author Francois Zaninotto
* @package propel.generator.builder.om
*/
class ExtensionQueryBuilder extends OMBuilder
{
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getTable()->getPhpName() . 'Query';
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
$requiredClassFilePath = $this->getQueryBuilder()->getClassFilePath();
$script .="
require '".$requiredClassFilePath."';
";
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$this->declareClassFromBuilder($this->getQueryBuilder());
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseClassname = $this->getQueryBuilder()->getClassname();
$script .= "
/**
* Skeleton subclass for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
class ".$this->getClassname()." extends $baseClassname {
";
}
/**
* Specifies the methods that are added as part of the stub query class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see QueryBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
$this->applyBehaviorModifier('extensionQueryFilter', $script, "");
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @return boolean
*/
public function hasBehaviorModifier($hookName, $modifier = null)
{
return parent::hasBehaviorModifier($hookName, 'QueryBuilderModifier');
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @param string &$script The script will be modified in this method.
*/
public function applyBehaviorModifier($hookName, &$script, $tab = " ")
{
return $this->applyBehaviorModifierBase($hookName, 'QueryBuilderModifier', $script, $tab);
}
/**
* Checks whether any registered behavior content creator on that table exists a contentName
* @param string $contentName The name of the content as called from one of this class methods, e.g. "parentClassname"
*/
public function getBehaviorContent($contentName)
{
return $this->getBehaviorContentBase($contentName, 'QueryBuilderModifier');
}
}

View file

@ -0,0 +1,138 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/OMBuilder.php';
/**
* Generates the empty PHP5 stub query class for use with single table inheritance.
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
*
* @author François Zaninotto
* @package propel.generator.builder.om
*/
class ExtensionQueryInheritanceBuilder extends OMBuilder
{
/**
* The current child "object" we are operating on.
*/
protected $child;
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getChild()->getClassName() . 'Query';
}
/**
* Set the child object that we're operating on currrently.
* @param $child Inheritance
*/
public function setChild(Inheritance $child)
{
$this->child = $child;
}
/**
* Returns the child object we're operating on currently.
* @return Inheritance
* @throws BuildException - if child was not set.
*/
public function getChild()
{
if (!$this->child) {
throw new BuildException("The PHP5MultiExtendObjectBuilder needs to be told which child class to build (via setChild() method) before it can build the stub class.");
}
return $this->child;
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
$requiredClassFilePath = $this->getStubQueryBuilder()->getClassFilePath();
$script .="
require '".$requiredClassFilePath."';
";
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseBuilder = $this->getNewQueryInheritanceBuilder($this->getChild());
$this->declareClassFromBuilder($baseBuilder);
$baseClassname = $baseBuilder->getClassname();
$script .= "
/**
* Skeleton subclass for representing a query for one of the subclasses of the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
class " .$this->getClassname() . " extends " . $baseClassname . " {
";
}
/**
* Specifies the methods that are added as part of the stub object class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
}
} // MultiExtensionQueryBuilder

View file

@ -0,0 +1,526 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/DataModelBuilder.php';
/**
* Baseclass for OM-building classes.
*
* OM-building classes are those that build a PHP (or other) class to service
* a single table. This includes Peer classes, Entity classes, Map classes,
* Node classes, Nested Set classes, etc.
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
abstract class OMBuilder extends DataModelBuilder
{
/**
* Declared fully qualified classnames, to build the 'namespace' statements
* according to this table's namespace.
* @var array
*/
protected $declaredClasses = array();
/**
* Builds the PHP source for current class and returns it as a string.
*
* This is the main entry point and defines a basic structure that classes should follow.
* In most cases this method will not need to be overridden by subclasses. This method
* does assume that the output language is PHP code, so it will need to be overridden if
* this is not the case.
*
* @return string The resulting PHP sourcecode.
*/
public function build()
{
$this->validateModel();
$script = '';
if ($this->isAddIncludes()) {
$this->addIncludes($script);
}
$this->addClassOpen($script);
$this->addClassBody($script);
$this->addClassClose($script);
if($useStatements = $this->getUseStatements($ignoredNamespace = $this->getNamespace())) {
$script = $useStatements . $script;
}
if($namespaceStatement = $this->getNamespaceStatement()) {
$script = $namespaceStatement . $script;
}
//if($this->getTable()->getName() == 'book_club_list') die($ignoredNamespace);
return "<" . "?php
" . $script;
}
/**
* Validates the current table to make sure that it won't
* result in generated code that will not parse.
*
* This method may emit warnings for code which may cause problems
* and will throw exceptions for errors that will definitely cause
* problems.
*/
protected function validateModel()
{
// Validation is currently only implemented in the subclasses.
}
/**
* Creates a $obj = new Book(); code snippet. Can be used by frameworks, for instance, to
* extend this behavior, e.g. initialize the object after creating the instance or so.
*
* @return string Some code
*/
public function buildObjectInstanceCreationCode($objName, $clsName)
{
return "$objName = new $clsName();";
}
/**
* Returns the qualified (prefixed) classname that is being built by the current class.
* This method must be implemented by child classes.
* @return string
*/
abstract public function getUnprefixedClassname();
/**
* Returns the prefixed classname that is being built by the current class.
* @return string
* @see DataModelBuilder#prefixClassname()
*/
public function getClassname()
{
return $this->prefixClassname($this->getUnprefixedClassname());
}
/**
* Returns the namespaced classname if there is a namespace, and the raw classname otherwise
* @return string
*/
public function getFullyQualifiedClassname()
{
if ($namespace = $this->getNamespace()) {
return $namespace . '\\' . $this->getClassname();
} else {
return $this->getClassname();
}
}
/**
* Gets the dot-path representation of current class being built.
* @return string
*/
public function getClasspath()
{
if ($this->getPackage()) {
$path = $this->getPackage() . '.' . $this->getClassname();
} else {
$path = $this->getClassname();
}
return $path;
}
/**
* Gets the full path to the file for the current class.
* @return string
*/
public function getClassFilePath()
{
return ClassTools::getFilePath($this->getPackage(), $this->getClassname());
}
/**
* Gets package name for this table.
* This is overridden by child classes that have different packages.
* @return string
*/
public function getPackage()
{
$pkg = ($this->getTable()->getPackage() ? $this->getTable()->getPackage() : $this->getDatabase()->getPackage());
if (!$pkg) {
$pkg = $this->getBuildProperty('targetPackage');
}
return $pkg;
}
/**
* Returns filesystem path for current package.
* @return string
*/
public function getPackagePath()
{
return strtr($this->getPackage(), '.', '/');
}
/**
* Return the user-defined namespace for this table,
* or the database namespace otherwise.
*
* @return string
*/
public function getNamespace()
{
return $this->getTable()->getNamespace();
}
public function declareClassNamespace($class, $namespace = '')
{
if (isset($this->declaredClasses[$namespace])
&& in_array($class, $this->declaredClasses[$namespace])) {
return;
}
$this->declaredClasses[$namespace][] = $class;
}
public function declareClass($fullyQualifiedClassName)
{
$fullyQualifiedClassName = trim($fullyQualifiedClassName, '\\');
if (($pos = strrpos($fullyQualifiedClassName, '\\')) !== false) {
$this->declareClassNamespace(substr($fullyQualifiedClassName, $pos + 1), substr($fullyQualifiedClassName, 0, $pos));
} else {
// root namespace
$this->declareClassNamespace($fullyQualifiedClassName);
}
}
public function declareClassFromBuilder($builder)
{
$this->declareClassNamespace($builder->getClassname(), $builder->getNamespace());
}
public function declareClasses()
{
$args = func_get_args();
foreach ($args as $class) {
$this->declareClass($class);
}
}
public function getDeclaredClasses($namespace = null)
{
if (null !== $namespace && isset($this->declaredClasses[$namespace])) {
return $this->declaredClasses[$namespace];
} else {
return $this->declaredClasses;
}
}
public function getNamespaceStatement()
{
$namespace = $this->getNamespace();
if ($namespace != '') {
return sprintf("namespace %s;
", $namespace);
}
}
public function getUseStatements($ignoredNamespace = null)
{
$declaredClasses = $this->declaredClasses;
unset($declaredClasses[$ignoredNamespace]);
ksort($declaredClasses);
foreach ($declaredClasses as $namespace => $classes) {
sort($classes);
foreach ($classes as $class) {
$script .= sprintf("use %s\\%s;
", $namespace, $class);
}
}
return $script;
}
/**
* Shortcut method to return the [stub] peer classname for current table.
* This is the classname that is used whenever object or peer classes want
* to invoke methods of the peer classes.
* @return string (e.g. 'MyPeer')
* @see StubPeerBuilder::getClassname()
*/
public function getPeerClassname() {
return $this->getStubPeerBuilder()->getClassname();
}
/**
* Shortcut method to return the [stub] query classname for current table.
* This is the classname that is used whenever object or peer classes want
* to invoke methods of the query classes.
* @return string (e.g. 'Myquery')
* @see StubQueryBuilder::getClassname()
*/
public function getQueryClassname() {
return $this->getStubQueryBuilder()->getClassname();
}
/**
* Returns the object classname for current table.
* This is the classname that is used whenever object or peer classes want
* to invoke methods of the object classes.
* @return string (e.g. 'My')
* @see StubPeerBuilder::getClassname()
*/
public function getObjectClassname() {
return $this->getStubObjectBuilder()->getClassname();
}
/**
* Get the column constant name (e.g. PeerName::COLUMN_NAME).
*
* @param Column $col The column we need a name for.
* @param string $classname The Peer classname to use.
*
* @return string If $classname is provided, then will return $classname::COLUMN_NAME; if not, then the peername is looked up for current table to yield $currTablePeer::COLUMN_NAME.
*/
public function getColumnConstant($col, $classname = null)
{
if ($col === null) {
$e = new Exception("No col specified.");
print $e;
throw $e;
}
if ($classname === null) {
return $this->getBuildProperty('classPrefix') . $col->getConstantName();
}
// was it overridden in schema.xml ?
if ($col->getPeerName()) {
$const = strtoupper($col->getPeerName());
} else {
$const = strtoupper($col->getName());
}
return $classname.'::'.$const;
}
/**
* Gets the basePeer path if specified for table/db.
* If not, will return 'propel.util.BasePeer'
* @return string
*/
public function getBasePeer(Table $table) {
$class = $table->getBasePeer();
if ($class === null) {
$class = "propel.util.BasePeer";
}
return $class;
}
/**
* Convenience method to get the foreign Table object for an fkey.
* @deprecated use ForeignKey::getForeignTable() instead
* @return Table
*/
protected function getForeignTable(ForeignKey $fk)
{
return $this->getTable()->getDatabase()->getTable($fk->getForeignTableName());
}
/**
* Convenience method to get the default Join Type for a relation.
* If the key is required, an INNER JOIN will be returned, else a LEFT JOIN will be suggested,
* unless the schema is provided with the DefaultJoin attribute, which overrules the default Join Type
*
* @param ForeignKey $fk
* @return string
*/
protected function getJoinType(ForeignKey $fk)
{
return $fk->getDefaultJoin() ?
"'".$fk->getDefaultJoin()."'" :
($fk->isLocalColumnsRequired() ? 'Criteria::INNER_JOIN' : 'Criteria::LEFT_JOIN');
}
/**
* Gets the PHP method name affix to be used for fkeys for the current table (not referrers to this table).
*
* The difference between this method and the getRefFKPhpNameAffix() method is that in this method the
* classname in the affix is the foreign table classname.
*
* @param ForeignKey $fk The local FK that we need a name for.
* @param boolean $plural Whether the php name should be plural (e.g. initRelatedObjs() vs. addRelatedObj()
* @return string
*/
public function getFKPhpNameAffix(ForeignKey $fk, $plural = false)
{
if ($fk->getPhpName()) {
if ($plural) {
return $this->getPluralizer()->getPluralForm($fk->getPhpName());
} else {
return $fk->getPhpName();
}
} else {
$className = $fk->getForeignTable()->getPhpName();
if ($plural) {
$className = $this->getPluralizer()->getPluralForm($className);
}
return $className . $this->getRelatedBySuffix($fk);
}
}
/**
* Gets the "RelatedBy*" suffix (if needed) that is attached to method and variable names.
*
* The related by suffix is based on the local columns of the foreign key. If there is more than
* one column in a table that points to the same foreign table, then a 'RelatedByLocalColName' suffix
* will be appended.
*
* @return string
*/
protected static function getRelatedBySuffix(ForeignKey $fk)
{
$relCol = '';
foreach ($fk->getLocalForeignMapping() as $localColumnName => $foreignColumnName) {
$localTable = $fk->getTable();
$localColumn = $localTable->getColumn($localColumnName);
if (!$localColumn) {
throw new Exception("Could not fetch column: $columnName in table " . $localTable->getName());
}
if (count($localTable->getForeignKeysReferencingTable($fk->getForeignTableName())) > 1
|| count($fk->getForeignTable()->getForeignKeysReferencingTable($fk->getTableName())) > 0
|| $fk->getForeignTableName() == $fk->getTableName()) {
// self referential foreign key, or several foreign keys to the same table, or cross-reference fkey
$relCol .= $localColumn->getPhpName();
}
}
if ($relCol != '') {
$relCol = 'RelatedBy' . $relCol;
}
return $relCol;
}
/**
* Gets the PHP method name affix to be used for referencing foreign key methods and variable names (e.g. set????(), $coll???).
*
* The difference between this method and the getFKPhpNameAffix() method is that in this method the
* classname in the affix is the classname of the local fkey table.
*
* @param ForeignKey $fk The referrer FK that we need a name for.
* @param boolean $plural Whether the php name should be plural (e.g. initRelatedObjs() vs. addRelatedObj()
* @return string
*/
public function getRefFKPhpNameAffix(ForeignKey $fk, $plural = false)
{
if ($fk->getRefPhpName()) {
if ($plural) {
return $this->getPluralizer()->getPluralForm($fk->getRefPhpName());
} else {
return $fk->getRefPhpName();
}
} else {
$className = $fk->getTable()->getPhpName();
if ($plural) {
$className = $this->getPluralizer()->getPluralForm($className);
}
return $className . $this->getRefRelatedBySuffix($fk);
}
}
protected static function getRefRelatedBySuffix(ForeignKey $fk)
{
$relCol = '';
foreach ($fk->getLocalForeignMapping() as $localColumnName => $foreignColumnName) {
$localTable = $fk->getTable();
$localColumn = $localTable->getColumn($localColumnName);
if (!$localColumn) {
throw new Exception("Could not fetch column: $columnName in table " . $localTable->getName());
}
$foreignKeysToForeignTable = $localTable->getForeignKeysReferencingTable($fk->getForeignTableName());
if ($fk->getForeignTableName() == $fk->getTableName()) {
// self referential foreign key
$relCol .= $fk->getForeignTable()->getColumn($foreignColumnName)->getPhpName();
if (count($foreignKeysToForeignTable) > 1) {
// several self-referential foreign keys
$relCol .= array_search($fk, $foreignKeysToForeignTable);
}
} elseif (count($foreignKeysToForeignTable) > 1 || count($fk->getForeignTable()->getForeignKeysReferencingTable($fk->getTableName())) > 0) {
// several foreign keys to the same table, or symmetrical foreign key in foreign table
$relCol .= $localColumn->getPhpName();
}
}
if ($relCol != '') {
$relCol = 'RelatedBy' . $relCol;
}
return $relCol;
}
/**
* Whether to add the include statements.
* This is based on the build property propel.addIncludes
*/
protected function isAddIncludes()
{
return $this->getBuildProperty('addIncludes');
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @param string $modifier The name of the modifier object providing the method in the behavior
* @return boolean
*/
public function hasBehaviorModifier($hookName, $modifier)
{
$modifierGetter = 'get' . $modifier;
foreach ($this->getTable()->getBehaviors() as $behavior) {
if(method_exists($behavior->$modifierGetter(), $hookName)) {
return true;
}
}
return false;
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @param string $modifier The name of the modifier object providing the method in the behavior
* @param string &$script The script will be modified in this method.
*/
public function applyBehaviorModifierBase($hookName, $modifier, &$script, $tab = " ")
{
$modifierGetter = 'get' . $modifier;
foreach ($this->getTable()->getBehaviors() as $behavior) {
$modifier = $behavior->$modifierGetter();
if(method_exists($modifier, $hookName)) {
if (strpos($hookName, 'Filter') !== false) {
// filter hook: the script string will be modified by the behavior
$modifier->$hookName($script, $this);
} else {
// regular hook: the behavior returns a string to append to the script string
$script .= "\n" . $tab . '// ' . $behavior->getName() . " behavior\n";
$script .= preg_replace('/^/m', $tab, $modifier->$hookName($this));
}
}
}
}
/**
* Checks whether any registered behavior content creator on that table exists a contentName
* @param string $contentName The name of the content as called from one of this class methods, e.g. "parentClassname"
* @param string $modifier The name of the modifier object providing the method in the behavior
*/
public function getBehaviorContentBase($contentName, $modifier)
{
$modifierGetter = 'get' . $modifier;
foreach ($this->getTable()->getBehaviors() as $behavior) {
$modifier = $behavior->$modifierGetter();
if(method_exists($modifier, $contentName)) {
return $modifier->$contentName($this);
}
}
}
}

View file

@ -0,0 +1,186 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/OMBuilder.php';
/**
* Base class for Peer-building classes.
*
* This class is designed so that it can be extended by a PHP4PeerBuilder in addition
* to the "standard" PHP5PeerBuilder and PHP5ComplexOMPeerBuilder. Hence, this class
* should not have any actual template code in it -- simply basic logic & utility
* methods.
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
abstract class ObjectBuilder extends OMBuilder
{
/**
* Constructs a new PeerBuilder subclass.
*/
public function __construct(Table $table) {
parent::__construct($table);
}
/**
* This method adds the contents of the generated class to the script.
*
* This method is abstract and should be overridden by the subclasses.
*
* Hint: Override this method in your subclass if you want to reorganize or
* drastically change the contents of the generated peer class.
*
* @param string &$script The script will be modified in this method.
*/
abstract protected function addClassBody(&$script);
/**
* Adds the getter methods for the column values.
* This is here because it is probably generic enough to apply to templates being generated
* in different langauges (e.g. PHP4 and PHP5).
* @param string &$script The script will be modified in this method.
*/
protected function addColumnAccessorMethods(&$script)
{
$table = $this->getTable();
foreach ($table->getColumns() as $col) {
// if they're not using the DateTime class than we will generate "compatibility" accessor method
if ($col->getType() === PropelTypes::DATE || $col->getType() === PropelTypes::TIME || $col->getType() === PropelTypes::TIMESTAMP) {
$this->addTemporalAccessor($script, $col);
} else {
$this->addDefaultAccessor($script, $col);
}
if ($col->isLazyLoad()) {
$this->addLazyLoader($script, $col);
}
}
}
/**
* Adds the mutator (setter) methods for setting column values.
* This is here because it is probably generic enough to apply to templates being generated
* in different langauges (e.g. PHP4 and PHP5).
* @param string &$script The script will be modified in this method.
*/
protected function addColumnMutatorMethods(&$script)
{
foreach ($this->getTable()->getColumns() as $col) {
if ($col->isLobType()) {
$this->addLobMutator($script, $col);
} elseif ($col->getType() === PropelTypes::DATE || $col->getType() === PropelTypes::TIME || $col->getType() === PropelTypes::TIMESTAMP) {
$this->addTemporalMutator($script, $col);
} else {
$this->addDefaultMutator($script, $col);
}
}
}
/**
* Gets the baseClass path if specified for table/db.
* If not, will return 'propel.om.BaseObject'
* @return string
*/
protected function getBaseClass() {
$class = $this->getTable()->getBaseClass();
if ($class === null) {
$class = "propel.om.BaseObject";
}
return $class;
}
/**
* Gets the interface path if specified for current table.
* If not, will return 'propel.om.Persistent'.
* @return string
*/
protected function getInterface() {
$interface = $this->getTable()->getInterface();
if ($interface === null && !$this->getTable()->isReadOnly()) {
$interface = "propel.om.Persistent";
}
return $interface;
}
/**
* Whether to add the generic mutator methods (setByName(), setByPosition(), fromArray()).
* This is based on the build property propel.addGenericMutators, and also whether the
* table is read-only or an alias.
*/
protected function isAddGenericMutators()
{
$table = $this->getTable();
return (!$table->isAlias() && $this->getBuildProperty('addGenericMutators') && !$table->isReadOnly());
}
/**
* Whether to add the generic accessor methods (getByName(), getByPosition(), toArray()).
* This is based on the build property propel.addGenericAccessors, and also whether the
* table is an alias.
*/
protected function isAddGenericAccessors()
{
$table = $this->getTable();
return (!$table->isAlias() && $this->getBuildProperty('addGenericAccessors'));
}
/**
* Whether to add the validate() method.
* This is based on the build property propel.addValidateMethod
*/
protected function isAddValidateMethod()
{
return $this->getBuildProperty('addValidateMethod');
}
protected function hasDefaultValues()
{
foreach ($this->getTable()->getColumns() as $col) {
if($col->getDefaultValue() !== null) return true;
}
return false;
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @return boolean
*/
public function hasBehaviorModifier($hookName, $modifier = null)
{
return parent::hasBehaviorModifier($hookName, 'ObjectBuilderModifier');
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @param string &$script The script will be modified in this method.
*/
public function applyBehaviorModifier($hookName, &$script, $tab = " ")
{
return $this->applyBehaviorModifierBase($hookName, 'ObjectBuilderModifier', $script, $tab);
}
/**
* Checks whether any registered behavior content creator on that table exists a contentName
* @param string $contentName The name of the content as called from one of this class methods, e.g. "parentClassname"
*/
public function getBehaviorContent($contentName)
{
return $this->getBehaviorContentBase($contentName, 'ObjectBuilderModifier');
}
}

View file

@ -0,0 +1,111 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/ObjectBuilder.php';
/**
* Generates the empty PHP5 stub node object class for user object model (OM).
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
* This class replaces the ExtensionNode.tpl, with the intent of being easier for users
* to customize (through extending & overriding).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5ExtensionNodeBuilder extends ObjectBuilder
{
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getTable()->getPhpName() . 'Node';
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
$script .= "
require '".$this->getNodeBuilder()->getClassFilePath()."';
";
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseClassname = $this->getNodeBuilder()->getClassname();
$script .= "
/**
* Skeleton subclass for representing a node from the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
class ".$this->getClassname()." extends $baseClassname {
";
}
/**
* Specifies the methods that are added as part of the stub object class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
// there is no class body
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
}
} // PHP5ExtensionObjectBuilder

View file

@ -0,0 +1,112 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/PeerBuilder.php';
/**
* Generates the empty PHP5 stub node peer class for user object model (OM).
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
* This class replaces the ExtensionNodePeer.tpl, with the intent of being easier for users
* to customize (through extending & overriding).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5ExtensionNodePeerBuilder extends PeerBuilder
{
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getStubNodeBuilder()->getClassname() . 'Peer';
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
$script .="
require '".$this->getNodePeerBuilder()->getClassFilePath()."';
";
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseClassname = $this->getNodePeerBuilder()->getClassname();
$script .= "
/**
* Skeleton subclass for performing query and update operations on nodes of the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
class ".$this->getClassname()." extends $baseClassname {
";
}
/**
* Specifies the methods that are added as part of the stub peer class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
// there is no class body
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
}
} // PHP5ExtensionPeerBuilder

View file

@ -0,0 +1,133 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/ObjectBuilder.php';
/**
* Generates the empty PHP5 stub object class for user object model (OM).
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
* This class replaces the ExtensionObject.tpl, with the intent of being easier for users
* to customize (through extending & overriding).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5ExtensionObjectBuilder extends ObjectBuilder
{
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getTable()->getPhpName();
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
switch($this->getTable()->treeMode()) {
case 'NestedSet':
$requiredClassFilePath = $this->getNestedSetBuilder()->getClassFilePath();
break;
case 'MaterializedPath':
case 'AdjacencyList':
default:
$requiredClassFilePath = $this->getObjectBuilder()->getClassFilePath();
break;
}
$script .="
require '".$requiredClassFilePath."';
";
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$this->declareClassFromBuilder($this->getObjectBuilder());
$tableName = $table->getName();
$tableDesc = $table->getDescription();
switch($table->treeMode()) {
case 'NestedSet':
$baseClassname = $this->getNestedSetBuilder()->getClassname();
break;
case 'MaterializedPath':
case "AdjacencyList":
default:
$baseClassname = $this->getObjectBuilder()->getClassname();
break;
}
$script .= "
/**
* Skeleton subclass for representing a row from the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
".($table->isAbstract() ? "abstract " : "")."class ".$this->getClassname()." extends $baseClassname {
";
}
/**
* Specifies the methods that are added as part of the stub object class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
$this->applyBehaviorModifier('extensionObjectFilter', $script, "");
}
} // PHP5ExtensionObjectBuilder

View file

@ -0,0 +1,136 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/PeerBuilder.php';
/**
* Generates the empty PHP5 stub peer class for user object model (OM).
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
* This class replaces the ExtensionPeer.tpl, with the intent of being easier for users
* to customize (through extending & overriding).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5ExtensionPeerBuilder extends PeerBuilder
{
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getStubObjectBuilder()->getUnprefixedClassname() . 'Peer';
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
switch($this->getTable()->treeMode()) {
case 'NestedSet':
$requiredClassFilePath = $this->getNestedSetPeerBuilder()->getClassFilePath();
break;
case 'MaterializedPath':
case 'AdjacencyList':
default:
$requiredClassFilePath = $this->getPeerBuilder()->getClassFilePath();
break;
}
$script .="
require '".$requiredClassFilePath."';
";
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$this->declareClassFromBuilder($this->getPeerBuilder());
$tableName = $table->getName();
$tableDesc = $table->getDescription();
switch($table->treeMode()) {
case 'NestedSet':
$baseClassname = $this->getNestedSetPeerBuilder()->getClassname();
break;
case 'MaterializedPath':
case 'AdjacencyList':
default:
$baseClassname = $this->getPeerBuilder()->getClassname();
break;
}
$script .= "
/**
* Skeleton subclass for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
class ".$this->getClassname()." extends $baseClassname {
";
}
/**
* Specifies the methods that are added as part of the stub peer class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
// there is no class body
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
$this->applyBehaviorModifier('extensionPeerFilter', $script, "");
}
} // PHP5ExtensionPeerBuilder

View file

@ -0,0 +1,108 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/ObjectBuilder.php';
/**
* Generates the empty PHP5 stub interface for user object model (OM).
*
* This class produces the empty stub interface when the interface="" attribute is used
* in the the schema xml.
*
* This class replaces the Interface.tpl, with the intent of being easier for users
* to customize (through extending & overriding).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5InterfaceBuilder extends ObjectBuilder
{
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return ClassTools::classname($this->getInterface());
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseClassname = $this->getObjectBuilder()->getClassname();
$script .= "
/**
* This is an interface that should be filled with the public api of the $tableName objects.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional method declarations to this interface to meet the
* application requirements. This interface will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
interface ".$this->getClassname()." {
";
}
/**
* Specifies the methods that are added as part of the stub object class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
// there is no class body
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
}
} // PHP5ExtensionObjectBuilder

View file

@ -0,0 +1,196 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/ObjectBuilder.php';
/**
* Generates the empty PHP5 stub object class for use with inheritance in the user object model (OM).
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
* This class replaces the MultiExtendObject.tpl, with the intent of being easier for users
* to customize (through extending & overriding).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5MultiExtendObjectBuilder extends ObjectBuilder
{
/**
* The current child "object" we are operating on.
*/
private $child;
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getChild()->getClassname();
}
/**
* Override method to return child package, if specified.
* @return string
*/
public function getPackage()
{
return ($this->child->getPackage() ? $this->child->getPackage() : parent::getPackage());
}
/**
* Set the child object that we're operating on currrently.
* @param $child Inheritance
*/
public function setChild(Inheritance $child)
{
$this->child = $child;
}
/**
* Returns the child object we're operating on currently.
* @return Inheritance
* @throws BuildException - if child was not set.
*/
public function getChild()
{
if (!$this->child) {
throw new BuildException("The PHP5MultiExtendObjectBuilder needs to be told which child class to build (via setChild() method) before it can build the stub class.");
}
return $this->child;
}
/**
* Returns classpath to parent class.
* @return string
*/
protected function getParentClasspath()
{
if ($this->getChild()->getAncestor()) {
return $this->getChild()->getAncestor();
} else {
return $this->getObjectBuilder()->getClasspath();
}
}
/**
* Returns classname of parent class.
* @return string
*/
protected function getParentClassname()
{
return ClassTools::classname($this->getParentClasspath());
}
/**
* Gets the file path to the parent class.
* @return string
*/
protected function getParentClassFilePath()
{
return ClassTools::getFilePath($this->getParentClasspath());
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
if ($this->getChild()->getAncestor()) {
$this->declareClassFromBuilder($this->getNewStubObjectBuilder($this->getDatabase()->getTableByPhpName($this->getChild()->getAncestor())));
} else {
$this->declareClassFromBuilder($this->getObjectBuilder());
}
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseClassname = $this->getObjectBuilder()->getClassname();
$script .= "
/**
* Skeleton subclass for representing a row from one of the subclasses of the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
class ".$this->getClassname()." extends ".$this->getParentClassname()." {
";
}
/**
* Specifies the methods that are added as part of the stub object class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
$this->declareClassFromBuilder($this->getStubPeerBuilder());
$child = $this->getChild();
$col = $child->getColumn();
$cfc = $col->getPhpName();
$const = "CLASSKEY_".strtoupper($child->getKey());
$script .= "
/**
* Constructs a new ".$this->getChild()->getClassname()." class, setting the ".$col->getName()." column to ".$this->getPeerClassname()."::$const.
*/
public function __construct()
{";
$script .= "
parent::__construct();
\$this->set$cfc(".$this->getPeerClassname()."::CLASSKEY_".strtoupper($child->getKey()).");
}
";
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
}
} // PHP5ExtensionObjectBuilder

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,754 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/PeerBuilder.php';
/**
* Generates a PHP5 tree node Peer class for user object model (OM).
*
* This class produces the base tree node object class (e.g. BaseMyTable) which contains all
* the custom-built accessor and setter methods.
*
* This class replaces the Node.tpl, with the intent of being easier for users
* to customize (through extending & overriding).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5NodePeerBuilder extends PeerBuilder
{
/**
* Gets the package for the [base] object classes.
* @return string
*/
public function getPackage()
{
return parent::getPackage() . ".om";
}
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getBuildProperty('basePrefix') . $this->getStubNodePeerBuilder()->getUnprefixedClassname();
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$script .= "
/**
* Base static class for performing query operations on the tree contained by the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* @package propel.generator.".$this->getPackage()."
*/
abstract class ".$this->getClassname()." {
";
}
/**
* 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)
{
$table = $this->getTable();
// FIXME
// - Probably the build needs to be customized for supporting
// tables that are "aliases". -- definitely a fringe usecase, though.
$this->addConstants($script);
$this->addIsCodeBase($script);
$this->addRetrieveMethods($script);
$this->addCreateNewRootNode($script);
$this->addInsertNewRootNode($script);
$this->addMoveNodeSubTree($script);
$this->addDeleteNodeSubTree($script);
$this->addBuildFamilyCriteria($script);
$this->addBuildTree($script);
$this->addPopulateNodes($script);
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
}
protected function addConstants(&$script)
{
$table = $this->getTable();
$npath_colname = '';
$npath_phpname = '';
$npath_len = 0;
$npath_sep = '';
foreach ($table->getColumns() as $col) {
if ($col->isNodeKey()) {
$npath_colname = $table->getName() . '.' . strtoupper($col->getName());
$npath_phpname = $col->getPhpName();
$npath_len = $col->getSize();
$npath_sep = $col->getNodeKeySep();
break;
}
}
$script .= "
const NPATH_COLNAME = '$npath_colname';
const NPATH_PHPNAME = '$npath_phpname';
const NPATH_SEP = '$npath_sep';
const NPATH_LEN = $npath_len;
";
}
protected function addIsCodeBase(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$script .= "
/**
* Temp function for CodeBase hacks that will go away.
*/
public static function isCodeBase(\$con = null)
{
if (\$con === null)
\$con = Propel::getConnection($peerClassname::DATABASE_NAME);
return (get_class(\$con) == 'ODBCConnection' &&
get_class(\$con->getAdapter()) == 'CodeBaseAdapter');
}
";
}
protected function addCreateNewRootNode(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Create a new Node at the top of tree. This method will destroy any
* existing root node (along with its children).
*
* Use at your own risk!
*
* @param $objectClassname Object wrapped by new node.
* @param PropelPDO Connection to use.
* @return $nodeObjectClassname
* @throws PropelException
*/
public static function createNewRootNode(\$obj, PropelPDO \$con = null)
{
if (\$con === null)
\$con = Propel::getConnection($peerClassname::DATABASE_NAME, Propel::CONNECTION_WRITE);
\$con->beginTransaction();
try {
self::deleteNodeSubTree('1', \$con);
\$setNodePath = 'set' . self::NPATH_PHPNAME;
\$obj->\$setNodePath('1');
\$obj->save(\$con);
\$con->commit();
} catch (PropelException \$e) {
\$con->rollBack();
throw \$e;
}
return new $nodeObjectClassname(\$obj);
}
";
}
protected function addInsertNewRootNode(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Inserts a new Node at the top of tree. Any existing root node (along with
* its children) will be made a child of the new root node. This is a
* safer alternative to createNewRootNode().
*
* @param $objectClassname Object wrapped by new node.
* @param PropelPDO Connection to use.
* @return $nodeObjectClassname
* @throws PropelException
*/
public static function insertNewRootNode(\$obj, PropelPDO \$con = null)
{
if (\$con === null)
\$con = Propel::getConnection($peerClassname::DATABASE_NAME, Propel::CONNECTION_WRITE);
\$con->beginTransaction();
try {
// Move root tree to an invalid node path.
$nodePeerClassname::moveNodeSubTree('1', '0', \$con);
\$setNodePath = 'set' . self::NPATH_PHPNAME;
// Insert the new root node.
\$obj->\$setNodePath('1');
\$obj->save(\$con);
// Move the old root tree as a child of the new root.
$nodePeerClassname::moveNodeSubTree('0', '1' . self::NPATH_SEP . '1', \$con);
\$con->commit();
} catch (PropelException \$e) {
\$con->rollBack();
throw \$e;
}
return new $nodeObjectClassname(\$obj);
}
";
}
/**
* Adds the methods for retrieving nodes.
*/
protected function addRetrieveMethods(&$script)
{
$this->addRetrieveNodes($script);
$this->addRetrieveNodeByPK($script);
$this->addRetrieveNodeByNP($script);
$this->addRetrieveRootNode($script);
}
protected function addRetrieveNodes(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$script .= "
/**
* Retrieves an array of tree nodes based on specified criteria. Optionally
* includes all parent and/or child nodes of the matching nodes.
*
* @param Criteria Criteria to use.
* @param boolean True if ancestors should also be retrieved.
* @param boolean True if descendants should also be retrieved.
* @param PropelPDO Connection to use.
* @return array Array of root nodes.
*/
public static function retrieveNodes(\$criteria, \$ancestors = false, \$descendants = false, PropelPDO \$con = null)
{
\$criteria = $nodePeerClassname::buildFamilyCriteria(\$criteria, \$ancestors, \$descendants);
\$stmt = ".$this->getStubPeerBuilder()->getClassname()."::doSelectStmt(\$criteria, \$con);
return self::populateNodes(\$stmt, \$criteria);
}
";
}
protected function addRetrieveNodeByPK(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Retrieves a tree node based on a primary key. Optionally includes all
* parent and/or child nodes of the matching node.
*
* @param mixed $objectClassname primary key (array for composite keys)
* @param boolean True if ancestors should also be retrieved.
* @param boolean True if descendants should also be retrieved.
* @param PropelPDO Connection to use.
* @return $nodeObjectClassname
*/
public static function retrieveNodeByPK(\$pk, \$ancestors = false, \$descendants = false, PropelPDO \$con = null)
{
throw new PropelException('retrieveNodeByPK() not implemented yet.');
}
";
}
protected function addRetrieveNodeByNP(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Retrieves a tree node based on a node path. Optionally includes all
* parent and/or child nodes of the matching node.
*
* @param string Node path to retrieve.
* @param boolean True if ancestors should also be retrieved.
* @param boolean True if descendants should also be retrieved.
* @param PropelPDO Connection to use.
* @return $objectClassname
*/
public static function retrieveNodeByNP(\$np, \$ancestors = false, \$descendants = false, PropelPDO \$con = null)
{
\$criteria = new Criteria($peerClassname::DATABASE_NAME);
\$criteria->add(self::NPATH_COLNAME, \$np, Criteria::EQUAL);
\$criteria = self::buildFamilyCriteria(\$criteria, \$ancestors, \$descendants);
\$stmt = $peerClassname::doSelectStmt(\$criteria, \$con);
\$nodes = self::populateNodes(\$stmt, \$criteria);
return (count(\$nodes) == 1 ? \$nodes[0] : null);
}
";
}
protected function addRetrieveRootNode(&$script)
{
$script .= "
/**
* Retrieves the root node.
*
* @param string Node path to retrieve.
* @param boolean True if descendants should also be retrieved.
* @param PropelPDO Connection to use.
* @return ".$this->getStubNodeBuilder()->getClassname()."
*/
public static function retrieveRootNode(\$descendants = false, PropelPDO \$con = null)
{
return self::retrieveNodeByNP('1', false, \$descendants, \$con);
}
";
}
protected function addMoveNodeSubTree(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Moves the node subtree at srcpath to the dstpath. This method is intended
* for internal use by the BaseNode object. Note that it does not check for
* preexisting nodes at the dstpath. It also does not update the node path
* of any Node objects that might currently be in memory.
*
* Use at your own risk!
*
* @param string Source node path to move (root of the src subtree).
* @param string Destination node path to move to (root of the dst subtree).
* @param PropelPDO Connection to use.
* @return void
* @throws PropelException
* @todo This is currently broken for simulated 'onCascadeDelete's.
* @todo Need to abstract the SQL better. The CONCAT sql function doesn't
* seem to be standardized (i.e. mssql), so maybe it needs to be moved
* to DBAdapter.
*/
public static function moveNodeSubTree(\$srcPath, \$dstPath, PropelPDO \$con = null)
{
if (substr(\$dstPath, 0, strlen(\$srcPath)) == \$srcPath)
throw new PropelException('Cannot move a node subtree within itself.');
if (\$con === null)
\$con = Propel::getConnection($peerClassname::DATABASE_NAME, Propel::CONNECTION_WRITE);
/**
* Example:
* UPDATE table
* SET npath = CONCAT('1.3', SUBSTRING(npath, 6, 74))
* WHERE npath = '1.2.2' OR npath LIKE '1.2.2.%'
*/
\$npath = $nodePeerClassname::NPATH_COLNAME;
//the following dot isn`t mean`t a nodeKeySeperator
\$setcol = substr(\$npath, strrpos(\$npath, '.')+1);
\$setcollen = $nodePeerClassname::NPATH_LEN;
\$db = Propel::getDb($peerClassname::DATABASE_NAME);
// <hack>
if ($nodePeerClassname::isCodeBase(\$con))
{
// This is a hack to get CodeBase working. It will eventually be removed.
// It is a workaround for the following CodeBase bug:
// -Prepared statement parameters cannot be embedded in SQL functions (i.e. CONCAT)
\$sql = \"UPDATE \" . $peerClassname::TABLE_NAME . \" \" .
\"SET \$setcol=\" . \$db->concatString(\"'\$dstPath'\", \$db->subString(\$npath, strlen(\$srcPath)+1, \$setcollen)) . \" \" .
\"WHERE \$npath = '\$srcPath' OR \$npath LIKE '\" . \$srcPath . $nodePeerClassname::NPATH_SEP . \"%'\";
\$con->executeUpdate(\$sql);
}
else
{
// </hack>
\$sql = \"UPDATE \" . $peerClassname::TABLE_NAME . \" \" .
\"SET \$setcol=\" . \$db->concatString('?', \$db->subString(\$npath, '?', '?')) . \" \" .
\"WHERE \$npath = ? OR \$npath LIKE ?\";
\$stmt = \$con->prepare(\$sql);
\$stmt->bindValue(1, \$dstPath); // string
\$srcPathPlus1 = strlen(\$srcPath)+1;
\$stmt->bindValue(2, \$srcPathPlus1); // int
\$stmt->bindValue(3, \$setcollen);// int
\$stmt->bindValue(4, \$srcPath);// string
\$srcPathWC = \$srcPath . $nodePeerClassname::NPATH_SEP . '%';
\$stmt->bindValue(5, \$srcPathWC); // string
\$stmt->execute();
// <hack>
}
}
";
}
protected function addDeleteNodeSubTree(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Deletes the node subtree at the specified node path from the database.
*
* @param string Node path to delete
* @param PropelPDO Connection to use.
* @return void
* @throws PropelException
* @todo This is currently broken for simulated 'onCascadeDelete's.
*/
public static function deleteNodeSubTree(\$nodePath, PropelPDO \$con = null)
{
if (\$con === null)
\$con = Propel::getConnection($peerClassname::DATABASE_NAME, Propel::CONNECTION_WRITE);
/**
* DELETE FROM table
* WHERE npath = '1.2.2' OR npath LIKE '1.2.2.%'
*/
\$criteria = new Criteria($peerClassname::DATABASE_NAME);
\$criteria->add($nodePeerClassname::NPATH_COLNAME, \$nodePath, Criteria::EQUAL);
\$criteria->addOr($nodePeerClassname::NPATH_COLNAME, \$nodePath . self::NPATH_SEP . '%', Criteria::LIKE);
{$this->basePeerClassname}::doDelete(\$criteria, \$con);
}
";
}
protected function addBuildFamilyCriteria(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Builds the criteria needed to retrieve node ancestors and/or descendants.
*
* @param Criteria Criteria to start with
* @param boolean True if ancestors should be retrieved.
* @param boolean True if descendants should be retrieved.
* @return Criteria
*/
public static function buildFamilyCriteria(\$criteria, \$ancestors = false, \$descendants = false)
{
/*
Example SQL to retrieve nodepath '1.2.3' with both ancestors and descendants:
SELECT L.NPATH, L.LABEL, test.NPATH, UCASE(L.NPATH)
FROM test L, test
WHERE test.NPATH='1.2.3' AND
(L.NPATH=SUBSTRING(test.NPATH, 1, LENGTH(L.NPATH)) OR
test.NPATH=SUBSTRING(L.NPATH, 1, LENGTH(test.NPATH)))
ORDER BY UCASE(L.NPATH) ASC
*/
if (\$criteria === null)
\$criteria = new Criteria($peerClassname::DATABASE_NAME);
if (!\$criteria->getSelectColumns())
$peerClassname::addSelectColumns(\$criteria);
\$db = Propel::getDb(\$criteria->getDbName());
if ((\$ancestors || \$descendants) && \$criteria->size())
{
// If we are retrieving ancestors/descendants, we need to do a
// self-join to locate them. The exception to this is if no search
// criteria is specified. In this case we're retrieving all nodes
// anyway, so there is no need to do a self-join.
// The left-side of the self-join will contain the columns we'll
// use to build node objects (target node records along with their
// ancestors and/or descendants). The right-side of the join will
// contain the target node records specified by the initial criteria.
// These are used to match the appropriate ancestor/descendant on
// the left.
// Specify an alias for the left-side table to use.
\$criteria->addAlias('L', $peerClassname::TABLE_NAME);
// Make sure we have select columns to begin with.
if (!\$criteria->getSelectColumns())
$peerClassname::addSelectColumns(\$criteria);
// Replace any existing columns for the right-side table with the
// left-side alias.
\$selectColumns = \$criteria->getSelectColumns();
\$criteria->clearSelectColumns();
foreach (\$selectColumns as \$colName)
\$criteria->addSelectColumn(str_replace($peerClassname::TABLE_NAME, 'L', \$colName));
\$a = null;
\$d = null;
\$npathL = $peerClassname::alias('L', $nodePeerClassname::NPATH_COLNAME);
\$npathR = $nodePeerClassname::NPATH_COLNAME;
\$npath_len = $nodePeerClassname::NPATH_LEN;
if (\$ancestors)
{
// For ancestors, match left-side node paths which are contained
// by right-side node paths.
\$a = \$criteria->getNewCriterion(\$npathL,
\"\$npathL=\" . \$db->subString(\$npathR, 1, \$db->strLength(\$npathL), \$npath_len),
Criteria::CUSTOM);
}
if (\$descendants)
{
// For descendants, match left-side node paths which contain
// right-side node paths.
\$d = \$criteria->getNewCriterion(\$npathR,
\"\$npathR=\" . \$db->subString(\$npathL, 1, \$db->strLength(\$npathR), \$npath_len),
Criteria::CUSTOM);
}
if (\$a)
{
if (\$d) \$a->addOr(\$d);
\$criteria->addAnd(\$a);
}
else if (\$d)
{
\$criteria->addAnd(\$d);
}
// Add the target node path column. This is used by populateNodes().
\$criteria->addSelectColumn(\$npathR);
// Sort by node path to speed up tree construction in populateNodes()
\$criteria->addAsColumn('npathlen', \$db->strLength(\$npathL));
\$criteria->addAscendingOrderByColumn('npathlen');
\$criteria->addAscendingOrderByColumn(\$npathL);
}
else
{
// Add the target node path column. This is used by populateNodes().
\$criteria->addSelectColumn($nodePeerClassname::NPATH_COLNAME);
// Sort by node path to speed up tree construction in populateNodes()
\$criteria->addAsColumn('npathlen', \$db->strLength($nodePeerClassname::NPATH_COLNAME));
\$criteria->addAscendingOrderByColumn('npathlen');
\$criteria->addAscendingOrderByColumn($nodePeerClassname::NPATH_COLNAME);
}
return \$criteria;
}
";
}
protected function addBuildTree(&$script)
{
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* This method reconstructs as much of the tree structure as possible from
* the given array of objects. Depending on how you execute your query, it
* is possible for the ResultSet to contain multiple tree fragments (i.e.
* subtrees). The array returned by this method will contain one entry
* for each subtree root node it finds. The remaining subtree nodes are
* accessible from the $nodeObjectClassname methods of the
* subtree root nodes.
*
* @param array Array of $nodeObjectClassname objects
* @return array Array of $nodeObjectClassname objects
*/
public static function buildTree(\$nodes)
{
// Subtree root nodes to return
\$rootNodes = array();
// Build the tree relations
foreach (\$nodes as \$node)
{
\$sep = strrpos(\$node->getNodePath(), $nodePeerClassname::NPATH_SEP);
\$parentPath = (\$sep !== false ? substr(\$node->getNodePath(), 0, \$sep) : '');
\$parentNode = null;
// Scan other nodes for parent.
foreach (\$nodes as \$pnode)
{
if (\$pnode->getNodePath() === \$parentPath)
{
\$parentNode = \$pnode;
break;
}
}
// If parent was found, attach as child, otherwise its a subtree root
if (\$parentNode)
\$parentNode->attachChildNode(\$node);
else
\$rootNodes[] = \$node;
}
return \$rootNodes;
}
";
}
protected function addPopulateNodes(&$script)
{
$table = $this->getTable();
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$objectClassname = $this->getStubObjectBuilder()->getClassname();
$nodePeerClassname = $this->getStubNodePeerBuilder()->getClassname();
$nodeObjectClassname = $this->getStubNodeBuilder()->getClassname();
$script .= "
/**
* Populates the $objectClassname objects from the
* specified ResultSet, wraps them in $nodeObjectClassname
* objects and build the appropriate node relationships.
* The array returned by this method will only include the initial targets
* of the query, even if ancestors/descendants were also requested.
* The ancestors/descendants will be cached in memory and are accessible via
* the getNode() methods.
*
* @param PDOStatement \$stmt Executed PDOStatement
* @param Criteria
* @return array Array of $nodeObjectClassname objects.
*/
public static function populateNodes(PDOStatement \$stmt, \$criteria)
{
\$nodes = array();
\$targets = array();
\$targetfld = count(\$criteria->getSelectColumns());
";
if (!$table->getChildrenColumn()) {
$script .= "
// set the class once to avoid overhead in the loop
\$cls = $peerClassname::getOMClass();
\$cls = substr('.'.\$cls, strrpos('.'.\$cls, '.') + 1);
";
}
$script .= "
// populate the object(s)
foreach(\$stmt->fetchAll() AS \$row)
{
if (!isset(\$nodes[\$row[0]]))
{
";
if ($table->getChildrenColumn()) {
$script .= "
// class must be set each time from the record row
\$cls = $peerClassname::getOMClass(\$row, 1);
\$cls = substr('.'.\$cls, strrpos('.'.\$cls, '.') + 1);
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj', '$cls') . "
\$obj->hydrate(\$row);
\$nodes[\$row[0]] = new $nodeObjectClassname(\$obj);
}
\$node = \$nodes[\$row[0]];
if (\$node->getNodePath() === \$row[\$targetfld])
\$targets[\$node->getNodePath()] = \$node;
}
$nodePeerClassname::buildTree(\$nodes);
return array_values(\$targets);
}
";
}
} // PHP5NodePeerBuilder

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,962 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/PHP5ObjectBuilder.php';
/**
* Generates a PHP5 base Object class for user object model (OM).
*
* This class produces the base object class (e.g. BaseMyTable) which contains all
* the custom-built accessor and setter methods.
*
* This class overrides PHP5BaseObject to use Peer methods and Criteria
* instead of Query objects for fetching foreign keys. This can be useful if
* some legacy Propel 1.4 code assumes that the getters returns arrays
* instead of collections.
*
* This class is not used by default. You must override
* the propel.builder.object.class setting in build.properties to use it:
* <code>
* propel.builder.object.class = builder.om.PHP5ObjectNoCollectionBuilder
* </code>
*
* @deprecated Since Propel 1.5
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5ObjectNoCollectionBuilder extends PHP5ObjectBuilder
{
/**
* Adds the lazy loader method.
* @param string &$script The script will be modified in this method.
* @param Column $col The current column.
* @see parent::addColumnAccessors()
*/
protected function addLazyLoader(&$script, Column $col)
{
$this->addLazyLoaderComment($script, $col);
$this->addLazyLoaderOpen($script, $col);
$this->addLazyLoaderBody($script, $col);
$this->addLazyLoaderClose($script, $col);
}
/**
* Adds the comment for the lazy loader method
* @param string &$script The script will be modified in this method.
* @param Column $col The current column.
* @see addLazyLoader()
**/
protected function addLazyLoaderComment(&$script, Column $col) {
$clo = strtolower($col->getName());
$script .= "
/**
* Load the value for the lazy-loaded [$clo] column.
*
* This method performs an additional query to return the value for
* the [$clo] column, since it is not populated by
* the hydrate() method.
*
* @param \$con PropelPDO (optional) The PropelPDO connection to use.
* @return void
* @throws PropelException - any underlying error will be wrapped and re-thrown.
*/";
}
/**
* Adds the function declaration for the lazy loader method
* @param string &$script The script will be modified in this method.
* @param Column $col The current column.
* @see addLazyLoader()
**/
protected function addLazyLoaderOpen(&$script, Column $col) {
$cfc = $col->getPhpName();
$script .= "
protected function load$cfc(PropelPDO \$con = null)
{";
}
/**
* Adds the function body for the lazy loader method
* @param string &$script The script will be modified in this method.
* @param Column $col The current column.
* @see addLazyLoader()
**/
protected function addLazyLoaderBody(&$script, Column $col) {
$platform = $this->getPlatform();
$clo = strtolower($col->getName());
$script .= "
\$c = \$this->buildPkeyCriteria();
\$c->addSelectColumn(".$this->getColumnConstant($col).");
try {
\$stmt = ".$this->getPeerClassname()."::doSelectStmt(\$c, \$con);
\$row = \$stmt->fetch(PDO::FETCH_NUM);
\$stmt->closeCursor();";
if ($col->getType() === PropelTypes::CLOB && $this->getPlatform() instanceof OraclePlatform) {
// PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string...
$script .= "
\$this->$clo = stream_get_contents(\$row[0]);";
} elseif ($col->isLobType() && !$platform->hasStreamBlobImpl()) {
$script .= "
if (\$row[0] !== null) {
\$this->$clo = fopen('php://memory', 'r+');
fwrite(\$this->$clo, \$row[0]);
rewind(\$this->$clo);
} else {
\$this->$clo = null;
}";
} elseif ($col->isPhpPrimitiveType()) {
$script .= "
\$this->$clo = (\$row[0] !== null) ? (".$col->getPhpType().") \$row[0] : null;";
} elseif ($col->isPhpObjectType()) {
$script .= "
\$this->$clo = (\$row[0] !== null) ? new ".$col->getPhpType()."(\$row[0]) : null;";
} else {
$script .= "
\$this->$clo = \$row[0];";
}
$script .= "
\$this->".$clo."_isLoaded = true;
} catch (Exception \$e) {
throw new PropelException(\"Error loading value for [$clo] column on demand.\", \$e);
}";
}
/**
* Adds the function close for the lazy loader
* @param string &$script The script will be modified in this method.
* @param Column $col The current column.
* @see addLazyLoader()
**/
protected function addLazyLoaderClose(&$script, Column $col) {
$script .= "
}";
} // addLazyLoader()
/**
* Adds the buildPkeyCriteria method
* @param string &$script The script will be modified in this method.
**/
protected function addBuildPkeyCriteria(&$script) {
$this->addBuildPkeyCriteriaComment($script);
$this->addBuildPkeyCriteriaOpen($script);
$this->addBuildPkeyCriteriaBody($script);
$this->addBuildPkeyCriteriaClose($script);
}
/**
* Adds the comment for the buildPkeyCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildPkeyCriteria()
**/
protected function addBuildPkeyCriteriaComment(&$script) {
$script .= "
/**
* Builds a Criteria object containing the primary key for this object.
*
* Unlike buildCriteria() this method includes the primary key values regardless
* of whether or not they have been modified.
*
* @return Criteria The Criteria object containing value(s) for primary key(s).
*/";
}
/**
* Adds the function declaration for the buildPkeyCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildPkeyCriteria()
**/
protected function addBuildPkeyCriteriaOpen(&$script) {
$script .= "
public function buildPkeyCriteria()
{";
}
/**
* Adds the function body for the buildPkeyCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildPkeyCriteria()
**/
protected function addBuildPkeyCriteriaBody(&$script) {
$script .= "
\$criteria = new Criteria(".$this->getPeerClassname()."::DATABASE_NAME);";
foreach ($this->getTable()->getColumns() as $col) {
$clo = strtolower($col->getName());
if ($col->isPrimaryKey()) {
$script .= "
\$criteria->add(".$this->getColumnConstant($col).", \$this->$clo);";
}
}
}
/**
* Adds the function close for the buildPkeyCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildPkeyCriteria()
**/
protected function addBuildPkeyCriteriaClose(&$script) {
$script .= "
return \$criteria;
}
";
}
/**
* Adds the buildCriteria method
* @param string &$script The script will be modified in this method.
**/
protected function addBuildCriteria(&$script)
{
$this->addBuildCriteriaComment($script);
$this->addBuildCriteriaOpen($script);
$this->addBuildCriteriaBody($script);
$this->addBuildCriteriaClose($script);
}
/**
* Adds comment for the buildCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildCriteria()
**/
protected function addBuildCriteriaComment(&$script) {
$script .= "
/**
* Build a Criteria object containing the values of all modified columns in this object.
*
* @return Criteria The Criteria object containing all modified values.
*/";
}
/**
* Adds the function declaration of the buildCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildCriteria()
**/
protected function addBuildCriteriaOpen(&$script) {
$script .= "
public function buildCriteria()
{";
}
/**
* Adds the function body of the buildCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildCriteria()
**/
protected function addBuildCriteriaBody(&$script) {
$script .= "
\$criteria = new Criteria(".$this->getPeerClassname()."::DATABASE_NAME);
";
foreach ($this->getTable()->getColumns() as $col) {
$clo = strtolower($col->getName());
$script .= "
if (\$this->isColumnModified(".$this->getColumnConstant($col).")) \$criteria->add(".$this->getColumnConstant($col).", \$this->$clo);";
}
}
/**
* Adds the function close of the buildCriteria method
* @param string &$script The script will be modified in this method.
* @see addBuildCriteria()
**/
protected function addBuildCriteriaClose(&$script) {
$script .= "
return \$criteria;
}
";
}
/**
* Adds the function body for the delete function
* @param string &$script The script will be modified in this method.
* @see addDelete()
**/
protected function addDeleteBody(&$script) {
$script .= "
if (\$this->isDeleted()) {
throw new PropelException(\"This object has already been deleted.\");
}
if (\$con === null) {
\$con = Propel::getConnection(".$this->getPeerClassname()."::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
\$con->beginTransaction();
try {";
if($this->getGeneratorConfig()->getBuildProperty('addHooks')) {
$script .= "
\$ret = \$this->preDelete(\$con);";
// apply behaviors
$this->applyBehaviorModifier('preDelete', $script, " ");
$script .= "
if (\$ret) {
".$this->getPeerClassname()."::doDelete(\$this, \$con);
\$this->postDelete(\$con);";
// apply behaviors
$this->applyBehaviorModifier('postDelete', $script, " ");
$script .= "
\$con->commit();
\$this->setDeleted(true);
} else {
\$con->commit();
}";
} else {
// apply behaviors
$this->applyBehaviorModifier('preDelete', $script, " ");
$script .= "
".$this->getPeerClassname()."::doDelete(\$this, \$con);";
// apply behaviors
$this->applyBehaviorModifier('postDelete', $script, " ");
$script .= "
\$con->commit();
\$this->setDeleted(true);";
}
$script .= "
} catch (PropelException \$e) {
\$con->rollBack();
throw \$e;
}";
}
/**
* Adds a reload() method to re-fetch the data for this object from the database.
* @param string &$script The script will be modified in this method.
*/
protected function addReload(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
*
* This will only work if the object has been saved and has a valid primary key set.
*
* @param boolean \$deep (optional) Whether to also de-associated any related objects.
* @param PropelPDO \$con (optional) The PropelPDO connection to use.
* @return void
* @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
*/
public function reload(\$deep = false, PropelPDO \$con = null)
{
if (\$this->isDeleted()) {
throw new PropelException(\"Cannot reload a deleted object.\");
}
if (\$this->isNew()) {
throw new PropelException(\"Cannot reload an unsaved object.\");
}
if (\$con === null) {
\$con = Propel::getConnection(".$this->getPeerClassname()."::DATABASE_NAME, Propel::CONNECTION_READ);
}
// We don't need to alter the object instance pool; we're just modifying this instance
// already in the pool.
\$stmt = ".$this->getPeerClassname()."::doSelectStmt(\$this->buildPkeyCriteria(), \$con);
\$row = \$stmt->fetch(PDO::FETCH_NUM);
\$stmt->closeCursor();
if (!\$row) {
throw new PropelException('Cannot find matching row in the database to reload object values.');
}
\$this->hydrate(\$row, 0, true); // rehydrate
";
// support for lazy load columns
foreach ($table->getColumns() as $col) {
if ($col->isLazyLoad()) {
$clo = strtolower($col->getName());
$script .= "
// Reset the $clo lazy-load column
\$this->" . $clo . " = null;
\$this->".$clo."_isLoaded = false;
";
}
}
$script .= "
if (\$deep) { // also de-associate any related objects?
";
foreach ($table->getForeignKeys() as $fk) {
$varName = $this->getFKVarName($fk);
$script .= "
\$this->".$varName." = null;";
}
foreach ($table->getReferrers() as $refFK) {
if ($refFK->isLocalPrimaryKey()) {
$script .= "
\$this->".$this->getPKRefFKVarName($refFK)." = null;
";
} else {
$script .= "
\$this->".$this->getRefFKCollVarName($refFK)." = null;
\$this->".$this->getRefFKLastCriteriaVarName($refFK)." = null;
";
}
}
$script .= "
} // if (deep)
}
";
} // addReload()
/**
* Gets variable name for the Criteria which was used to fetch the objects which
* referencing current table by specified foreign key.
* @param ForeignKey $fk
* @return string
*/
protected function getRefFKLastCriteriaVarName(ForeignKey $fk)
{
return 'last' . $this->getRefFKPhpNameAffix($fk, $plural = false) . 'Criteria';
}
/**
* 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();
$varName = $this->getFKVarName($fk);
$pCollName = $this->getFKPhpNameAffix($fk, $plural = true);
$fkPeerBuilder = $this->getNewPeerBuilder($this->getForeignTable($fk));
$fkObjectBuilder = $this->getNewObjectBuilder($this->getForeignTable($fk))->getStubObjectBuilder();
$className = $fkObjectBuilder->getClassname(); // get the Classname that has maybe a prefix
$and = "";
$comma = "";
$conditional = "";
$argmap = array(); // foreign -> local mapping
$argsize = 0;
foreach ($fk->getLocalColumns() as $columnName) {
$lfmap = $fk->getLocalForeignMapping();
$localColumn = $table->getColumn($columnName);
$foreignColumn = $fk->getForeignTable()->getColumn($lfmap[$columnName]);
$column = $table->getColumn($columnName);
$cptype = $column->getPhpType();
$clo = strtolower($column->getName());
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";
}
$argmap[] = array('foreign' => $foreignColumn, 'local' => $localColumn);
$and = " && ";
$comma = ", ";
$argsize = $argsize + 1;
}
// If the related column is a primary kay and if it's a simple association,
// The use retrieveByPk() instead of doSelect() to take advantage of instance pooling
$useRetrieveByPk = count($argmap) == 1 && $argmap[0]['foreign']->isPrimaryKey();
$script .= "
/**
* Get the associated $className object
*
* @param PropelPDO Optional Connection object.
* @return $className The associated $className object.
* @throws PropelException
*/
public function get".$this->getFKPhpNameAffix($fk, $plural = false)."(PropelPDO \$con = null)
{";
$script .= "
if (\$this->$varName === null && ($conditional)) {";
if ($useRetrieveByPk) {
$script .= "
\$this->$varName = ".$fkPeerBuilder->getPeerClassname()."::retrieveByPk(\$this->$clo);";
} else {
$script .= "
\$c = new Criteria(".$fkPeerBuilder->getPeerClassname()."::DATABASE_NAME);";
foreach ($argmap as $el) {
$fcol = $el['foreign'];
$lcol = $el['local'];
$clo = strtolower($lcol->getName());
$script .= "
\$c->add(".$fkPeerBuilder->getColumnConstant($fcol).", \$this->".$clo.");";
}
$script .= "
\$this->$varName = ".$fkPeerBuilder->getPeerClassname()."::doSelectOne(\$c, \$con);";
}
if ($fk->isLocalPrimaryKey()) {
$script .= "
// Because this foreign key represents a one-to-one relationship, we will create a bi-directional association.
\$this->{$varName}->set".$this->getRefFKPhpNameAffix($fk, $plural = false)."(\$this);";
} else {
$script .= "
/* The following can be used additionally to
guarantee the related object contains a reference
to this object. This level of coupling may, however, be
undesirable since it could result in an only partially populated collection
in the referenced object.
\$this->{$varName}->add".$this->getRefFKPhpNameAffix($fk, $plural = true)."(\$this);
*/";
}
$script .= "
}
return \$this->$varName;
}
";
} // addFKAccessor
/**
* 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)
{
$table = $this->getTable();
$tblFK = $refFK->getTable();
$join_behavior = $this->getGeneratorConfig()->getBuildProperty('useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN';
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural=true);
$collName = $this->getRefFKCollVarName($refFK);
$lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK);
$fkPeerBuilder = $this->getNewPeerBuilder($tblFK);
$lastTable = "";
foreach ($tblFK->getForeignKeys() as $fk2) {
$tblFK2 = $this->getForeignTable($fk2);
$doJoinGet = !$tblFK2->isForReferenceOnly();
// it doesn't make sense to join in rows from the curent table, since we are fetching
// objects related to *this* table (i.e. the joined rows will all be the same row as current object)
if ($this->getTable()->getPhpName() == $tblFK2->getPhpName()) {
$doJoinGet = false;
}
$relCol2 = $this->getFKPhpNameAffix($fk2, $plural = false);
if ( $this->getRelatedBySuffix($refFK) != "" &&
($this->getRelatedBySuffix($refFK) == $this->getRelatedBySuffix($fk2))) {
$doJoinGet = false;
}
if ($doJoinGet) {
$script .= "
/**
* If this collection has already been initialized with
* an identical criteria, it returns the collection.
* Otherwise if this ".$table->getPhpName()." is new, it will return
* an empty collection; or if this ".$table->getPhpName()." has previously
* been saved, it will retrieve related $relCol from storage.
*
* This method is protected by default in order to keep the public
* api reasonable. You can provide public methods for those you
* actually need in ".$table->getPhpName().".
*/
public function get".$relCol."Join".$relCol2."(\$criteria = null, \$con = null, \$join_behavior = $join_behavior)
{";
$script .= "
if (\$criteria === null) {
\$criteria = new Criteria($peerClassname::DATABASE_NAME);
}
elseif (\$criteria instanceof Criteria)
{
\$criteria = clone \$criteria;
}
if (\$this->$collName === null) {
if (\$this->isNew()) {
\$this->$collName = array();
} else {
";
foreach ($refFK->getForeignColumns() as $columnName) {
$column = $table->getColumn($columnName);
$flMap = $refFK->getForeignLocalMapping();
$colFKName = $flMap[$columnName];
$colFK = $tblFK->getColumn($colFKName);
if ($colFK === null) {
throw new EngineException("Column $colFKName not found in " . $tblFK->getName());
}
$clo = strtolower($column->getName());
$script .= "
\$criteria->add(".$fkPeerBuilder->getColumnConstant($colFK).", \$this->$clo);
";
} // end foreach ($fk->getForeignColumns()
$script .= "
\$this->$collName = ".$fkPeerBuilder->getPeerClassname()."::doSelectJoin$relCol2(\$criteria, \$con, \$join_behavior);
}
} else {
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
";
foreach ($refFK->getForeignColumns() as $columnName) {
$column = $table->getColumn($columnName);
$flMap = $refFK->getForeignLocalMapping();
$colFKName = $flMap[$columnName];
$colFK = $tblFK->getColumn($colFKName);
$clo = strtolower($column->getName());
$script .= "
\$criteria->add(".$fkPeerBuilder->getColumnConstant($colFK).", \$this->$clo);
";
} /* end foreach ($fk->getForeignColumns() */
$script .= "
if (!isset(\$this->$lastCriteriaName) || !\$this->".$lastCriteriaName."->equals(\$criteria)) {
\$this->$collName = ".$fkPeerBuilder->getPeerClassname()."::doSelectJoin$relCol2(\$criteria, \$con, \$join_behavior);
}
}
\$this->$lastCriteriaName = \$criteria;
return \$this->$collName;
}
";
} /* end if ($doJoinGet) */
} /* end foreach ($tblFK->getForeignKeys() as $fk2) { */
} // function
/**
* 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) {
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$collName = $this->getRefFKCollVarName($refFK);
$script .= "
/**
* Initializes the $collName collection (array).
*
* By default this just sets the $collName collection to an empty array (like clear$collName());
* however, you may wish to override this method in your stub class to provide setting appropriate
* to your application -- for example, setting the initial array to the values stored in database.
*
* @return void
*/
public function init$relCol()
{
\$this->$collName = array();
}
";
} // addRefererInit()
/**
* 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();
$joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
$className = $joinedTableObjectBuilder->getObjectClassname();
$collName = $this->getRefFKCollVarName($refFK);
$script .= "
/**
* Method called to associate a $className 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)
{
if (\$this->$collName === null) {
\$this->init".$this->getRefFKPhpNameAffix($refFK, $plural = true)."();
}
if (!in_array(\$l, \$this->$collName, true)) { // only add it if the **same** object is not already associated
array_push(\$this->$collName, \$l);
\$l->set".$this->getFKPhpNameAffix($refFK, $plural = false)."(\$this);
}
}
";
} // addRefererAdd
/**
* 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)
{
$table = $this->getTable();
$tblFK = $refFK->getTable();
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$fkPeerBuilder = $this->getNewPeerBuilder($refFK->getTable());
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$collName = $this->getRefFKCollVarName($refFK);
$lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK);
$className = $fkPeerBuilder->getObjectClassname();
$script .= "
/**
* Returns the number of related $className objects.
*
* @param Criteria \$criteria
* @param boolean \$distinct
* @param PropelPDO \$con
* @return int Count of related $className objects.
* @throws PropelException
*/
public function count$relCol(Criteria \$criteria = null, \$distinct = false, PropelPDO \$con = null)
{";
$script .= "
if (\$criteria === null) {
\$criteria = new Criteria($peerClassname::DATABASE_NAME);
} else {
\$criteria = clone \$criteria;
}
if (\$distinct) {
\$criteria->setDistinct();
}
\$count = null;
if (\$this->$collName === null) {
if (\$this->isNew()) {
\$count = 0;
} else {
";
foreach ($refFK->getLocalColumns() as $colFKName) {
// $colFKName is local to the referring table (i.e. foreign to this table)
$lfmap = $refFK->getLocalForeignMapping();
$localColumn = $this->getTable()->getColumn($lfmap[$colFKName]);
$colFK = $refFK->getTable()->getColumn($colFKName);
$clo = strtolower($localColumn->getName());
$script .= "
\$criteria->add(".$fkPeerBuilder->getColumnConstant($colFK).", \$this->$clo);
";
} // end foreach ($fk->getForeignColumns()
$script .= "
\$count = ".$fkPeerBuilder->getPeerClassname()."::doCount(\$criteria, false, \$con);
}
} else {
// criteria has no effect for a new object
if (!\$this->isNew()) {
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return count of the collection.
";
foreach ($refFK->getLocalColumns() as $colFKName) {
// $colFKName is local to the referring table (i.e. foreign to this table)
$lfmap = $refFK->getLocalForeignMapping();
$localColumn = $this->getTable()->getColumn($lfmap[$colFKName]);
$colFK = $refFK->getTable()->getColumn($colFKName);
$clo = strtolower($localColumn->getName());
$script .= "
\$criteria->add(".$fkPeerBuilder->getColumnConstant($colFK).", \$this->$clo);
";
} // foreach ($fk->getForeignColumns()
$script .= "
if (!isset(\$this->$lastCriteriaName) || !\$this->".$lastCriteriaName."->equals(\$criteria)) {
\$count = ".$fkPeerBuilder->getPeerClassname()."::doCount(\$criteria, false, \$con);
} else {
\$count = count(\$this->$collName);
}
} else {
\$count = count(\$this->$collName);
}
}
return \$count;
}
";
} // addRefererCount
/**
* 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();
$peerClassname = $this->getStubPeerBuilder()->getClassname();
$fkPeerBuilder = $this->getNewPeerBuilder($refFK->getTable());
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$collName = $this->getRefFKCollVarName($refFK);
$lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK);
$className = $fkPeerBuilder->getObjectClassname();
$script .= "
/**
* Gets an array of $className objects which contain a foreign key that references this object.
*
* If this collection has already been initialized with an identical Criteria, it returns the collection.
* Otherwise if this ".$this->getObjectClassname()." has previously been saved, it will retrieve
* related $relCol from storage. If this ".$this->getObjectClassname()." is new, it will return
* an empty collection or the current collection, the criteria is ignored on a new object.
*
* @param PropelPDO \$con
* @param Criteria \$criteria
* @return array {$className}[]
* @throws PropelException
*/
public function get$relCol(\$criteria = null, PropelPDO \$con = null)
{";
$script .= "
if (\$criteria === null) {
\$criteria = new Criteria($peerClassname::DATABASE_NAME);
}
elseif (\$criteria instanceof Criteria)
{
\$criteria = clone \$criteria;
}
if (\$this->$collName === null) {
if (\$this->isNew()) {
\$this->$collName = array();
} else {
";
foreach ($refFK->getLocalColumns() as $colFKName) {
// $colFKName is local to the referring table (i.e. foreign to this table)
$lfmap = $refFK->getLocalForeignMapping();
$localColumn = $this->getTable()->getColumn($lfmap[$colFKName]);
$colFK = $refFK->getTable()->getColumn($colFKName);
$clo = strtolower($localColumn->getName());
$script .= "
\$criteria->add(".$fkPeerBuilder->getColumnConstant($colFK).", \$this->$clo);
";
} // end foreach ($fk->getForeignColumns()
$script .= "
".$fkPeerBuilder->getPeerClassname()."::addSelectColumns(\$criteria);
\$this->$collName = ".$fkPeerBuilder->getPeerClassname()."::doSelect(\$criteria, \$con);
}
} else {
// criteria has no effect for a new object
if (!\$this->isNew()) {
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
";
foreach ($refFK->getLocalColumns() as $colFKName) {
// $colFKName is local to the referring table (i.e. foreign to this table)
$lfmap = $refFK->getLocalForeignMapping();
$localColumn = $this->getTable()->getColumn($lfmap[$colFKName]);
$colFK = $refFK->getTable()->getColumn($colFKName);
$clo = strtolower($localColumn->getName());
$script .= "
\$criteria->add(".$fkPeerBuilder->getColumnConstant($colFK).", \$this->$clo);
";
} // foreach ($fk->getForeignColumns()
$script .= "
".$fkPeerBuilder->getPeerClassname()."::addSelectColumns(\$criteria);
if (!isset(\$this->$lastCriteriaName) || !\$this->".$lastCriteriaName."->equals(\$criteria)) {
\$this->$collName = ".$fkPeerBuilder->getPeerClassname()."::doSelect(\$criteria, \$con);
}
}
}
\$this->$lastCriteriaName = \$criteria;
return \$this->$collName;
}
";
} // addRefererGet()
/**
* Adds the method that gets a one-to-one related referrer fkey.
* This is for one-to-one relationship special case.
* @param string &$script The script will be modified in this method.
*/
protected function addPKRefFKGet(&$script, ForeignKey $refFK)
{
$table = $this->getTable();
$tblFK = $refFK->getTable();
$joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
$joinedTablePeerBuilder = $this->getNewObjectBuilder($refFK->getTable());
$className = $joinedTableObjectBuilder->getObjectClassname();
$varName = $this->getPKRefFKVarName($refFK);
$script .= "
/**
* Gets a single $className object, which is related to this object by a one-to-one relationship.
*
* @param PropelPDO \$con
* @return $className
* @throws PropelException
*/
public function get".$this->getRefFKPhpNameAffix($refFK, $plural = false)."(PropelPDO \$con = null)
{
";
$script .= "
if (\$this->$varName === null && !\$this->isNew()) {";
$lfmap = $refFK->getLocalForeignMapping();
// remember: this object represents the foreign table,
// so we need foreign columns of the reffk to know the local columns
// that we need to set :)
$localcols = $refFK->getForeignColumns();
// we know that at least every column in the primary key of the foreign table
// is represented in this foreign key
$params = array();
foreach ($tblFK->getPrimaryKey() as $col) {
$localColumn = $table->getColumn($lfmap[$col->getName()]);
$clo = strtolower($localColumn->getName());
$params[] = "\$this->$clo";
}
$script .= "
\$this->$varName = ".$joinedTableObjectBuilder->getPeerClassname()."::retrieveByPK(".implode(", ", $params).", \$con);
}
return \$this->$varName;
}
";
} // addPKRefFKGet()
} // PHP5ObjectBuilder

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,354 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/OMBuilder.php';
/**
* Generates the PHP5 table map class for user object model (OM).
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
class PHP5TableMapBuilder extends OMBuilder
{
/**
* Gets the package for the map builder classes.
* @return string
*/
public function getPackage()
{
return parent::getPackage() . '.map';
}
public function getNamespace()
{
if ($namespace = parent::getNamespace()) {
if ($this->getGeneratorConfig() && $omns = $this->getGeneratorConfig()->getBuildProperty('namespaceMap')) {
return $namespace . '\\' . $omns;
} else {
return $namespace;
}
}
}
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getTable()->getPhpName() . 'TableMap';
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$script .= "
/**
* This class defines the structure of the '".$table->getName()."' table.
*
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
*
* This map class is used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package propel.generator.".$this->getPackage()."
*/
class ".$this->getClassname()." extends TableMap {
";
}
/**
* Specifies the methods that are added as part of the map builder class.
* This can be overridden by subclasses that wish to add more methods.
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
$this->declareClasses('TableMap', 'RelationMap');
$this->addConstants($script);
$this->addAttributes($script);
$this->addInitialize($script);
$this->addBuildRelations($script);
$this->addGetBehaviors($script);
}
/**
* Adds any constants needed for this TableMap class.
* @param string &$script The script will be modified in this method.
*/
protected function addConstants(&$script)
{
$script .= "
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = '".$this->getClasspath()."';
";
}
/**
* Adds any attributes needed for this TableMap class.
* @param string &$script The script will be modified in this method.
*/
protected function addAttributes(&$script)
{
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
$this->applyBehaviorModifier('tableMapFilter', $script, "");
}
/**
* Adds the addInitialize() method to the table map class.
* @param string &$script The script will be modified in this method.
*/
protected function addInitialize(&$script)
{
$table = $this->getTable();
$platform = $this->getPlatform();
$ddlBuilder = $this->getDDLBuilder();
$script .= "
/**
* Initialize the table attributes, columns and validators
* Relations are not initialized by this method since they are lazy loaded
*
* @return void
* @throws PropelException
*/
public function initialize()
{
// attributes
\$this->setName('".$table->getName()."');
\$this->setPhpName('".$table->getPhpName()."');
\$this->setClassname('" . addslashes($this->getStubObjectBuilder()->getFullyQualifiedClassname()) . "');
\$this->setPackage('" . parent::getPackage() . "');";
if ($table->getIdMethod() == "native") {
$script .= "
\$this->setUseIdGenerator(true);";
} else {
$script .= "
\$this->setUseIdGenerator(false);";
}
if ($table->getIdMethodParameters()) {
$params = $table->getIdMethodParameters();
$imp = $params[0];
$script .= "
\$this->setPrimaryKeyMethodInfo('".$imp->getValue()."');";
} elseif ($table->getIdMethod() == IDMethod::NATIVE && ($platform->getNativeIdMethod() == Platform::SEQUENCE || $platform->getNativeIdMethod() == Platform::SERIAL)) {
$script .= "
\$this->setPrimaryKeyMethodInfo('".$ddlBuilder->getSequenceName()."');";
}
if ($this->getTable()->getChildrenColumn()) {
$script .= "
\$this->setSingleTableInheritance(true);";
}
// Add columns to map
$script .= "
// columns";
foreach ($table->getColumns() as $col) {
$cup=strtoupper($col->getName());
$cfc=$col->getPhpName();
if (!$col->getSize()) {
$size = "null";
} else {
$size = $col->getSize();
}
$default = $col->getDefaultValueString();
if ($col->isPrimaryKey()) {
if ($col->isForeignKey()) {
foreach ($col->getForeignKeys() as $fk) {
$script .= "
\$this->addForeignPrimaryKey('$cup', '$cfc', '".$col->getType()."' , '".$fk->getForeignTableName()."', '".strtoupper($fk->getMappedForeignColumn($col->getName()))."', ".($col->isNotNull() ? 'true' : 'false').", ".$size.", $default);";
}
} else {
$script .= "
\$this->addPrimaryKey('$cup', '$cfc', '".$col->getType()."', ".var_export($col->isNotNull(), true).", ".$size.", $default);";
}
} else {
if ($col->isForeignKey()) {
foreach ($col->getForeignKeys() as $fk) {
$script .= "
\$this->addForeignKey('$cup', '$cfc', '".$col->getType()."', '".$fk->getForeignTableName()."', '".strtoupper($fk->getMappedForeignColumn($col->getName()))."', ".($col->isNotNull() ? 'true' : 'false').", ".$size.", $default);";
}
} else {
$script .= "
\$this->addColumn('$cup', '$cfc', '".$col->getType()."', ".var_export($col->isNotNull(), true).", ".$size.", $default);";
}
} // if col-is prim key
} // foreach
// validators
$script .= "
// validators";
foreach ($table->getValidators() as $val) {
$col = $val->getColumn();
$cup = strtoupper($col->getName());
foreach ($val->getRules() as $rule) {
if ($val->getTranslate() !== Validator::TRANSLATE_NONE) {
$script .= "
\$this->addValidator('$cup', '".$rule->getName()."', '".$rule->getClass()."', '".str_replace("'", "\'", $rule->getValue())."', ".$val->getTranslate()."('".str_replace("'", "\'", $rule->getMessage())."'));";
} else {
$script .= "
\$this->addValidator('$cup', '".$rule->getName()."', '".$rule->getClass()."', '".str_replace("'", "\'", $rule->getValue())."', '".str_replace("'", "\'", $rule->getMessage())."');";
} // if ($rule->getTranslation() ...
} // foreach rule
} // foreach validator
$script .= "
} // initialize()
";
}
/**
* Adds the method that build the RelationMap objects
* @param string &$script The script will be modified in this method.
*/
protected function addBuildRelations(&$script)
{
$script .= "
/**
* Build the RelationMap objects for this table relationships
*/
public function buildRelations()
{";
foreach ($this->getTable()->getForeignKeys() as $fkey)
{
$columnMapping = 'array(';
foreach ($fkey->getLocalForeignMapping() as $key => $value)
{
$columnMapping .= "'$key' => '$value', ";
}
$columnMapping .= ')';
$onDelete = $fkey->hasOnDelete() ? "'" . $fkey->getOnDelete() . "'" : 'null';
$onUpdate = $fkey->hasOnUpdate() ? "'" . $fkey->getOnUpdate() . "'" : 'null';
$script .= "
\$this->addRelation('" . $this->getFKPhpNameAffix($fkey) . "', '" . addslashes($this->getNewStubObjectBuilder($fkey->getForeignTable())->getFullyQualifiedClassname()) . "', RelationMap::MANY_TO_ONE, $columnMapping, $onDelete, $onUpdate);";
}
foreach ($this->getTable()->getReferrers() as $fkey)
{
$columnMapping = 'array(';
foreach ($fkey->getForeignLocalMapping() as $key => $value)
{
$columnMapping .= "'$key' => '$value', ";
}
$columnMapping .= ')';
$onDelete = $fkey->hasOnDelete() ? "'" . $fkey->getOnDelete() . "'" : 'null';
$onUpdate = $fkey->hasOnUpdate() ? "'" . $fkey->getOnUpdate() . "'" : 'null';
$script .= "
\$this->addRelation('" . $this->getRefFKPhpNameAffix($fkey) . "', '" . addslashes($this->getNewStubObjectBuilder($fkey->getTable())->getFullyQualifiedClassname()) . "', RelationMap::ONE_TO_" . ($fkey->isLocalPrimaryKey() ? "ONE" : "MANY") .", $columnMapping, $onDelete, $onUpdate);";
}
foreach ($this->getTable()->getCrossFks() as $fkList)
{
list($refFK, $crossFK) = $fkList;
$onDelete = $fkey->hasOnDelete() ? "'" . $fkey->getOnDelete() . "'" : 'null';
$onUpdate = $fkey->hasOnUpdate() ? "'" . $fkey->getOnUpdate() . "'" : 'null';
$script .= "
\$this->addRelation('" . $this->getFKPhpNameAffix($crossFK) . "', '" . addslashes($this->getNewStubObjectBuilder($crossFK->getForeignTable())->getFullyQualifiedClassname()) . "', RelationMap::MANY_TO_MANY, array(), $onDelete, $onUpdate);";
}
$script .= "
} // buildRelations()
";
}
/**
* Adds the behaviors getter
* @param string &$script The script will be modified in this method.
*/
protected function addGetBehaviors(&$script)
{
if ($behaviors = $this->getTable()->getBehaviors())
{
$script .= "
/**
*
* Gets the list of behaviors registered for this table
*
* @return array Associative array (name => parameters) of behaviors
*/
public function getBehaviors()
{
return array(";
foreach ($behaviors as $behavior)
{
$script .= "
'{$behavior->getName()}' => array(";
foreach ($behavior->getParameters() as $key => $value)
{
$script .= "'$key' => '$value', ";
}
$script .= "),";
}
$script .= "
);
} // getBehaviors()
";
}
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @return boolean
*/
public function hasBehaviorModifier($hookName, $modifier = null)
{
return parent::hasBehaviorModifier($hookName, 'TableMapBuilderModifier');
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @param string &$script The script will be modified in this method.
*/
public function applyBehaviorModifier($hookName, &$script, $tab = " ")
{
return $this->applyBehaviorModifierBase($hookName, 'TableMapBuilderModifier', $script, $tab);
}
} // PHP5TableMapBuilder

View file

@ -0,0 +1,305 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/OMBuilder.php';
/**
* Base class for Peer-building classes.
*
* This class is designed so that it can be extended by a PHP4PeerBuilder in addition
* to the "standard" PHP5PeerBuilder and PHP5ComplexOMPeerBuilder. Hence, this class
* should not have any actual template code in it -- simply basic logic & utility
* methods.
*
* @author Hans Lellelid <hans@xmpl.org>
* @package propel.generator.builder.om
*/
abstract class PeerBuilder extends OMBuilder
{
protected $basePeerClass;
protected $basePeerClassname;
/**
* Constructs a new PeerBuilder subclass.
*/
public function __construct(Table $table) {
parent::__construct($table);
$this->basePeerClassname = $this->basePeerClass = $this->getBasePeer($table);
$pos = strrpos($this->basePeerClassname, '.');
if ($pos !== false) {
$this->basePeerClassname = substr($this->basePeerClassname, $pos + 1);
}
}
/**
* Adds the addSelectColumns(), doCount(), etc. methods.
* @param string &$script The script will be modified in this method.
*/
protected function addSelectMethods(&$script)
{
$this->addAddSelectColumns($script);
$this->addDoCount($script);
// consider refactoring the doSelect stuff
// into a top-level method
$this->addDoSelectOne($script);
$this->addDoSelect($script);
$this->addDoSelectStmt($script); // <-- there's PDO code in here
$this->addAddInstanceToPool($script);
$this->addRemoveInstanceFromPool($script);
$this->addGetInstanceFromPool($script);
$this->addClearInstancePool($script);
$this->addClearRelatedInstancePool($script);
$this->addGetPrimaryKeyHash($script);
$this->addGetPrimaryKeyFromRow($script);
$this->addPopulateObjects($script); // <-- there's PDO code in here
$this->addPopulateObject($script);
}
/**
* Adds the correct getOMClass() method, depending on whether this table uses inheritance.
* @param string &$script The script will be modified in this method.
*/
protected function addGetOMClassMethod(&$script)
{
$table = $this->getTable();
if ($table->getChildrenColumn()) {
$this->addGetOMClass_Inheritance($script);
} else {
if ($table->isAbstract()) {
$this->addGetOMClass_NoInheritance_Abstract($script);
} else {
$this->addGetOMClass_NoInheritance($script);
}
}
}
/**
* Adds the doInsert(), doUpdate(), doDeleteAll(), doValidate(), etc. methods.
* @param string &$script The script will be modified in this method.
*/
protected function addUpdateMethods(&$script)
{
$this->addDoInsert($script);
$this->addDoUpdate($script);
$this->addDoDeleteAll($script);
$this->addDoDelete($script);
if ($this->isDeleteCascadeEmulationNeeded()) {
$this->addDoOnDeleteCascade($script);
}
if ($this->isDeleteSetNullEmulationNeeded()) {
$this->addDoOnDeleteSetNull($script);
}
$this->addDoValidate($script);
}
/**
* Adds the retrieveByPK() (and possibly retrieveByPKs()) method(s) appropriate for this class.
* @param string &$script The script will be modified in this method.
*/
protected function addRetrieveByPKMethods(&$script)
{
if (count($this->getTable()->getPrimaryKey()) === 1) {
$this->addRetrieveByPK_SinglePK($script);
$this->addRetrieveByPKs_SinglePK($script);
} else {
$this->addRetrieveByPK_MultiPK($script);
}
}
/**
* This method adds the contents of the generated class to the script.
*
* This method contains the high-level logic that determines which methods
* get generated.
*
* Hint: Override this method in your subclass if you want to reorganize or
* drastically change the contents of the generated peer class.
*
* @param string &$script The script will be modified in this method.
*/
protected function addClassBody(&$script)
{
$table = $this->getTable();
if (!$table->isAlias()) {
$this->addConstantsAndAttributes($script);
}
$this->addTranslateFieldName($script);
$this->addGetFieldNames($script);
if (!$table->isAlias()) {
$this->addAlias($script); // alias() utility method (deprecated?)
$this->addSelectMethods($script);
$this->addGetTableMap($script);
}
$this->addBuildTableMap($script);
$this->addGetOMClassMethod($script);
// add the insert, update, delete, validate etc. methods
if (!$table->isAlias() && !$table->isReadOnly()) {
$this->addUpdateMethods($script);
}
if (count($table->getPrimaryKey()) > 0) {
$this->addRetrieveByPKMethods($script);
}
}
/**
* Whether the platform in use requires ON DELETE CASCADE emulation and whether there are references to this table.
* @return boolean
*/
protected function isDeleteCascadeEmulationNeeded()
{
$table = $this->getTable();
if ((!$this->getPlatform()->supportsNativeDeleteTrigger() || $this->getBuildProperty('emulateForeignKeyConstraints')) && count($table->getReferrers()) > 0) {
foreach ($table->getReferrers() as $fk) {
if ($fk->getOnDelete() == ForeignKey::CASCADE) {
return true;
}
}
}
return false;
}
/**
* Whether the platform in use requires ON DELETE SETNULL emulation and whether there are references to this table.
* @return boolean
*/
protected function isDeleteSetNullEmulationNeeded()
{
$table = $this->getTable();
if ((!$this->getPlatform()->supportsNativeDeleteTrigger() || $this->getBuildProperty('emulateForeignKeyConstraints')) && count($table->getReferrers()) > 0) {
foreach ($table->getReferrers() as $fk) {
if ($fk->getOnDelete() == ForeignKey::SETNULL) {
return true;
}
}
}
return false;
}
/**
* Whether to add the generic mutator methods (setByName(), setByPosition(), fromArray()).
* This is based on the build property propel.addGenericMutators, and also whether the
* table is read-only or an alias.
* @return boolean
*/
protected function isAddGenericMutators()
{
$table = $this->getTable();
return (!$table->isAlias() && $this->getBuildProperty('addGenericMutators') && !$table->isReadOnly());
}
/**
* Whether to add the generic accessor methods (getByName(), getByPosition(), toArray()).
* This is based on the build property propel.addGenericAccessors, and also whether the
* table is an alias.
* @return boolean
*/
protected function isAddGenericAccessors()
{
$table = $this->getTable();
return (!$table->isAlias() && $this->getBuildProperty('addGenericAccessors'));
}
/**
* Returns the retrieveByPK method name to use for this table.
* If the table is an alias then the method name looks like "retrieveTablenameByPK"
* otherwise simply "retrieveByPK".
* @return string
*/
public function getRetrieveMethodName()
{
if ($this->getTable()->isAlias()) {
$retrieveMethod = "retrieve" . $this->getTable()->getPhpName() . "ByPK";
} else {
$retrieveMethod = "retrieveByPK";
}
return $retrieveMethod;
}
/**
* COMPATIBILITY: Get the column constant name (e.g. PeerName::COLUMN_NAME).
*
* This method exists simply because it belonged to the 'PeerBuilder' that this
* class is replacing (because of name conflict more than actual functionality overlap).
* When the new builder model is finished this method will be removed.
*
* @param Column $col The column we need a name for.
* @param string $phpName The PHP Name of the peer class. The 'Peer' is appended automatically.
*
* @return string If $phpName is provided, then will return {$phpName}Peer::COLUMN_NAME; if not, just COLUMN_NAME.
* @deprecated
*/
public static function getColumnName(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 . 'Peer::' . $const;
} else {
return $const;
}
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @return boolean
*/
public function hasBehaviorModifier($hookName, $modifier = null)
{
return parent::hasBehaviorModifier($hookName, 'PeerBuilderModifier');
}
/**
* Checks whether any registered behavior on that table has a modifier for a hook
* @param string $hookName The name of the hook as called from one of this class methods, e.g. "preSave"
* @param string &$script The script will be modified in this method.
*/
public function applyBehaviorModifier($hookName, &$script, $tab = " ")
{
return $this->applyBehaviorModifierBase($hookName, 'PeerBuilderModifier', $script, $tab);
}
/**
* Checks whether any registered behavior content creator on that table exists a contentName
* @param string $contentName The name of the content as called from one of this class methods, e.g. "parentClassname"
*/
public function getBehaviorContent($contentName)
{
return $this->getBehaviorContentBase($contentName, 'PeerBuilderModifier');
}
/**
* Get the BasePeer class name for the current table (e.g. 'BasePeer')
*
* @return string The Base Peer Class name
*/
public function getBasePeerClassname()
{
return $this->basePeerClassname;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,276 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
require_once 'builder/om/OMBuilder.php';
/**
* Generates the empty PHP5 stub query class for use with single table inheritance.
*
* This class produces the empty stub class that can be customized with application
* business logic, custom behavior, etc.
*
*
* @author François Zaninotto
* @package propel.generator.builder.om
*/
class QueryInheritanceBuilder extends OMBuilder
{
/**
* The current child "object" we are operating on.
*/
protected $child;
/**
* Returns the name of the current class being built.
* @return string
*/
public function getUnprefixedClassname()
{
return $this->getBuildProperty('basePrefix') . $this->getNewStubQueryInheritanceBuilder($this->getChild())->getUnprefixedClassname();
}
/**
* Gets the package for the [base] object classes.
* @return string
*/
public function getPackage()
{
return parent::getPackage() . ".om";
}
public function getNamespace()
{
if ($namespace = parent::getNamespace()) {
if ($this->getGeneratorConfig() && $omns = $this->getGeneratorConfig()->getBuildProperty('namespaceOm')) {
return $namespace . '\\' . $omns;
} else {
return $namespace;
}
}
}
/**
* Set the child object that we're operating on currrently.
* @param $child Inheritance
*/
public function setChild(Inheritance $child)
{
$this->child = $child;
}
/**
* Returns the child object we're operating on currently.
* @return Inheritance
* @throws BuildException - if child was not set.
*/
public function getChild()
{
if (!$this->child) {
throw new BuildException("The PHP5MultiExtendObjectBuilder needs to be told which child class to build (via setChild() method) before it can build the stub class.");
}
return $this->child;
}
/**
* Adds the include() statements for files that this class depends on or utilizes.
* @param string &$script The script will be modified in this method.
*/
protected function addIncludes(&$script)
{
$requiredClassFilePath = $this->getStubQueryBuilder()->getClassFilePath();
$script .="
require '".$requiredClassFilePath."';
";
} // addIncludes()
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$baseBuilder = $this->getStubQueryBuilder();
$this->declareClassFromBuilder($baseBuilder);
$baseClassname = $baseBuilder->getClassname();
$script .= "
/**
* Skeleton subclass for representing a query for one of the subclasses of the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator.".$this->getPackage()."
*/
class " .$this->getClassname() . " extends " . $baseClassname . " {
";
}
/**
* Specifies the methods that are added as part of the stub object class.
*
* By default there are no methods for the empty stub classes; override this method
* if you want to change that behavior.
*
* @see ObjectBuilder::addClassBody()
*/
protected function addClassBody(&$script)
{
$this->declareClassFromBuilder($this->getStubPeerBuilder());
$this->declareClasses('PropelPDO', 'Criteria');
$this->addFactory($script);
$this->addPreSelect($script);
$this->addPreUpdate($script);
$this->addPreDelete($script);
$this->addDoDeleteAll($script);
}
/**
* Adds the factory for this object.
* @param string &$script The script will be modified in this method.
*/
protected function addFactory(&$script)
{
$builder = $this->getNewStubQueryInheritanceBuilder($this->getChild());
$this->declareClassFromBuilder($builder);
$classname = $builder->getClassname();
$script .= "
/**
* Returns a new " . $classname . " object.
*
* @param string \$modelAlias The alias of a model in the query
* @param Criteria \$criteria Optional Criteria to build the query from
*
* @return " . $classname . "
*/
public static function create(\$modelAlias = null, \$criteria = null)
{
if (\$criteria instanceof " . $classname . ") {
return \$criteria;
}
\$query = new " . $classname . "();
if (null !== \$modelAlias) {
\$query->setModelAlias(\$modelAlias);
}
if (\$criteria instanceof Criteria) {
\$query->mergeWith(\$criteria);
}
return \$query;
}
";
}
protected function addPreSelect(&$script)
{
$child = $this->getChild();
$col = $child->getColumn();
$script .= "
/**
* Filters the query to target only " . $child->getClassname() . " objects.
*/
public function preSelect(PropelPDO \$con)
{
" . $this->getClassKeyCondition() . "
}
";
}
protected function addPreUpdate(&$script)
{
$child = $this->getChild();
$col = $child->getColumn();
$script .= "
/**
* Filters the query to target only " . $child->getClassname() . " objects.
*/
public function preUpdate(&\$values, PropelPDO \$con, \$forceIndividualSaves = false)
{
" . $this->getClassKeyCondition() . "
}
";
}
protected function addPreDelete(&$script)
{
$child = $this->getChild();
$col = $child->getColumn();
$script .= "
/**
* Filters the query to target only " . $child->getClassname() . " objects.
*/
public function preDelete(PropelPDO \$con)
{
" . $this->getClassKeyCondition() . "
}
";
}
protected function getClassKeyCondition()
{
$child = $this->getChild();
$col = $child->getColumn();
return "\$this->addUsingAlias(" . $col->getConstantName() . ", " . $this->getPeerClassname()."::CLASSKEY_".strtoupper($child->getKey()).");";
}
protected function addDoDeleteAll(&$script)
{
$child = $this->getChild();
$script .= "
/**
* Issue a DELETE query based on the current ModelCriteria deleting all rows in the table
* Having the " . $child->getClassname() . " class.
* This method is called by ModelCriteria::deleteAll() inside a transaction
*
* @param PropelPDO \$con a connection object
*
* @return integer the number of deleted rows
*/
public function doDeleteAll(\$con)
{
// condition on class key is already added in preDelete()
return parent::doDelete(\$con);
}
";
}
/**
* Closes class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassClose(&$script)
{
$script .= "
} // " . $this->getClassname() . "
";
}
} // MultiExtensionQueryBuilder