@@ 272-287 (lines=16) @@ | ||
269 | * @return \yii\db\ActiveQuery |
|
270 | * @throws NotSupportedException |
|
271 | */ |
|
272 | public function getPrev() |
|
273 | { |
|
274 | if ($this->sortable === false) { |
|
275 | throw new NotSupportedException('prev() not allow if not set sortable'); |
|
276 | } |
|
277 | $tableName = $this->owner->tableName(); |
|
278 | $query = $this->owner->find() |
|
279 | ->andWhere(['like', "{$tableName}.[[{$this->pathAttribute}]]", $this->getLike($this->getParentPath()), false]) |
|
280 | ->andWhere(["{$tableName}.[[{$this->depthAttribute}]]" => $this->owner->getAttribute($this->depthAttribute)]) |
|
281 | ->andWhere(['<', "{$tableName}.[[{$this->behavior->sortAttribute}]]", $this->owner->getSortablePosition()]) |
|
282 | ->andWhere($this->treeCondition()) |
|
283 | ->orderBy(["{$tableName}.[[{$this->behavior->sortAttribute}]]" => SORT_DESC]) |
|
284 | ->limit(1); |
|
285 | $query->multiple = false; |
|
286 | return $query; |
|
287 | } |
|
288 | ||
289 | /** |
|
290 | * @return \yii\db\ActiveQuery |
|
@@ 293-308 (lines=16) @@ | ||
290 | * @return \yii\db\ActiveQuery |
|
291 | * @throws NotSupportedException |
|
292 | */ |
|
293 | public function getNext() |
|
294 | { |
|
295 | if ($this->sortable === false) { |
|
296 | throw new NotSupportedException('prev() not allow if not set sortable'); |
|
297 | } |
|
298 | $tableName = $this->owner->tableName(); |
|
299 | $query = $this->owner->find() |
|
300 | ->andWhere(['like', "{$tableName}.[[{$this->pathAttribute}]]", $this->getLike($this->getParentPath()), false]) |
|
301 | ->andWhere(["{$tableName}.[[{$this->depthAttribute}]]" => $this->owner->getAttribute($this->depthAttribute)]) |
|
302 | ->andWhere(['>', "{$tableName}.[[{$this->behavior->sortAttribute}]]", $this->owner->getSortablePosition()]) |
|
303 | ->andWhere($this->treeCondition()) |
|
304 | ->orderBy(["{$tableName}.[[{$this->behavior->sortAttribute}]]" => SORT_ASC]) |
|
305 | ->limit(1); |
|
306 | $query->multiple = false; |
|
307 | return $query; |
|
308 | } |
|
309 | ||
310 | /** |
|
311 | * Returns all sibilings of node. |