1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-06-17 07:10:46 +03:00

Added NestedSetsBehavior::leaves feature

This commit is contained in:
Alexander Kochetov 2015-01-08 23:28:33 +03:00
parent c5cde0e6da
commit 42d25ce72a

View file

@ -247,6 +247,24 @@ class NestedSetsBehavior extends Behavior
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
}
/**
* Gets the leaves of the node.
* @return \yii\db\ActiveQuery
*/
public function leaves()
{
$condition = [
'and',
['>', $this->leftAttribute, $this->owner->getAttribute($this->leftAttribute)],
['<', $this->rightAttribute, $this->owner->getAttribute($this->rightAttribute)],
[$this->rightAttribute => new Expression($this->owner->getDb()->quoteColumnName($this->leftAttribute) . '+ 1')],
];
$this->applyTreeAttributeCondition($condition);
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
}
/**
* Gets the previous sibling of the node.
* @return \yii\db\ActiveQuery