Merge commit 'b22faa8' from maz0717

Conflicts:
	src/NestedSetsBehavior.php
This commit is contained in:
Alexander Yakovlev 2016-02-15 13:36:26 +07:00
commit a5ed820083
1 changed files with 20 additions and 2 deletions

View File

@ -249,6 +249,24 @@ class NestedSetsBehavior extends Behavior
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
}
public function subtree($depth = null)
{
$condition = [
'and',
['>=', $this->leftAttribute, $this->owner->getAttribute($this->leftAttribute)],
['<=', $this->rightAttribute, $this->owner->getAttribute($this->rightAttribute)],
];
if ($depth !== null) {
$condition[] = ['<=', $this->depthAttribute, $this->owner->getAttribute($this->depthAttribute) + $depth];
}
$this->applyTreeAttributeCondition($condition);
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
}
/**
* Gets the leaves of the node.
* @return \yii\db\ActiveQuery
@ -509,7 +527,7 @@ class NestedSetsBehavior extends Behavior
* @param AfterSaveEvent $event
* @return void
*/
protected function moveNodeAsRoot($event)
public function moveNodeAsRoot($event)
{
$db = $this->owner->getDb();
$leftValue = $this->owner->getAttribute($this->leftAttribute);
@ -542,7 +560,7 @@ class NestedSetsBehavior extends Behavior
* @param integer $value
* @param integer $depth
*/
protected function moveNode($value, $depth)
public function moveNode($value, $depth)
{
$db = $this->owner->getDb();
$leftValue = $this->owner->getAttribute($this->leftAttribute);