Skip to content

Commit

Permalink
[Generator] [NestedSet] More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Jan 12, 2013
1 parent bf67367 commit d6dd037
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 127 deletions.
33 changes: 0 additions & 33 deletions src/Propel/Generator/Behavior/NestedSet/NestedSetBehavior.php
Expand Up @@ -96,37 +96,4 @@ public function getColumnConstant($columnName, $builder)
{
return $builder->getColumnConstant($this->getColumnForParameter($columnName));
}

public function staticAttributes($builder)
{
$tableName = $this->table->getName();

$script = "
/**
* Left column for the set
*/
const LEFT_COL = '" . $tableName . '.' . $this->getColumnConstant('left_column', $builder) . "';
/**
* Right column for the set
*/
const RIGHT_COL = '" . $tableName . '.' . $this->getColumnConstant('right_column', $builder) . "';
/**
* Level column for the set
*/
const LEVEL_COL = '" . $tableName . '.' . $this->getColumnConstant('level_column', $builder) . "';
";

if ($this->useScope()) {
$script .= "
/**
* Scope column for the set
*/
const SCOPE_COL = '" . $tableName . '.' . $this->getColumnConstant('scope_column', $builder) . "';
";
}

return $script;
}
}
Expand Up @@ -52,32 +52,6 @@ protected function setBuilder($builder)
$this->builder = $builder;
}

public function objectAttributes($builder)
{
$objectClassName = $builder->getObjectClassName();

return "
/**
* Queries to be executed in the save transaction
* @var array
*/
protected \$nestedSetQueries = array();
/**
* Internal cache for children nodes
* @var null|ObjectCollection
*/
protected \$collNestedSetChildren = null;
/**
* Internal cache for parent node
* @var null|$objectClassName
*/
protected \$aNestedSetParent = null;
";
}

public function preSave($builder)
{
$queryClassName = $builder->getQueryClassName();
Expand Down Expand Up @@ -165,7 +139,7 @@ public function objectMethods($builder)
}

if ('LeftValue' !== $this->getColumnPhpName('left_column')) {
$script += $this->addSetLeft();
$script .= $this->addSetLeft();
}
if ('RightValue' !== $this->getColumnPhpName('right_column')) {
$this->addSetRight($script);
Expand Down Expand Up @@ -215,7 +189,7 @@ public function objectMethods($builder)
$this->addAddChild($script);
$this->addInsertAsFirstChildOf($script);

$script += $this->addInsertAsLastChildOf();
$script .= $this->addInsertAsLastChildOf();

$this->addInsertAsPrevSiblingOf($script);
$this->addInsertAsNextSiblingOf($script);
Expand All @@ -232,7 +206,7 @@ public function objectMethods($builder)
'\Propel\Runtime\ActiveRecord\NestedSetRecursiveIterator'
);

$script += $this->addGetIterator();
$script .= $this->addGetIterator();

return $script;
}
Expand Down Expand Up @@ -1054,11 +1028,13 @@ public function insertAsFirstChildOf(\$parent)
\$this->setLeftValue(\$left);
\$this->setRightValue(\$left + 1);
\$this->setLevel(\$parent->getLevel() + 1);";

if ($useScope) {
$script .= "
\$scope = \$parent->getScopeValue();
\$this->setScopeValue(\$scope);";
}

$script .= "
// update the children collection of the parent
\$parent->addNestedSetChild(\$this);
Expand Down Expand Up @@ -1449,6 +1425,58 @@ public function deleteDescendants(ConnectionInterface \$con = null)
";
}

public function objectAttributes($builder)
{
$tableName = $this->table->getName();
$objectClassName = $builder->getObjectClassName();

$script = "
/**
* Queries to be executed in the save transaction
* @var array
*/
protected \$nestedSetQueries = array();
/**
* Internal cache for children nodes
* @var null|ObjectCollection
*/
protected \$collNestedSetChildren = null;
/**
* Internal cache for parent node
* @var null|$objectClassName
*/
protected \$aNestedSetParent = null;
/**
* Left column for the set
*/
const LEFT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('left_column', $builder) . "';
/**
* Right column for the set
*/
const RIGHT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('right_column', $builder) . "';
/**
* Level column for the set
*/
const LEVEL_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('level_column', $builder) . "';
";

if ($this->behavior->useScope()) {
$script .= "
/**
* Scope column for the set
*/
const SCOPE_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('scope_column', $builder) . "';
";
}

return $script;
}

protected function addGetIterator()
{
return $this->behavior->renderTemplate('objectGetIterator');
Expand Down

0 comments on commit d6dd037

Please sign in to comment.