initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
// Create empty stub node class which extends the BaseNode class created in Node.tpl.
//
// $Id: ExtensionNode.tpl,v 1.2 2004/12/12 10:40:23 micha Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
?>
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . 'Node') ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?> on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getPhpName() ?>Node extends <?php echo $basePrefix . $table->getPhpName() . 'Node' ?> {
}

View File

@ -0,0 +1,35 @@
<?php
// Create empty stub node peer class which extends the BaseNodePeer class created in NodePeer.tpl.
//
// $Id: ExtensionNodePeer.tpl,v 1.2 2004/12/12 10:40:23 micha Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
?>
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . 'NodePeer') ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?> on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getPhpName() ?>NodePeer extends <?php echo $basePrefix . $table->getPhpName() . 'NodePeer' ?> {
}

View File

@ -0,0 +1,36 @@
<?php
// Create empty stub object class which extends the Base class created in Object.tpl.
//
// $Id: ExtensionObject.tpl,v 1.2 2004/10/30 17:53:47 micha Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if ($db->getPackage()) {
$package = $db->getPackage();
} else {
$package = $targetPackage;
}
?>
require_once 'propel/om/Persistent.php';
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName()) ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?> on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getPhpName() ?> extends <?php echo $basePrefix . $table->getPhpName()
?>
{
}

View File

@ -0,0 +1,36 @@
<?php
// Create empty stub Peer class which extends the Base class created in Peer.tpl.
//
// $Id: ExtensionPeer.tpl,v 1.2 2004/10/31 10:24:41 micha Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if ($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
$thisClass = $table->getPhpName() . 'Peer';
$baseClass = $basePrefix . $thisClass;
?>
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . 'Peer') ?>';
include_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName()) ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?>on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getPhpName()?>Peer extends <?php echo $basePrefix . $table->getPhpName() ?>Peer
{
}

View File

@ -0,0 +1,30 @@
<?php
// Create an empty interface.
//
// $Id: Interface.tpl,v 1.3 2004/10/31 10:16:09 micha Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if ($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
?>
/**
* This is an interface that should be filled with the public api of the
* <?php echo $table->getPhpName()?> objects.
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?>on:
*
* [<?php echo $now ?>]
* <?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getInterface() ?>
{
}

View File

@ -0,0 +1,135 @@
<?php
// Create a MapBuilder class for describing the current database at runtime.
//
// $Id: MapBuilder.tpl,v 1.3 2004/12/04 14:32:45 micha Exp $
echo '<' . '?' . 'php';
?>
require_once 'propel/map/MapBuilder.php';
include_once 'creole/CreoleTypes.php';
/**
* This class adds structure of '<?php echo $table->getName() ?>' table to '<?php echo $table->getDatabase()->getName() ?>' DatabaseMap object.
*
* These statically-built map classes are 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).
*
<?php if ($addTimeStamp) { ?>
* This class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* @see BasePeer
* @see DatabaseMap
* @package <?php echo $package ?>.map;
*/
class <?php echo $table->getPhpName() ?>MapBuilder extends MapBuilder
{
/**
* Returns the name of this class.
*/
function CLASS_NAME() { return ("<?php echo $pkmap . '.' . $table->getPhpName() ?>MapBuilder"); }
/**
* The database map.
*/
var $dbMap = null;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean TRUE if this DatabaseMapBuilder is built
*/
function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return DatabaseMap This database map.
*/
function & getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
function doBuild()
{
$this->dbMap =& Propel::getDatabaseMap("<?php echo $table->getDatabase()->getName() ?>");
$tMap =& $this->dbMap->addTable("<?php echo $table->getName()?>");
$tMap->setPhpName("<?php echo $table->getPhpName()?>");
<?php if ($table->getIdMethod() == "native") { ?>
$tMap->setUseIdGenerator(true);
<?php } else { ?>
$tMap->setUseIdGenerator(false);
<?php } ?>
<?php if ($table->getIdMethodParameters()) {
$params = $table->getIdMethodParameters();
$imp = $params[0]; ?>
$tMap->setPrimaryKeyMethodInfo("<?php echo $imp->getValue() ?>");
<?php } elseif ($table->getIdMethod() == "native" && ($platform->getNativeIdMethod() == Platform::SEQUENCE)) { ?>
$tMap->setPrimaryKeyMethodInfo("<?php echo $table->getSequenceName() ?>");
<?php } elseif ($table->getIdMethod() == "native" && ($platform->getNativeIdMethod() == Platform::SEQUENCE)) { ?>
$tMap->setPrimaryKeyMethodInfo("<?php echo $table->getName() ?>");
<?php } ?>
// Add columns to map
<?php foreach ($table->getColumns() as $col) {
$tfc=$table->getPhpName();
$cfc=$col->getPhpName();
$cup=strtoupper($col->getName());
if($col->isPrimaryKey()) {
if($col->isForeignKey()) { ?>
$tMap->addForeignPrimaryKey("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType() ?>" , CreoleTypes::<?php echo $col->getType() ?>(), "<?php echo $col->getRelatedTableName()?>" , "<?php echo strtoupper($col->getRelatedColumnName()) ?>", <?php echo $col->isNotNull() ? 'true' : 'false' ?>);
<?php } else { ?>
$tMap->addPrimaryKey("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType() ?>", CreoleTypes::<?php echo $col->getType() ?>(), <?php echo $col->isNotNull() ? 'true' : 'false' ?>);
<?php }
} else {
if($col->isForeignKey()) { ?>
$tMap->addForeignKey("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType()?>", CreoleTypes::<?php echo $col->getType() ?>(), "<?php echo $col->getRelatedTableName() ?>" , "<?php echo strtoupper($col->getRelatedColumnName()) ?>", <?php echo $col->isNotNull() ? 'true' : 'false' ?>);
<?php } else {
if (!$col->getSize()) {
$size = "null";
} else {
$size = $col->getSize();
}
?>
$tMap->addColumn("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType()?>", CreoleTypes::<?php echo $col->getType() ?>(), <?php echo $col->isNotNull() ? 'true' : 'false' ?>, <?php echo $size ?>);
<?php }
} // if col-is prim key
} // foreach
foreach($table->getValidators() as $val) {
$col = $val->getColumn();
$cup = strtoupper($col->getName());
foreach($val->getRules() as $rule) {
if ($val->getTranslate() !== Validator::TRANSLATE_NONE) {
?>
$tMap->addValidator("<?php echo $cup ?>", "<?php echo $rule->getName() ?>", "<?php echo $rule->getClass() ?>", "<?php echo $rule->getValue()?>", <?php echo $val->getTranslate() ?>("<?php echo str_replace('"', '\"', $rule->getMessage()) ?>"));
<?php } else { ?>
$tMap->addValidator("<?php echo $cup ?>", "<?php echo $rule->getName() ?>", "<?php echo $rule->getClass() ?>", "<?php echo $rule->getValue()?>", "<?php echo str_replace('"', '\"', $rule->getMessage()) ?>");
<?php
} // if ($rule->getTranslation() ...
} // foreach validator
}
?>
}
}

View File

@ -0,0 +1,63 @@
<?php
// Create empty stub subclass which extends the parent stub om class created in ExtensionObject.tpl.
//
// $Id: MultiExtendObject.tpl,v 1.2 2004/12/12 10:40:23 micha Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if ($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
$packagePath = strtr($package, '.', '/');
if ($packagePath != "") $packagePath .= '/';
if ($child->getAncestor()) {
$parent = $child->getAncestor();
?>
require_once '<?php echo strtr($parent, '.', '/') ?>.php';
<?php
$parts = explode('.', $parent);
$parentClass = array_pop($parts);
} else {
$parentClass = $table->getPhpName();
?>
require_once '<?php echo $packagePath . $parentClass ?>.php';
<?php
}
?>
/**
<?php if ($addTimeStamp) { ?>
* The skeleton for this class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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.
*/
class <?php echo $child->getClassName()?> extends <?php echo $parentClass ?>
{
function <?php echo $child->getClassName()?>()
{
<?php
$col = $child->getColumn();
$cfc = $col->getPhpName();
$table = $col->getTable();
?>
$this->set<?php echo $cfc ?>(<?php echo $table->getPhpName() ?>Peer::CLASSKEY_<?php echo strtoupper($child->getKey()) ?>());
}
}

View File

@ -0,0 +1,871 @@
<?php
// Template for creating base node class on tree table.
//
// $Id: Node.tpl,v 1.8 2005/04/04 11:02:40 dlawson_mi Exp $
require_once 'propel/engine/builder/om/ClassTools.php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
$CLASS = $table->getPhpName() . 'NodePeer';
echo '<' . '?' . 'php';
?>
require_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName() . 'NodePeer') ?>';
/**
* Base tree node class for manipulating a tree of <?php echo $table->getPhpName() ?> objects.
* This class will wrap these objects within a "node" interface. It provides a
* method overload mechanism which allows you to use a <?php echo $table->getPhpName() ?>Node
* object just like a <?php $table->getPhpName() ?> object.
*
* To avoid tree corruption, you should always use this class to make changes to
* the tree and objects within it rather than using the <?php echo $table->getPhpName() ?>
* class directly.
*
<?php if ($addTimeStamp) { ?>
* This class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* @package <?php echo $package ?>
*
*/
class <?php echo $basePrefix . $table->getPhpName() ?>Node /*implements IteratorAggregate*/
{
/**
* @var <?php echo $table->getPhpName() ?> Object wrapped by this node.
*/
var $obj = null;
/**
* The parent node for this node.
* @var <?php echo $table->getPhpName() ?>Node
*/
var $parentNode = null;
/**
* Array of child nodes for this node. Nodes indexes are one-based.
* @var array
*/
var $childNodes = array();
/**
* Constructor.
*
* @param <?php echo $table->getPhpName() ?> Object wrapped by this node.
*/
function <?php echo $table->getPhpName() ?>Node($obj = null)
{
Propel::assertParam($obj, '<?php echo $CLASS; ?>', '<?php echo $table->getPhpName() ?>Node', 1);
$obj =& Param::get($obj);
if ($obj !== null)
{
$this->obj =& $obj;
}
else
{
$setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME();
$this->obj =& new <?php echo $table->getPhpName() ?>();
$this->obj->$setNodePath('0');
}
}
/**
* Convenience overload for wrapped object methods.
*
* @param string Method name to call on wrapped object.
* @param mixed Parameter accepted by wrapped object set method.
* @return mixed Return value of wrapped object method.
* @throws PropelException Fails if method is not defined for wrapped object.
*/
function & callObjMethod($name, $parms = null)
{
$params =& Param::get($parms);
if (method_exists($this->obj, $name)) {
if (is_array($params)) {
$implode = array();
$keys = array_keys($params);
foreach($keys as $key)
$implode [] = "\$params['{$key}']";
eval('$result =& $this->obj->$name(' . implode(',', $implode) . ');');
}
else {
$result =& $this->obj->$name($params);
}
return $result;
}
else
return new PropelException(PROPEL_ERROR, "get method not defined: $name");
}
/**
* Sets the default options for iterators created from this object.
* The options are specified in map format. The following options
* are supported by all iterators. Some iterators may support other
* options:
*
* "querydb" - True if nodes should be retrieved from database.
* "con" - Connection to use if retrieving from database.
*
* @param string Type of iterator to use ("pre", "post", "level").
* @param array Map of option name => value.
* @return void
* @todo Implement other iterator types (i.e. post-order, level, etc.)
*/
function setIteratorOptions($type, $opts)
{
$this->itType = $type;
$this->itOpts = $opts;
}
/**
* Returns a pre-order iterator for this node and its children.
*
* @param string Type of iterator to use ("pre", "post", "level")
* @param array Map of option name => value.
* @return NodeIterator
*/
function & getIterator($type = null, $opts = null)
{
if ($type === null)
$type = (isset($this->itType) ? $this->itType : 'Pre');
if ($opts === null)
$opts = (isset($this->itOpts) ? $this->itOpts : array());
$itclass = ucfirst(strtolower($type)) . 'OrderNodeIterator';
require_once('propel/om/' . $itclass . '.php');
return new $itclass($this, $opts);
}
/**
* Returns the object wrapped by this class.
* @return <?php echo $table->getPhpName() . "\n" ?>
*/
function & getNodeObj()
{
return $this->obj;
}
/**
* Convenience method for retrieving nodepath.
* @return string
*/
function getNodePath()
{
$getNodePath = 'get' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME();
return $this->obj->$getNodePath();
}
/**
* Returns one-based node index among siblings.
* @return int
*/
function getNodeIndex()
{
$npath = $this->getNodePath();
//strrpos fix
$sep = 0;
while(false !== ($last = strpos($npath, <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP(), $sep))) {
$sep = $last + strlen(<?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP());
}
return (int) ($sep != 0 ? substr($npath, $sep) : $npath);
}
/**
* Returns one-based node level within tree (root node is level 1).
* @return int
*/
function getNodeLevel()
{
return (substr_count($this->getNodePath(), <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP()) + 1);
}
/**
* Returns true if specified node is a child of this node. If recurse is
* true, checks if specified node is a descendant of this node.
*
* @param <?php echo $table->getPhpName() ?>Node Node to look for.
* @param boolean True if strict comparison should be used.
* @param boolean True if all descendants should be checked.
* @return boolean
*/
function hasChildNode(&$node, $strict = false, $recurse = false)
{
foreach ($this->childNodes as $key => $childNode)
{
if ($this->childNodes[$key]->equals($node, $strict))
return true;
if ($recurse && $this->childNodes[$key]->hasChildNode($node, $recurse))
return true;
}
return false;
}
/**
* Returns child node at one-based index. Retrieves from database if not
* loaded yet.
*
* @param int One-based child node index.
* @param boolean True if child should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
function & getChildNodeAt($i, $querydb = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'getChildNodeAt', 3);
$con =& Param::get($con);
if ($querydb &&
!$this->obj->isNew() &&
!$this->obj->isDeleted() &&
!isset($this->childNodes[$i]))
{
$criteria =& new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME(),
$this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . $i,
Criteria::EQUAL());
if ($childObj =& <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, Param::set($con)))
$this->attachChildNode(new <?php echo $table->getPhpName() ?>Node(Param::set($childObj)));
}
return (isset($this->childNodes[$i]) ? $this->childNodes[$i] : null);
}
/**
* Returns first child node (if any). Retrieves from database if not loaded yet.
*
* @param boolean True if child should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
function & getFirstChildNode($querydb = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'getFirstChildNode', 2);
$con =& Param::get($con);
return $this->getChildNodeAt(1, $querydb, Param::set($con));
}
/**
* Returns last child node (if any).
*
* @param boolean True if child should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
*/
function & getLastChildNode($querydb = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'getLastChildNode', 2);
$con =& Param::get($con);
$lastNode = null;
if ($this->obj->isNew() || $this->obj->isDeleted())
{
if (count($this->childNodes)) {
end($this->childNodes);
$lastNode =& $this->childNodes[key($this->childNodes)];
}
}
else if ($querydb)
{
$db =& Propel::getDb(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
$criteria =& new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME(),
$this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . '%',
Criteria::LIKE());
$criteria->addAnd(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME(),
$this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . '%' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . '%',
Criteria::NOT_LIKE());
$criteria->addAsColumn('npathlen', $db->strLength(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME()));
$criteria->addDescendingOrderByColumn('npathlen');
$criteria->addDescendingOrderByColumn(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME());
$lastObj =& <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, Param::set($con));
if ($lastObj !== null)
{
$lastNode =& new <?php echo $table->getPhpName() ?>Node(Param::set($lastObj));
$endNode = null;
if (count($this->childNodes)) {
end($this->childNodes);
$endNode =& $this->childNodes[key($this->childNodes)];
}
if ($endNode)
{
if ($endNode->getNodePath() > $lastNode->getNodePath())
return new PropelException(PROPEL_ERROR, 'Cached child node inconsistent with database.');
else if ($endNode->getNodePath() == $lastNode->getNodePath())
$lastNode =& $endNode;
else
$this->attachChildNode($lastNode);
}
else
{
$this->attachChildNode($lastNode);
}
}
}
return $lastNode;
}
/**
* Returns next (or previous) sibling node or null. Retrieves from database if
* not loaded yet.
*
* @param boolean True if previous sibling should be returned.
* @param boolean True if sibling should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
function & getSiblingNode($prev = false, $querydb = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'getSiblingNode', 3);
$con =& Param::get($con);
$nidx = $this->getNodeIndex();
if ($this->isRootNode())
{
return null;
}
else if ($prev)
{
if ($nidx > 1 && ($parentNode =& $this->getParentNode($querydb, Param::set($con))))
return $parentNode->getChildNodeAt($nidx-1, $querydb, Param::set($con));
else
return null;
}
else
{
if ($parentNode =& $this->getParentNode($querydb, Param::set($con)))
return $parentNode->getChildNodeAt($nidx+1, $querydb, Param::set($con));
else
return null;
}
}
/**
* Returns parent node. Loads from database if not cached yet.
*
* @param boolean True if parent should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
function & getParentNode($querydb = true, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'getParentNode', 2);
$con =& Param::get($con);
if ($querydb &&
$this->parentNode === null &&
!$this->isRootNode() &&
!$this->obj->isNew() &&
!$this->obj->isDeleted())
{
$npath =& $this->getNodePath();
//strrpos fix
$sep = 0;
while(false !== ($last = strpos($npath, <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP(), $sep))) {
$sep = $last + strlen(<?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP());
}
$ppath = substr($npath, 0, $sep - strlen(<?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP()));
$criteria =& new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME(), $ppath, Criteria::EQUAL());
if ($parentObj =& <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, Param::set($con)))
{
$parentNode =& new <?php echo $table->getPhpName() ?>Node(Param::set($parentObj));
$parentNode->attachChildNode($this);
}
}
return $this->parentNode;
}
/**
* Returns an array of all ancestor nodes, starting with the root node
* first.
*
* @param boolean True if ancestors should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return array
*/
function & getAncestors($querydb = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'getAncestors', 2);
$con =& Param::get($con);
$ancestors = array();
$parentNode = $this;
while ($parentNode =& $parentNode->getParentNode($querydb, Param::set($con)))
array_unshift($ancestors, $parentNode);
return $ancestors;
}
/**
* Returns true if node is the root node of the tree.
* @return boolean
*/
function isRootNode()
{
return ($this->getNodePath() === '1');
}
/**
* Changes the state of the object and its descendants to 'new'.
* Also changes the node path to '0' to indicate that it is not a
* stored node.
*
* @param boolean
* @return void
*/
function setNew($b)
{
$this->adjustStatus('new', $b);
$this->adjustNodePath($this->getNodePath(), '0');
}
/**
* Changes the state of the object and its descendants to 'deleted'.
*
* @param boolean
* @return void
*/
function setDeleted($b)
{
$this->adjustStatus('deleted', $b);
}
/**
* Adds the specified node (and its children) as a child to this node. If a
* valid $beforeNode is specified, the node will be inserted in front of
* $beforeNode. If $beforeNode is not specified the node will be appended to
* the end of the child nodes.
*
* @param <?php echo $table->getPhpName() ?>Node Node to add.
* @param <?php echo $table->getPhpName() ?>Node Node to insert before.
* @param Connection Connection to use.
*/
function addChildNode(&$node, $beforeNode = null, $con = null)
{
Propel::assertParam($beforeNode, '<?php echo $CLASS; ?>', 'addChildNode', 2);
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'addChildNode', 3);
$beforeNode =& Param::get($beforeNode);
$con =& Param::get($con);
if ($this->obj->isNew() && !$node->obj->isNew())
return new PropelException(PROPEL_ERROR, 'Cannot add stored nodes to a new node.');
if ($this->obj->isDeleted() || $node->obj->isDeleted())
return new PropelException(PROPEL_ERROR, 'Cannot add children in a deleted state.');
if ($this->hasChildNode($node))
return new PropelException(PROPEL_ERROR, 'Node is already a child of this node.');
if ($beforeNode && !$this->hasChildNode($beforeNode))
return new PropelException(PROPEL_ERROR, 'Invalid beforeNode.');
if ($con === null)
$con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
if (Propel::isError($con))
return $con;
if (!$this->obj->isNew()) {
$e = $con->begin();
if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
}
if ($beforeNode)
{
// Inserting before a node.
$childIdx = $beforeNode->getNodeIndex();
$e = $this->shiftChildNodes(1, $beforeNode->getNodeIndex(), $con);
if (Propel::isError($e)) { $con->rollback(); return $e; }
}
else
{
// Appending child node.
if ($lastNode =& $this->getLastChildNode(true, Param::set($con)))
$childIdx = $lastNode->getNodeIndex()+1;
else
$childIdx = 1;
}
// Add the child (and its children) at the specified index.
if (!$this->obj->isNew() && $node->obj->isNew())
{
$e = $this->insertNewChildNode($node, $childIdx, $con);
if (Propel::isError($e)) { $con->rollback(); return $e; }
}
else
{
// $this->isNew() && $node->isNew() ||
// !$this->isNew() && !node->isNew()
$srcPath = $node->getNodePath();
$dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . $childIdx;
if (!$node->obj->isNew())
{
$e = <?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree($srcPath, $dstPath, Param::set($con));
if (Propel::isError($e)) { $con->rollback(); return $e; }
$parentNode =& $node->getParentNode(true, Param::set($con));
}
else
{
$parentNode =& $node->getParentNode();
}
if ($parentNode)
{
$parentNode->detachChildNode($node);
$e = $parentNode->shiftChildNodes(-1, $node->getNodeIndex()+1, $con);
if (Propel::isError($e)) { $con->rollback(); return $e; }
}
$node->adjustNodePath($srcPath, $dstPath);
}
if (!$this->obj->isNew()) {
$e = $con->commit();
if (Creole::isError($e)) { return new PropelException(PROPEL_ERROR_DB, $e); }
}
$this->attachChildNode($node);
}
/**
* Moves the specified child node in the specified direction.
*
* @param <?php $table->getPhpName() ?>Node Node to move.
* @param int Number of spaces to move among siblings (may be negative).
* @param Connection Connection to use.
* @throws PropelException
*/
function moveChildNode(&$node, $direction, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'moveChildNode', 3);
$con =& Param::get($con);
return new PropelException(PROPEL_ERROR, 'moveChildNode() not implemented yet.');
}
/**
* Saves modified object data to the datastore.
*
* @param boolean If true, descendants will be saved as well.
* @param Connection Connection to use.
*/
function save($recurse = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'save', 2);
$con =& Param::get($con);
if ($this->obj->isDeleted())
return new PropelException(PROPEL_ERROR, 'Cannot save deleted node.');
if (substr($this->getNodePath(), 0, 1) == '0')
return new PropelException(PROPEL_ERROR, 'Cannot save unattached node.');
if ($this->obj->isColumnModified(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME()))
return new PropelException(PROPEL_ERROR, 'Cannot save manually modified node path.');
$this->obj->save(Param::set($con));
if ($recurse)
{
foreach ($this->childNodes as $key => $childNode)
$this->childNodes[$key]->save($recurse, Param::set($con));
}
}
/**
* Removes this object and all descendants from datastore.
*
* @param Connection Connection to use.
* @return void
* @throws PropelException
*/
function delete($con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'delete', 1);
$con =& Param::get($con);
if ($this->obj->isDeleted())
return new PropelException(PROPEL_ERROR, 'This node has already been deleted.');
if (!$this->obj->isNew())
{
<?php echo $table->getPhpName() ?>NodePeer::deleteNodeSubTree($this->getNodePath(), Param::set($con));
}
if ($parentNode =& $this->getParentNode(true, Param::set($con)))
{
$parentNode->detachChildNode($this);
$parentNode->shiftChildNodes(-1, $this->getNodeIndex()+1, $con);
}
$this->setDeleted(true);
}
/**
* Compares the object wrapped by this node with that of another node. Use
* this instead of equality operators to prevent recursive dependency
* errors.
*
* @param <?php echo $table->getPhpName() ?>Node Node to compare.
* @param boolean True if strict comparison should be used.
* @return boolean
*/
function equals(&$node, $strict = false)
{
if ($strict)
return ($this->obj === $node->obj);
else
return ($this->obj == $node->obj);
}
/**
* This method is used internally when constructing the tree structure
* from the database. To set the parent of a node, you should call
* addChildNode() on the parent.
* @param <?php echo $table->getPhpName() ?>Node Parent node to attach.
* @return void
* @throws PropelException
*/
function attachParentNode(&$node)
{
if (!$node->hasChildNode($this, true))
return new PropelException(PROPEL_ERROR, 'Failed to attach parent node for non-child.');
$this->parentNode =& $node;
}
/**
* This method is used internally when constructing the tree structure
* from the database. To add a child to a node you should call the
* addChildNode() method instead.
*
* @param <?php echo $table->getPhpName() ?>Node Child node to attach.
* @return void
* @throws PropelException
*/
function attachChildNode(&$node)
{
if ($this->hasChildNode($node))
return new PropelException(PROPEL_ERROR, 'Failed to attach child node. Node already exists.');
if ($this->obj->isDeleted() || $node->obj->isDeleted())
return new PropelException(PROPEL_ERROR, 'Failed to attach node in deleted state.');
if ($this->obj->isNew() && !$node->obj->isNew())
return new PropelException(PROPEL_ERROR, 'Failed to attach non-new child to new node.');
if (!$this->obj->isNew() && $node->obj->isNew())
return new PropelException(PROPEL_ERROR, 'Failed to attach new child to non-new node.');
if ($this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . $node->getNodeIndex() != $node->getNodePath())
return new PropelException(PROPEL_ERROR, 'Failed to attach child node. Node path mismatch.');
$this->childNodes[$node->getNodeIndex()] =& $node;
ksort($this->childNodes);
$node->attachParentNode($this);
}
/**
* This method is used internally when deleting nodes. It is used to break
* the link to this node's parent.
* @param <?php echo $table->getPhpName() ?>Node Parent node to detach from.
* @return void
* @throws PropelException
*/
function detachParentNode(&$node)
{
if (!$node->hasChildNode($this, true))
return new PropelException(PROPEL_ERROR, 'Failed to detach parent node from non-child.');
unset($node->childNodes[$this->getNodeIndex()]);
$this->parentNode = null;
}
/**
* This method is used internally when deleting nodes. It is used to break
* the link to this between this node and the specified child.
* @param <?php echo $table->getPhpName() ?>Node Child node to detach.
* @return void
* @throws PropelException
*/
function detachChildNode(&$node)
{
if (!$this->hasChildNode($node, true))
return new PropelException(PROPEL_ERROR, 'Failed to detach non-existent child node.');
$this->childNodes[$node->getNodeIndex()] = & Propel::null();
unset($this->childNodes[$node->getNodeIndex()]);
$node->parentNode =& Propel::null();
}
/**
* Shifts child nodes in the specified direction and offset index. This
* method assumes that there is already space available in the
* direction/offset indicated.
*
* @param int Direction/# spaces to shift. 1=leftshift, 1=rightshift
* @param int Node index to start shift at.
* @param Connection The connection to be used.
* @return void
* @throws PropelException
*/
function shiftChildNodes($direction, $offsetIdx, &$con)
{
if ($this->obj->isDeleted())
return new PropelException(PROPEL_ERROR, 'Cannot shift nodes for deleted object');
$lastNode =& $this->getLastChildNode(true, Param::set($con));
$lastIdx = ($lastNode !== null ? $lastNode->getNodeIndex() : 0);
if ($lastNode === null || $offsetIdx > $lastIdx)
return;
if ($con === null)
$con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
if (Propel::isError($con)) {
return $con;
}
if (!$this->obj->isNew())
{
// Shift nodes in database.
$e = $con->begin();
if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
$n = $lastIdx - $offsetIdx + 1;
$i = $direction < 1 ? $offsetIdx : $lastIdx;
while ($n--)
{
$srcPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . $i; // 1.2.2
$dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . ($i+$direction); // 1.2.3
$e = <?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree($srcPath, $dstPath, Param::set($con));
if (Propel::isError($e)) { $con->rollback(); return $e; }
$i -= $direction;
}
$e = $con->commit();
if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
}
// Shift the in-memory objects.
$n = $lastIdx - $offsetIdx + 1;
$i = $direction < 1 ? $offsetIdx : $lastIdx;
while ($n--)
{
if (isset($this->childNodes[$i]))
{
$srcPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . $i; // 1.2.2
$dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . ($i+$direction); // 1.2.3
$this->childNodes[$i+$direction] =& $this->childNodes[$i];
$this->childNodes[$i+$direction]->adjustNodePath($srcPath, $dstPath);
unset($this->childNodes[$i]);
}
$i -= $direction;
}
ksort($this->childNodes);
}
/**
* Inserts the node and its children at the specified childIdx.
*
* @param <?php echo $table->getPhpName() ?>Node Node to insert.
* @param int One-based child index to insert at.
* @param Connection Connection to use.
* @param void
*/
function insertNewChildNode(&$node, $childIdx, &$con)
{
if (!$node->obj->isNew())
return new PropelException(PROPEL_ERROR, 'Failed to insert non-new node.');
$setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME();
$node->obj->$setNodePath($this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . $childIdx);
$node->obj->save(Param::set($con));
$i = 1;
foreach($node->childNodes as $key => $childNode)
$node->insertNewChildNode($node->childNodes[$key], $i++, $con);
}
/**
* Adjust new/deleted status of node and all children.
*
* @param string Status to change ('New' or 'Deleted')
* @param boolean Value for status.
* @return void
*/
function adjustStatus($status, $b)
{
$setStatus = 'set' . $status;
$this->obj->$setStatus($b);
foreach ($this->childNodes as $key => $childNode)
$this->childNodes[$key]->obj->$setStatus($b);
}
/**
* Adjust path of node and all children. This is used internally when
* inserting/moving nodes.
*
* @param string Section of old path to change.
* @param string New section to replace old path with.
* @return void
*/
function adjustNodePath($oldBasePath, $newBasePath)
{
$setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME();
$this->obj->$setNodePath($newBasePath .
substr($this->getNodePath(), strlen($oldBasePath)));
$this->obj->resetModified(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME());
foreach ($this->childNodes as $key => $childNode)
$this->childNodes[$key]->adjustNodePath($oldBasePath, $newBasePath);
}
}
?>

View File

@ -0,0 +1,563 @@
<?php
// Template for creating base node Peer class on tree table.
//
// $Id: NodePeer.tpl,v 1.10 2005/02/13 12:23:52 micha Exp $
require_once 'propel/engine/builder/om/ClassTools.php';
require_once 'propel/engine/builder/om/PeerBuilder.php';
$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;
}
}
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
$CLASS = $table->getPhpName() . 'NodePeer';
echo '<' . '?' . 'php';
?>
require_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName()) ?>';
require_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName() . 'Node') ?>';
/**
* Base static class for performing query operations on the tree contained by the
* '<?php echo $table->getPhpName() ?>' table.
*
<?php if ($addTimeStamp) { ?>
* This class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* @package <?php echo $package ?>
*/
class <?php echo $basePrefix . $table->getPhpName() ?>NodePeer
{
function NPATH_COLNAME() { return '<?php echo $npath_colname ?>'; }
function NPATH_PHPNAME() { return '<?php echo $npath_phpname ?>'; }
function NPATH_SEP() { return '<?php echo $npath_sep ?>'; }
/**
* Temp function for CodeBase hacks that will go away.
*/
function isCodeBase($con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'isCodeBase', 1);
$con =& Param::get($con);
if ($con === null)
$con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
return (get_class($con) == 'ODBCConnection' &&
get_class($con->getAdapter()) == 'CodeBaseAdapter');
}
/**
* 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 <?php echo $table->getPhpName() ?> Object wrapped by new node.
* @param Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
* @throws PropelException
*/
function & createNewRootNode(&$obj, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'createNewRootNode', 2);
$con =& Param::get($con);
if ($con === null)
$con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
if (Propel::isError($con)) {
return $con;
}
$e = $con->begin();
if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
$e = <?php echo $table->getPhpName() ?>NodePeer::deleteNodeSubTree('1', Param::set($con));
if (Propel::isError($e)) { $con->rollback(); return $e; }
$setNodePath = 'set' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME();
$obj->$setNodePath('1');
$e = $obj->save(Param::set($con));
if (Propel::isError($e)) { $con->rollback(); return $e; }
$e = $con->commit();
if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
return new <?php echo $table->getPhpName() ?>Node(Param::set($obj));
}
/**
* 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 <?php echo $table->getPhpName() ?> Object wrapped by new node.
* @param Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
* @throws PropelException
*/
function & insertNewRootNode(&$obj, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'insertNewRootNode', 2);
$con =& Param::get($con);
if ($con === null)
$con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
$e = $con->begin();
if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
// Move root tree to an invalid node path.
$e = <?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree('1', '0', Param::set($con));
if (Propel::isError($e)) { $con->rollback(); return $e; }
$setNodePath = 'set' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME();
// Insert the new root node.
$obj->$setNodePath('1');
$e = $obj->save(Param::set($con));
if (Propel::isError($e)) { $con->rollback(); return $e; }
// Move the old root tree as a child of the new root.
$e = <?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree('0', '1' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . '1', Param::set($con));
if (Propel::isError($e)) { $con->rollback(); return $e; }
$e = $con->commit();
if (Creole::isError($e)) { $con->rollback(); return new PropelException(PROPEL_ERROR_DB, $e); }
return new <?php echo $table->getPhpName() ?>Node(Param::set($obj));
}
/**
* 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 Connection Connection to use.
* @return array Array of root nodes.
*/
function & retrieveNodes(&$criteria, $ancestors = false, $descendants = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'retrieveNodes', 4);
$con =& Param::get($con);
$criteria =& <?php echo $table->getPhpName() ?>NodePeer::buildFamilyCriteria($criteria, $ancestors, $descendants);
$rs =& <?php echo $table->getPhpName() ?>Peer::doSelectRS($criteria, Param::set($con));
return <?php echo $table->getPhpName() ?>NodePeer::populateNodes($rs, $criteria);
}
/**
* Retrieves a tree node based on a primary key. Optionally includes all
* parent and/or child nodes of the matching node.
*
* @param mixed <?php echo $table->getPhpName() ?> 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 Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
*/
function & retrieveNodeByPK($pk, $ancestors = false, $descendants = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'retrieveNodeByPK', 4);
$con =& Param::get($con);
return new PropelException(PROPEL_ERROR, 'retrieveNodeByPK() not implemented yet.');
}
/**
* 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 Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
*/
function & retrieveNodeByNP($np, $ancestors = false, $descendants = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'retrieveNodeByNP', 4);
$con =& Param::get($con);
$criteria =& new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME(), $np, Criteria::EQUAL());
$criteria =& <?php echo $table->getPhpName() ?>NodePeer::buildFamilyCriteria($criteria, $ancestors, $descendants);
$rs =& <?php echo $table->getPhpName() ?>Peer::doSelectRS($criteria, Param::set($con));
$nodes =& <?php echo $table->getPhpName() ?>NodePeer::populateNodes($rs, $criteria);
return (count($nodes) == 1 ? $nodes[0] : null);
}
/**
* Retrieves the root node.
*
* @param string Node path to retrieve.
* @param boolean True if descendants should also be retrieved.
* @param Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
*/
function & retrieveRootNode($descendants = false, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'retrieveRootNode', 2);
$con =& Param::get($con);
return <?php echo $table->getPhpName() ?>NodePeer::retrieveNodeByNP('1', false, $descendants, Param::set($con));
}
/**
* 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 Connection 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.
*/
function moveNodeSubTree($srcPath, $dstPath, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'moveNodeSubTree', 3);
$con =& Param::get($con);
if (substr($dstPath, 0, strlen($srcPath)) == $srcPath)
return new PropelException(PROPEL_ERROR, 'Cannot move a node subtree within itself.');
if ($con === null)
$con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
/**
* Example:
* UPDATE table
* SET npath = CONCAT('1.3', SUBSTRING(npath, 6, 74))
* WHERE npath = '1.2.2' OR npath LIKE '1.2.2.%'
*/
$npath = <?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME();
//the following dot isn`t mean`t a nodeKeySeperator
$setcol = substr($npath, strpos($npath, '.')+1);
$setcollen = <?php echo $npath_len ?>;
$db = Propel::getDb(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
// <hack>
if (<?php echo $table->getPhpName() ?>NodePeer::isCodeBase(Param::set($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 " . <?php echo $table->getPhpName() ?>Peer::TABLE_NAME() . " " .
"SET $setcol=" . $db->concatString("'$dstPath'", $db->subString($npath, strlen($srcPath)+1, $setcollen)) . " " .
"WHERE $npath = '$srcPath' OR $npath LIKE '$srcPath" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . "%'";
$con->executeUpdate($sql);
}
else
{
// </hack>
$sql = "UPDATE " . <?php echo $table->getPhpName() ?>Peer::TABLE_NAME() . " " .
"SET $setcol=" . $db->concatString('?', $db->subString($npath, '?', '?')) . " " .
"WHERE $npath = ? OR $npath LIKE ?";
$stmt =& $con->prepareStatement($sql);
$stmt->setString(1, $dstPath);
$stmt->setInt(2, strlen($srcPath)+1);
$stmt->setInt(3, $setcollen);
$stmt->setString(4, $srcPath);
$stmt->setString(5, $srcPath . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . '%');
$stmt->executeUpdate();
// <hack>
}
// </hack>
}
/**
* Deletes the node subtree at the specified node path from the database.
*
* @param string Node path to delete
* @param Connection Connection to use.
* @return void
* @throws PropelException
* @todo This is currently broken for simulated "onCascadeDelete"s.
*/
function deleteNodeSubTree($nodePath, $con = null)
{
Propel::assertParam($con, '<?php echo $CLASS; ?>', 'deleteNodeSubTree', 2);
$con =& Param::get($con);
if ($con === null)
$con =& Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
/**
* DELETE FROM table
* WHERE npath = '1.2.2' OR npath LIKE '1.2.2.%'
*/
$criteria =& new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME());
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME(), $nodePath, Criteria::EQUAL());
$criteria->addOr(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME(), $nodePath . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP() . '%', Criteria::LIKE());
// For now, we call BasePeer directly since <?php echo $table->getPhpName() ?>Peer tries to
// do a cascade delete.
// <?php echo $table->getPhpName() ?>Peer::doDelete($criteria, Param::set($con));
BasePeer::doDelete($criteria, $con);
}
/**
* 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
*/
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(<?php echo $table->getPhpName() ?>::DATABASE_NAME());
if (!$criteria->getSelectColumns())
<?php echo $table->getPhpName() ?>Peer::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', <?php echo $table->getPhpName() ?>Peer::TABLE_NAME());
// Make sure we have select columns to begin with.
if (!$criteria->getSelectColumns())
<?php echo $table->getPhpName() ?>Peer::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(<?php echo $table->getPhpName() ?>Peer::TABLE_NAME(), 'L', $colName));
$a = null;
$d = null;
$npathL = <?php echo $table->getPhpName() ?>Peer::alias('L', <?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME());
$npathR = <?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME();
$npath_len = <?php echo $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(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME());
// Sort by node path to speed up tree construction in populateNodes()
$criteria->addAsColumn('npathlen', $db->strLength(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME()));
$criteria->addAscendingOrderByColumn('npathlen');
$criteria->addAscendingOrderByColumn(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME());
}
return $criteria;
}
/**
* 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 <?php echo $table->getPhpName() ?>Node methods of the
* subtree root nodes.
*
* @param array Array of <?php echo $table->getPhpName() ?>Node objects
* @return array Array of <?php echo $table->getPhpName() ?>Node objects
*/
function & buildTree(&$nodes)
{
// Subtree root nodes to return
$rootNodes = array();
$copy = $nodes;
// Build the tree relations
foreach ($nodes as $key1 => $node)
{
//strrpos fix
$sep = 0;
while(false !== ($last = strpos($node->getNodePath(), <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP(), $sep))) {
$sep = $last + strlen(<?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP());
}
$parentPath = ($sep != 0 ? substr($node->getNodePath(), 0, $sep - strlen(<?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP())) : '');
$parentNode =& Propel::null();
// Scan other nodes for parent.
foreach ($copy as $key2 => $pnode)
{
if ($pnode->getNodePath() == $parentPath)
{
$parentNode =& $nodes[$key2];
break;
}
}
// If parent was found, attach as child, otherwise its a subtree root
if ($parentNode)
$parentNode->attachChildNode($nodes[$key1]);
else
$rootNodes[] =& $nodes[$key1];
}
return $rootNodes;
}
/**
* Populates the <?php echo $table->getPhpName() ?> objects from the
* specified ResultSet, wraps them in <?php echo $table->getPhpName() ?>Node
* 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 ResultSet
* @param Criteria
* @return array Array of <?php $table->getPhpName() ?>Node objects.
*/
function & populateNodes(&$rs, &$criteria)
{
$nodes = array();
$targets = array();
$values = array();
$targetfld = count($criteria->getSelectColumns());
<?php if (!$table->getChildrenColumn()) { ?>
// set the class once to avoid overhead in the loop
$cls = <?php echo $table->getPhpName() ?>Peer::getOMClass();
if (Propel::isError($cls =& Propel::import($cls))) {
return $cls;
}
<?php } ?>
// populate the object(s)
while($rs->next())
{
if (!isset($nodes[$rs->getString(1)]))
{
<?php if ($table->getChildrenColumn()) { ?>
// class must be set each time from the record row
$cls =& Propel::import(<?php echo $table->getPhpName() ?>Peer::getOMClass($rs, 1));
if (Propel::isError($cls)) {
return $cls;
}
<?php } ?>
$obj =& new $cls();
if (Propel::isError($e =& $obj->hydrate($rs))) {
return $e;
}
$nodes[$rs->getString(1)] =& new <?php echo $table->getPhpName() ?>Node(Param::set($obj));
}
$node =& $nodes[$rs->getString(1)];
if ($node->getNodePath() == $rs->getString($targetfld))
$targets[$node->getNodePath()] =& $node;
}
<?php echo $table->getPhpName() ?>NodePeer::buildTree($nodes);
foreach($targets as $key => $value)
$values[] =& $targets[$key];
return $values;
}
}
?>

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,35 @@
<?php
// Create empty stub node class which extends the BaseNode class created in Node.tpl.
//
// $Id: ExtensionNode.tpl,v 1.2 2004/10/06 16:54:47 hlellelid Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
?>
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . 'Node') ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?> on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getPhpName() ?>Node extends <?php echo $basePrefix . $table->getPhpName() . 'Node' ?> {
}

View File

@ -0,0 +1,35 @@
<?php
// Create empty stub node peer class which extends the BaseNodePeer class created in NodePeer.tpl.
//
// $Id: ExtensionNodePeer.tpl,v 1.2 2004/10/06 16:54:47 hlellelid Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
?>
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . 'NodePeer') ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?> on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getPhpName() ?>NodePeer extends <?php echo $basePrefix . $table->getPhpName() . 'NodePeer' ?> {
}

View File

@ -0,0 +1,49 @@
<?php
// Create empty stub object class which extends the Base class created in Object.tpl.
//
// $Id: ExtensionObject.tpl,v 1.5 2004/10/06 16:54:47 hlellelid Exp $
echo '<' . '?' . 'php';
$interface = ClassTools::getInterface($table);
if (!empty($interface)) {
?>
require_once '<?php echo ClassTools::getFilePath($interface) ?>';
<?php
}
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
$abstract = "";
if ($table->isAbstract()) {
$abstract = "abstract ";
}
?>
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName()) ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?> on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
<?php echo $abstract ?>class <?php echo $table->getPhpName() ?> extends <?php echo $basePrefix . $table->getPhpName() ?><?php if (!empty($interface)) { ?> implements <?php echo ClassTools::classname($interface) ?><?php } ?> {
}

View File

@ -0,0 +1,37 @@
<?php
// Create empty stub Peer class which extends the Base class created in Peer.tpl.
//
// $Id: ExtensionPeer.tpl,v 1.2 2004/10/06 16:54:47 hlellelid Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
?>
// The parent class
require_once '<?php echo ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . 'Peer') ?>';
// The object class
include_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName()) ?>';
/**
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?>on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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 <?php echo $package ?>
*/
class <?php echo $table->getPhpName()?>Peer extends <?php echo $basePrefix . $table->getPhpName() ?>Peer {
}

View File

@ -0,0 +1,33 @@
<?php
// Create an empty interface.
//
// $Id: Interface.tpl,v 1.2 2004/10/06 16:54:47 hlellelid Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
$interface = ClassTools::getInterface($table);
?>
/**
* This is an interface that should be filled with the public api of the
* <?php echo $table->getPhpName()?> objects.
* The skeleton for this class was autogenerated by Propel <?php if ($addTimeStamp) { ?>on:
*
* [<?php echo $now ?>]
* <?php } ?>
* 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.
*/
interface <?php echo ClassTools::classname($interface) ?> {
}

View File

@ -0,0 +1,135 @@
<?php
// Create a MapBuilder class for describing the current database at runtime.
//
// $Id: MapBuilder.tpl,v 1.2 2004/12/04 14:32:45 micha Exp $
echo '<' . '?' . 'php';
?>
require_once 'propel/map/MapBuilder.php';
include_once 'creole/CreoleTypes.php';
/**
* This class adds structure of '<?php echo $table->getName() ?>' table to '<?php echo $table->getDatabase()->getName() ?>' DatabaseMap object.
*
* These statically-built map classes are 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).
*
<?php if ($addTimeStamp) { ?>
* This class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* @see BasePeer
* @see DatabaseMap
* @package <?php echo $package ?>.map
*/
class <?php echo $table->getPhpName() ?>MapBuilder implements MapBuilder {
/**
* The name of this class
*/
const CLASS_NAME = "<?php echo $pkmap . '.' . $table->getPhpName() ?>MapBuilder";
/**
* The database map.
*/
private $dbMap = null;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return true if this DatabaseMapBuilder is built
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap("<?php echo $table->getDatabase()->getName() ?>");
$tMap = $this->dbMap->addTable("<?php echo $table->getName()?>");
$tMap->setPhpName("<?php echo $table->getPhpName()?>");
<?php if ($table->getIdMethod() == "native") { ?>
$tMap->setUseIdGenerator(true);
<?php } else { ?>
$tMap->setUseIdGenerator(false);
<?php } ?>
<?php if ($table->getIdMethodParameters()) {
$params = $table->getIdMethodParameters();
$imp = $params[0]; ?>
$tMap->setPrimaryKeyMethodInfo("<?php echo $imp->getValue() ?>");
<?php } elseif ($table->getIdMethod() == "native" && ($platform->getNativeIdMethod() == Platform::SEQUENCE)) { ?>
$tMap->setPrimaryKeyMethodInfo("<?php echo $table->getSequenceName() ?>");
<?php } elseif ($table->getIdMethod() == "native" && ($platform->getNativeIdMethod() == Platform::SEQUENCE)) { ?>
$tMap->setPrimaryKeyMethodInfo("<?php echo $table->getName() ?>");
<?php } ?>
// Add columns to map
<?php foreach ($table->getColumns() as $col) {
$tfc=$table->getPhpName();
$cfc=$col->getPhpName();
$cup=strtoupper($col->getName());
if (!$col->getSize()) {
$size = "null";
} else {
$size = $col->getSize();
}
if($col->isPrimaryKey()) {
if($col->isForeignKey()) { ?>
$tMap->addForeignPrimaryKey("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType() ?>" , CreoleTypes::<?php echo $col->getType() ?>, "<?php echo $col->getRelatedTableName()?>", "<?php echo strtoupper($col->getRelatedColumnName()) ?>", <?php echo $col->isNotNull() ? 'true' : 'false' ?>, <?php echo $size ?>);
<?php } else { ?>
$tMap->addPrimaryKey("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType() ?>", CreoleTypes::<?php echo $col->getType() ?>, <?php echo $col->isNotNull() ? 'true' : 'false' ?>, <?php echo $size ?>);
<?php }
} else {
if($col->isForeignKey()) { ?>
$tMap->addForeignKey("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType()?>", CreoleTypes::<?php echo $col->getType() ?>, "<?php echo $col->getRelatedTableName() ?>" , "<?php echo strtoupper($col->getRelatedColumnName()) ?>", <?php echo $col->isNotNull() ? 'true' : 'false' ?>, <?php echo $size ?>);
<?php } else { ?>
$tMap->addColumn("<?php echo $cup ?>", "<?php echo $cfc?>", "<?php echo $col->getPhpType()?>", CreoleTypes::<?php echo $col->getType() ?>, <?php echo $col->isNotNull() ? 'true' : 'false' ?>, <?php echo $size ?>);
<?php }
} // if col-is prim key
} // foreach
foreach($table->getValidators() as $val) {
$col = $val->getColumn();
$cup = strtoupper($col->getName());
foreach($val->getRules() as $rule) {
if ($val->getTranslate() !== Validator::TRANSLATE_NONE) {
?>
$tMap->addValidator("<?php echo $cup ?>", "<?php echo $rule->getName() ?>", "<?php echo $rule->getClass() ?>", "<?php echo $rule->getValue()?>", <?php echo $val->getTranslate() ?>("<?php echo str_replace('"', '\"', $rule->getMessage()) ?>"));
<?php } else { ?>
$tMap->addValidator("<?php echo $cup ?>", "<?php echo $rule->getName() ?>", "<?php echo $rule->getClass() ?>", "<?php echo $rule->getValue()?>", "<?php echo str_replace('"', '\"', $rule->getMessage()) ?>");
<?php
} // if ($rule->getTranslation() ...
} // foreach validator
}
?>
}
}

View File

@ -0,0 +1,60 @@
<?php
// Create empty stub subclass which extends the parent stub om class created in ExtensionObject.tpl.
//
// $Id: MultiExtendObject.tpl,v 1.2 2004/10/06 16:54:47 hlellelid Exp $
echo '<' . '?' . 'php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
$packagePath = strtr($package, '.', '/');
if ($packagePath != "") $packagePath .= '/';
if ($child->getAncestor()) {
$parent = $child->getAncestor();
?>
require_once '<?php echo strtr($parent, '.', '/') ?>.php';
<?php
$parts = explode('.', $parent);
$parentClass = array_pop($parts);
} else {
$parentClass = $table->getPhpName();
?>
require_once '<?php echo $packagePath . $parentClass ?>.php';
<?php
}
?>
/**
<?php if ($addTimeStamp) { ?>
* The skeleton for this class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* 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.
*/
class <?php echo $child->getClassName()?> extends <?php echo $parentClass ?> {
public function __construct()
{ <?php
$col = $child->getColumn();
$cfc=$col->getPhpName();
$table = $col->getTable();
?>
$this->set<?php echo $cfc ?>(<?php echo $table->getPhpName() ?>Peer::CLASSKEY_<?php echo strtoupper($child->getKey()) ?>);
}
}

View File

@ -0,0 +1,801 @@
<?php
// Template for creating base node class on tree table.
//
// $Id: Node.tpl,v 1.6 2005/04/04 10:48:33 dlawson_mi Exp $
require_once 'propel/engine/builder/om/ClassTools.php';
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
echo '<' . '?' . 'php';
?>
require_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName() . 'NodePeer') ?>';
/**
* Base tree node class for manipulating a tree of <?php echo $table->getPhpName() ?> objects.
* This class will wrap these objects within a "node" interface. It provides a
* method overload mechanism which allows you to use a <?php echo $table->getPhpName() ?>Node
* object just like a <?php $table->getPhpName() ?> object.
*
* To avoid tree corruption, you should always use this class to make changes to
* the tree and objects within it rather than using the <?php echo $table->getPhpName() ?>
* class directly.
*
<?php if (isset($addTimeStamp)) { ?>
* This class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* @package <?php echo $package ?>
*
*/
class <?php echo $basePrefix . $table->getPhpName() ?>Node implements IteratorAggregate
{
/**
* @var <?php echo $table->getPhpName() ?> Object wrapped by this node.
*/
protected $obj = null;
/**
* The parent node for this node.
* @var <?php echo $table->getPhpName() ?>Node
*/
protected $parentNode = null;
/**
* Array of child nodes for this node. Nodes indexes are one-based.
* @var array
*/
protected $childNodes = array();
/**
* Constructor.
*
* @param <?php echo $table->getPhpName() ?> Object wrapped by this node.
*/
public function __construct($obj = null)
{
if ($obj !== null)
{
$this->obj = $obj;
}
else
{
$setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME;
$this->obj = new <?php echo $table->getPhpName() ?>();
$this->obj->$setNodePath('0');
}
}
/**
* Convenience overload for wrapped object methods.
*
* @param string Method name to call on wrapped object.
* @param mixed Parameter accepted by wrapped object set method.
* @return mixed Return value of wrapped object method.
* @throws PropelException Fails if method is not defined for wrapped object.
*/
public function __call($name, $parms)
{
if (method_exists($this->obj, $name))
return call_user_func_array(array($this->obj, $name), $parms);
else
throw new PropelException("get method not defined: $name");
}
/**
* Sets the default options for iterators created from this object.
* The options are specified in map format. The following options
* are supported by all iterators. Some iterators may support other
* options:
*
* "querydb" - True if nodes should be retrieved from database.
* "con" - Connection to use if retrieving from database.
*
* @param string Type of iterator to use ("pre", "post", "level").
* @param array Map of option name => value.
* @return void
* @todo Implement other iterator types (i.e. post-order, level, etc.)
*/
public function setIteratorOptions($type, $opts)
{
$this->itType = $type;
$this->itOpts = $opts;
}
/**
* Returns a pre-order iterator for this node and its children.
*
* @param string Type of iterator to use ("pre", "post", "level")
* @param array Map of option name => value.
* @return NodeIterator
*/
public function getIterator($type = null, $opts = null)
{
if ($type === null)
$type = (isset($this->itType) ? $this->itType : 'Pre');
if ($opts === null)
$opts = (isset($this->itOpts) ? $this->itOpts : array());
$itclass = ucfirst(strtolower($type)) . 'OrderNodeIterator';
require_once('propel/om/' . $itclass . '.php');
return new $itclass($this, $opts);
}
/**
* Returns the object wrapped by this class.
* @return <?php echo $table->getPhpName() . "\n" ?>
*/
public function getNodeObj()
{
return $this->obj;
}
/**
* Convenience method for retrieving nodepath.
* @return string
*/
public function getNodePath()
{
$getNodePath = 'get' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME;
return $this->obj->$getNodePath();
}
/**
* Returns one-based node index among siblings.
* @return int
*/
public function getNodeIndex()
{
$npath =& $this->getNodePath();
$sep = strrpos($npath, <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP);
return (int) ($sep !== false ? substr($npath, $sep+1) : $npath);
}
/**
* Returns one-based node level within tree (root node is level 1).
* @return int
*/
public function getNodeLevel()
{
return (substr_count($this->getNodePath(), <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP) + 1);
}
/**
* Returns true if specified node is a child of this node. If recurse is
* true, checks if specified node is a descendant of this node.
*
* @param <?php echo $table->getPhpName() ?>Node Node to look for.
* @param boolean True if strict comparison should be used.
* @param boolean True if all descendants should be checked.
* @return boolean
*/
public function hasChildNode($node, $strict = false, $recurse = false)
{
foreach ($this->childNodes as $childNode)
{
if ($childNode->equals($node, $strict))
return true;
if ($recurse && $childNode->hasChildNode($node, $recurse))
return true;
}
return false;
}
/**
* Returns child node at one-based index. Retrieves from database if not
* loaded yet.
*
* @param int One-based child node index.
* @param boolean True if child should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
public function getChildNodeAt($i, $querydb = false, $con = null)
{
if ($querydb &&
!$this->obj->isNew() &&
!$this->obj->isDeleted() &&
!isset($this->childNodes[$i]))
{
$criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $i, Criteria::EQUAL);
if ($childObj = <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, $con))
$this->attachChildNode(new <?php echo $table->getPhpName() ?>Node($childObj));
}
return (isset($this->childNodes[$i]) ? $this->childNodes[$i] : null);
}
/**
* Returns first child node (if any). Retrieves from database if not loaded yet.
*
* @param boolean True if child should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
public function getFirstChildNode($querydb = false, $con = null)
{
return $this->getChildNodeAt(1, $querydb, $con);
}
/**
* Returns last child node (if any).
*
* @param boolean True if child should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
*/
public function getLastChildNode($querydb = false, $con = null)
{
$lastNode = null;
if ($this->obj->isNew() || $this->obj->isDeleted())
{
end($this->childNodes);
$lastNode = (count($this->childNodes) ? current($this->childNodes) : null);
}
else if ($querydb)
{
$db = Propel::getDb(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
$criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . '%', Criteria::LIKE);
$criteria->addAnd(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . '%' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . '%', Criteria::NOT_LIKE);
$criteria->addAsColumn('npathlen', $db->strLength(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME));
$criteria->addDescendingOrderByColumn('npathlen');
$criteria->addDescendingOrderByColumn(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME);
$lastObj = <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, $con);
if ($lastObj !== null)
{
$lastNode = new <?php echo $table->getPhpName() ?>Node($lastObj);
end($this->childNodes);
$endNode = (count($this->childNodes) ? current($this->childNodes) : null);
if ($endNode)
{
if ($endNode->getNodePath() > $lastNode->getNodePath())
throw new PropelException('Cached child node inconsistent with database.');
else if ($endNode->getNodePath() == $lastNode->getNodePath())
$lastNode = $endNode;
else
$this->attachChildNode($lastNode);
}
else
{
$this->attachChildNode($lastNode);
}
}
}
return $lastNode;
}
/**
* Returns next (or previous) sibling node or null. Retrieves from database if
* not loaded yet.
*
* @param boolean True if previous sibling should be returned.
* @param boolean True if sibling should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
public function getSiblingNode($prev = false, $querydb = false, $con = null)
{
$nidx = $this->getNodeIndex();
if ($this->isRootNode())
{
return null;
}
else if ($prev)
{
if ($nidx > 1 && ($parentNode = $this->getParentNode($querydb, $con)))
return $parentNode->getChildNodeAt($nidx-1, $querydb, $con);
else
return null;
}
else
{
if ($parentNode = $this->getParentNode($querydb, $con))
return $parentNode->getChildNodeAt($nidx+1, $querydb, $con);
else
return null;
}
}
/**
* Returns parent node. Loads from database if not cached yet.
*
* @param boolean True if parent should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return <?php echo $table->getPhpName() ?>Node
*/
public function getParentNode($querydb = true, $con = null)
{
if ($querydb &&
$this->parentNode === null &&
!$this->isRootNode() &&
!$this->obj->isNew() &&
!$this->obj->isDeleted())
{
$npath =& $this->getNodePath();
$sep = strrpos($npath, <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP);
$ppath = substr($npath, 0, $sep);
$criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
$criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $ppath, Criteria::EQUAL);
if ($parentObj = <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, $con))
{
$parentNode = new <?php echo $table->getPhpName() ?>Node($parentObj);
$parentNode->attachChildNode($this);
}
}
return $this->parentNode;
}
/**
* Returns an array of all ancestor nodes, starting with the root node
* first.
*
* @param boolean True if ancestors should be retrieved from database.
* @param Connection Connection to use if retrieving from database.
* @return array
*/
public function getAncestors($querydb = false, $con = null)
{
$ancestors = array();
$parentNode = $this;
while ($parentNode = $parentNode->getParentNode($querydb, $con))
array_unshift($ancestors, $parentNode);
return $ancestors;
}
/**
* Returns true if node is the root node of the tree.
* @return boolean
*/
public function isRootNode()
{
return ($this->getNodePath() === '1');
}
/**
* Changes the state of the object and its descendants to 'new'.
* Also changes the node path to '0' to indicate that it is not a
* stored node.
*
* @param boolean
* @return void
*/
public function setNew($b)
{
$this->adjustStatus('new', $b);
$this->adjustNodePath($this->getNodePath(), '0');
}
/**
* Changes the state of the object and its descendants to 'deleted'.
*
* @param boolean
* @return void
*/
public function setDeleted($b)
{
$this->adjustStatus('deleted', $b);
}
/**
* Adds the specified node (and its children) as a child to this node. If a
* valid $beforeNode is specified, the node will be inserted in front of
* $beforeNode. If $beforeNode is not specified the node will be appended to
* the end of the child nodes.
*
* @param <?php echo $table->getPhpName() ?>Node Node to add.
* @param <?php echo $table->getPhpName() ?>Node Node to insert before.
* @param Connection Connection to use.
*/
public function addChildNode($node, $beforeNode = null, $con = null)
{
if ($this->obj->isNew() && !$node->obj->isNew())
throw new PropelException('Cannot add stored nodes to a new node.');
if ($this->obj->isDeleted() || $node->obj->isDeleted())
throw new PropelException('Cannot add children in a deleted state.');
if ($this->hasChildNode($node))
throw new PropelException('Node is already a child of this node.');
if ($beforeNode && !$this->hasChildNode($beforeNode))
throw new PropelException('Invalid beforeNode.');
if ($con === null)
$con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
try {
if (!$this->obj->isNew()) $con->begin();
if ($beforeNode)
{
// Inserting before a node.
$childIdx = $beforeNode->getNodeIndex();
$this->shiftChildNodes(1, $beforeNode->getNodeIndex(), $con);
}
else
{
// Appending child node.
if ($lastNode = $this->getLastChildNode(true, $con))
$childIdx = $lastNode->getNodeIndex()+1;
else
$childIdx = 1;
}
// Add the child (and its children) at the specified index.
if (!$this->obj->isNew() && $node->obj->isNew())
{
$this->insertNewChildNode($node, $childIdx, $con);
}
else
{
// $this->isNew() && $node->isNew() ||
// !$this->isNew() && !node->isNew()
$srcPath = $node->getNodePath();
$dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $childIdx;
if (!$node->obj->isNew())
{
<?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree($srcPath, $dstPath, $con);
$parentNode = $node->getParentNode(true, $con);
}
else
{
$parentNode = $node->getParentNode();
}
if ($parentNode)
{
$parentNode->detachChildNode($node);
$parentNode->shiftChildNodes(-1, $node->getNodeIndex()+1, $con);
}
$node->adjustNodePath($srcPath, $dstPath);
}
if (!$this->obj->isNew()) $con->commit();
$this->attachChildNode($node);
} catch (SQLException $e) {
if (!$this->obj->isNew()) $con->rollback();
throw new PropelException($e);
}
}
/**
* Moves the specified child node in the specified direction.
*
* @param <?php $table->getPhpName() ?>Node Node to move.
* @param int Number of spaces to move among siblings (may be negative).
* @param Connection Connection to use.
* @throws PropelException
*/
public function moveChildNode($node, $direction, $con = null)
{
throw new PropelException('moveChildNode() not implemented yet.');
}
/**
* Saves modified object data to the datastore.
*
* @param boolean If true, descendants will be saved as well.
* @param Connection Connection to use.
*/
public function save($recurse = false, $con = null)
{
if ($this->obj->isDeleted())
throw new PropelException('Cannot save deleted node.');
if (substr($this->getNodePath(), 0, 1) == '0')
throw new PropelException('Cannot save unattached node.');
if ($this->obj->isColumnModified(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME))
throw new PropelException('Cannot save manually modified node path.');
$this->obj->save($con);
if ($recurse)
{
foreach ($this->childNodes as $childNode)
$childNode->save($recurse, $con);
}
}
/**
* Removes this object and all descendants from datastore.
*
* @param Connection Connection to use.
* @return void
* @throws PropelException
*/
public function delete($con = null)
{
if ($this->obj->isDeleted())
throw new PropelException('This node has already been deleted.');
if (!$this->obj->isNew())
{
<?php echo $table->getPhpName() ?>NodePeer::deleteNodeSubTree($this->getNodePath(), $con);
}
if ($parentNode = $this->getParentNode(true, $con))
{
$parentNode->detachChildNode($this);
$parentNode->shiftChildNodes(-1, $this->getNodeIndex()+1, $con);
}
$this->setDeleted(true);
}
/**
* Compares the object wrapped by this node with that of another node. Use
* this instead of equality operators to prevent recursive dependency
* errors.
*
* @param <?php echo $table->getPhpName() ?>Node Node to compare.
* @param boolean True if strict comparison should be used.
* @return boolean
*/
public function equals($node, $strict = false)
{
if ($strict)
return ($this->obj === $node->obj);
else
return ($this->obj == $node->obj);
}
/**
* This method is used internally when constructing the tree structure
* from the database. To set the parent of a node, you should call
* addChildNode() on the parent.
*
* @param <?php echo $table->getPhpName() ?>Node Parent node to attach.
* @return void
* @throws PropelException
*/
public function attachParentNode($node)
{
if (!$node->hasChildNode($this, true))
throw new PropelException('Failed to attach parent node for non-child.');
$this->parentNode = $node;
}
/**
* This method is used internally when constructing the tree structure
* from the database. To add a child to a node you should call the
* addChildNode() method instead.
*
* @param <?php echo $table->getPhpName() ?>Node Child node to attach.
* @return void
* @throws PropelException
*/
public function attachChildNode($node)
{
if ($this->hasChildNode($node))
throw new PropelException('Failed to attach child node. Node already exists.');
if ($this->obj->isDeleted() || $node->obj->isDeleted())
throw new PropelException('Failed to attach node in deleted state.');
if ($this->obj->isNew() && !$node->obj->isNew())
throw new PropelException('Failed to attach non-new child to new node.');
if (!$this->obj->isNew() && $node->obj->isNew())
throw new PropelException('Failed to attach new child to non-new node.');
if ($this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $node->getNodeIndex() != $node->getNodePath())
throw new PropelException('Failed to attach child node. Node path mismatch.');
$this->childNodes[$node->getNodeIndex()] = $node;
ksort($this->childNodes);
$node->attachParentNode($this);
}
/**
* This method is used internally when deleting nodes. It is used to break
* the link to this node's parent.
* @param <?php echo $table->getPhpName() ?>Node Parent node to detach from.
* @return void
* @throws PropelException
*/
public function detachParentNode($node)
{
if (!$node->hasChildNode($this, true))
throw new PropelException('Failed to detach parent node from non-child.');
unset($node->childNodes[$this->getNodeIndex()]);
$this->parentNode = null;
}
/**
* This method is used internally when deleting nodes. It is used to break
* the link to this between this node and the specified child.
* @param <?php echo $table->getPhpName() ?>Node Child node to detach.
* @return void
* @throws PropelException
*/
public function detachChildNode($node)
{
if (!$this->hasChildNode($node, true))
throw new PropelException('Failed to detach non-existent child node.');
unset($this->childNodes[$node->getNodeIndex()]);
$node->parentNode = null;
}
/**
* Shifts child nodes in the specified direction and offset index. This
* method assumes that there is already space available in the
* direction/offset indicated.
*
* @param int Direction/# spaces to shift. 1=leftshift, 1=rightshift
* @param int Node index to start shift at.
* @param Connection The connection to be used.
* @return void
* @throws PropelException
*/
protected function shiftChildNodes($direction, $offsetIdx, $con)
{
if ($this->obj->isDeleted())
throw new PropelException('Cannot shift nodes for deleted object');
$lastNode = $this->getLastChildNode(true, $con);
$lastIdx = ($lastNode !== null ? $lastNode->getNodeIndex() : 0);
if ($lastNode === null || $offsetIdx > $lastIdx)
return;
if ($con === null)
$con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
if (!$this->obj->isNew())
{
// Shift nodes in database.
try {
$con->begin();
$n = $lastIdx - $offsetIdx + 1;
$i = $direction < 1 ? $offsetIdx : $lastIdx;
while ($n--)
{
$srcPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $i; // 1.2.2
$dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . ($i+$direction); // 1.2.3
<?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree($srcPath, $dstPath, $con);
$i -= $direction;
}
$con->commit();
} catch (SQLException $e) {
$con->rollback();
throw new PropelException($e);
}
}
// Shift the in-memory objects.
$n = $lastIdx - $offsetIdx + 1;
$i = $direction < 1 ? $offsetIdx : $lastIdx;
while ($n--)
{
if (isset($this->childNodes[$i]))
{
$srcPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $i; // 1.2.2
$dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . ($i+$direction); // 1.2.3
$this->childNodes[$i+$direction] = $this->childNodes[$i];
$this->childNodes[$i+$direction]->adjustNodePath($srcPath, $dstPath);
unset($this->childNodes[$i]);
}
$i -= $direction;
}
ksort($this->childNodes);
}
/**
* Inserts the node and its children at the specified childIdx.
*
* @param <?php echo $table->getPhpName() ?>Node Node to insert.
* @param int One-based child index to insert at.
* @param Connection Connection to use.
* @param void
*/
protected function insertNewChildNode($node, $childIdx, $con)
{
if (!$node->obj->isNew())
throw new PropelException('Failed to insert non-new node.');
$setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME;
$node->obj->$setNodePath($this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $childIdx);
$node->obj->save($con);
$i = 1;
foreach ($node->childNodes as $childNode)
$node->insertNewChildNode($childNode, $i++, $con);
}
/**
* Adjust new/deleted status of node and all children.
*
* @param string Status to change ('New' or 'Deleted')
* @param boolean Value for status.
* @return void
*/
protected function adjustStatus($status, $b)
{
$setStatus = 'set' . $status;
$this->obj->$setStatus($b);
foreach ($this->childNodes as $childNode)
$childNode->obj->$setStatus($b);
}
/**
* Adjust path of node and all children. This is used internally when
* inserting/moving nodes.
*
* @param string Section of old path to change.
* @param string New section to replace old path with.
* @return void
*/
protected function adjustNodePath($oldBasePath, $newBasePath)
{
$setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME;
$this->obj->$setNodePath($newBasePath .
substr($this->getNodePath(), strlen($oldBasePath)));
$this->obj->resetModified(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME);
foreach ($this->childNodes as $childNode)
$childNode->adjustNodePath($oldBasePath, $newBasePath);
}
}
?>

View File

@ -0,0 +1,522 @@
<?php
// Template for creating base node Peer class on tree table.
//
// $Id: NodePeer.tpl,v 1.6 2004/11/24 13:09:52 kasparsj Exp $
require_once 'propel/engine/builder/om/ClassTools.php';
require_once 'propel/engine/builder/om/PeerBuilder.php';
$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;
}
}
$db = $table->getDatabase();
if($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $targetPackage;
}
echo '<' . '?' . 'php';
?>
require_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName()) ?>';
require_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName() . 'Node') ?>';
/**
* Base static class for performing query operations on the tree contained by the
* '<?php echo $table->getPhpName() ?>' table.
*
<?php if ($addTimeStamp) { ?>
* This class was autogenerated by Propel on:
*
* [<?php echo $now ?>]
*
<?php } ?>
* @package <?php echo $package ?>
*/
class <?php echo $basePrefix . $table->getPhpName() ?>NodePeer
{
const NPATH_COLNAME = '<?php echo $npath_colname ?>';
const NPATH_PHPNAME = '<?php echo $npath_phpname ?>';
const NPATH_SEP = '<?php echo $npath_sep ?>';
/**
* Temp function for CodeBase hacks that will go away.
*/
public static function isCodeBase($con = null)
{
if ($con === null)
$con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
return (get_class($con) == 'ODBCConnection' &&
get_class($con->getAdapter()) == 'CodeBaseAdapter');
}
/**
* 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 <?php echo $table->getPhpName() ?> Object wrapped by new node.
* @param Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
* @throws PropelException
*/
public static function createNewRootNode($obj, $con = null)
{
if ($con === null)
$con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
try {
$con->begin();
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 <?php echo $table->getPhpName() ?>Node($obj);
}
/**
* 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 <?php echo $table->getPhpName() ?> Object wrapped by new node.
* @param Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
* @throws PropelException
*/
public static function insertNewRootNode($obj, $con = null)
{
if ($con === null)
$con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
try {
$con->begin();
// Move root tree to an invalid node path.
self::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.
self::moveNodeSubTree('0', '1' . self::NPATH_SEP . '1', $con);
$con->commit();
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
return new <?php echo $table->getPhpName() ?>Node($obj);
}
/**
* 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 Connection Connection to use.
* @return array Array of root nodes.
*/
public static function retrieveNodes($criteria, $ancestors = false, $descendants = false, $con = null)
{
$criteria = self::buildFamilyCriteria($criteria, $ancestors, $descendants);
$rs = <?php echo $table->getPhpName() ?>Peer::doSelectRS($criteria, $con);
return self::populateNodes($rs, $criteria);
}
/**
* Retrieves a tree node based on a primary key. Optionally includes all
* parent and/or child nodes of the matching node.
*
* @param mixed <?php echo $table->getPhpName() ?> 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 Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
*/
public static function retrieveNodeByPK($pk, $ancestors = false, $descendants = false, $con = null)
{
throw new PropelException('retrieveNodeByPK() not implemented yet.');
}
/**
* 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 Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
*/
public static function retrieveNodeByNP($np, $ancestors = false, $descendants = false, $con = null)
{
$criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
$criteria->add(self::NPATH_COLNAME, $np, Criteria::EQUAL);
$criteria = self::buildFamilyCriteria($criteria, $ancestors, $descendants);
$rs = <?php echo $table->getPhpName() ?>Peer::doSelectRS($criteria, $con);
$nodes = self::populateNodes($rs, $criteria);
return (count($nodes) == 1 ? $nodes[0] : null);
}
/**
* Retrieves the root node.
*
* @param string Node path to retrieve.
* @param boolean True if descendants should also be retrieved.
* @param Connection Connection to use.
* @return <?php echo $table->getPhpName() ?>Node
*/
public static function retrieveRootNode($descendants = false, $con = null)
{
return self::retrieveNodeByNP('1', false, $descendants, $con);
}
/**
* 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 Connection 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, $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(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
/**
* Example:
* UPDATE table
* SET npath = CONCAT('1.3', SUBSTRING(npath, 6, 74))
* WHERE npath = '1.2.2' OR npath LIKE '1.2.2.%'
*/
$npath = self::NPATH_COLNAME;
//the following dot isn`t mean`t a nodeKeySeperator
$setcol = substr($npath, strpos($npath, '.')+1);
$setcollen = <?php echo $npath_len ?>;
$db = Propel::getDb(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
// <hack>
if (<?php echo $table->getPhpName() ?>NodePeer::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 " . <?php echo $table->getPhpName() ?>Peer::TABLE_NAME . " " .
"SET $setcol=" . $db->concatString("'$dstPath'", $db->subString($npath, strlen($srcPath)+1, $setcollen)) . " " .
"WHERE $npath = '$srcPath' OR $npath LIKE '" . $srcPath . self::NPATH_SEP . "%'";
$con->executeUpdate($sql);
}
else
{
// </hack>
$sql = "UPDATE " . <?php echo $table->getPhpName() ?>Peer::TABLE_NAME . " " .
"SET $setcol=" . $db->concatString('?', $db->subString($npath, '?', '?')) . " " .
"WHERE $npath = ? OR $npath LIKE ?";
$stmt = $con->prepareStatement($sql);
$stmt->setString(1, $dstPath);
$stmt->setInt(2, strlen($srcPath)+1);
$stmt->setInt(3, $setcollen);
$stmt->setString(4, $srcPath);
$stmt->setString(5, $srcPath . self::NPATH_SEP . '%');
$stmt->executeUpdate();
// <hack>
}
// </hack>
}
/**
* Deletes the node subtree at the specified node path from the database.
*
* @param string Node path to delete
* @param Connection Connection to use.
* @return void
* @throws PropelException
* @todo This is currently broken for simulated "onCascadeDelete"s.
*/
public static function deleteNodeSubTree($nodePath, $con = null)
{
if ($con === null)
$con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
/**
* DELETE FROM table
* WHERE npath = '1.2.2' OR npath LIKE '1.2.2.%'
*/
$criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME);
$criteria->add(self::NPATH_COLNAME, $nodePath, Criteria::EQUAL);
$criteria->addOr(self::NPATH_COLNAME, $nodePath . self::NPATH_SEP . '%', Criteria::LIKE);
// For now, we call BasePeer directly since <?php echo $table->getPhpName() ?>Peer tries to
// do a cascade delete.
// <?php echo $table->getPhpName() ?>Peer::doDelete($criteria, $con);
BasePeer::doDelete($criteria, $con);
}
/**
* 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(<?php echo $table->getPhpName() ?>::DATABASE_NAME);
if (!$criteria->getSelectColumns())
<?php echo $table->getPhpName() ?>Peer::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', <?php echo $table->getPhpName() ?>Peer::TABLE_NAME);
// Make sure we have select columns to begin with.
if (!$criteria->getSelectColumns())
<?php echo $table->getPhpName() ?>Peer::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(<?php echo $table->getPhpName() ?>Peer::TABLE_NAME, 'L', $colName));
$a = null;
$d = null;
$npathL = <?php echo $table->getPhpName() ?>Peer::alias('L', self::NPATH_COLNAME);
$npathR = self::NPATH_COLNAME;
$npath_len = <?php echo $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(self::NPATH_COLNAME);
// Sort by node path to speed up tree construction in populateNodes()
$criteria->addAsColumn('npathlen', $db->strLength(self::NPATH_COLNAME));
$criteria->addAscendingOrderByColumn('npathlen');
$criteria->addAscendingOrderByColumn(self::NPATH_COLNAME);
}
return $criteria;
}
/**
* 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 <?php echo $table->getPhpName() ?>Node methods of the
* subtree root nodes.
*
* @param array Array of <?php echo $table->getPhpName() ?>Node objects
* @return array Array of <?php echo $table->getPhpName() ?>Node 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(), self::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;
}
/**
* Populates the <?php echo $table->getPhpName() ?> objects from the
* specified ResultSet, wraps them in <?php echo $table->getPhpName() ?>Node
* 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 ResultSet
* @param Criteria
* @return array Array of <?php $table->getPhpName() ?>Node objects.
*/
public static function populateNodes($rs, $criteria)
{
$nodes = array();
$targets = array();
$targetfld = count($criteria->getSelectColumns());
<?php if (!$table->getChildrenColumn()) { ?>
// set the class once to avoid overhead in the loop
$cls = Propel::import(<?php echo $table->getPhpName() ?>Peer::getOMClass());
<?php } ?>
// populate the object(s)
while($rs->next())
{
if (!isset($nodes[$rs->getString(1)]))
{
<?php if ($table->getChildrenColumn()) { ?>
// class must be set each time from the record row
$cls = Propel::import(<?php echo $table->getPhpName() ?>Peer::getOMClass($rs, 1));
<?php } ?>
$obj = new $cls();
$obj->hydrate($rs);
$nodes[$rs->getString(1)] = new <?php echo $table->getPhpName() ?>Node($obj);
}
$node = $nodes[$rs->getString(1)];
if ($node->getNodePath() == $rs->getString($targetfld))
$targets[$node->getNodePath()] = $node;
}
self::buildTree($nodes);
return array_values($targets);
}
}
?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff