|
@@ 211-226 (lines=16) @@
|
| 208 |
|
* @param integer|null $depth the depth |
| 209 |
|
* @return \yii\db\ActiveQuery |
| 210 |
|
*/ |
| 211 |
|
public function parents($depth = null) |
| 212 |
|
{ |
| 213 |
|
$condition = [ |
| 214 |
|
'and', |
| 215 |
|
['<', $this->leftAttribute, $this->owner->getAttribute($this->leftAttribute)], |
| 216 |
|
['>', $this->rightAttribute, $this->owner->getAttribute($this->rightAttribute)], |
| 217 |
|
]; |
| 218 |
|
|
| 219 |
|
if ($depth !== null) { |
| 220 |
|
$condition[] = ['>=', $this->depthAttribute, $this->owner->getAttribute($this->depthAttribute) - $depth]; |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
$this->applyTreeAttributeCondition($condition); |
| 224 |
|
|
| 225 |
|
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
/** |
| 229 |
|
* Gets the children of the node. |
|
@@ 233-248 (lines=16) @@
|
| 230 |
|
* @param integer|null $depth the depth |
| 231 |
|
* @return \yii\db\ActiveQuery |
| 232 |
|
*/ |
| 233 |
|
public function children($depth = null) |
| 234 |
|
{ |
| 235 |
|
$condition = [ |
| 236 |
|
'and', |
| 237 |
|
['>', $this->leftAttribute, $this->owner->getAttribute($this->leftAttribute)], |
| 238 |
|
['<', $this->rightAttribute, $this->owner->getAttribute($this->rightAttribute)], |
| 239 |
|
]; |
| 240 |
|
|
| 241 |
|
if ($depth !== null) { |
| 242 |
|
$condition[] = ['<=', $this->depthAttribute, $this->owner->getAttribute($this->depthAttribute) + $depth]; |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
$this->applyTreeAttributeCondition($condition); |
| 246 |
|
|
| 247 |
|
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]); |
| 248 |
|
} |
| 249 |
|
|
| 250 |
|
/** |
| 251 |
|
* Gets the leaves of the node. |