1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-05-01 08:29:22 +03:00

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

View file

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