/** * @inheritdoc */ public function behaviors() { return [['class' => SortableBehavior::className(), 'query' => function ($model) { /** @var ItemWindow $model */ $tableName = $model->tableName(); return $model->find()->andWhere(["{$tableName}.[[parent_id]]" => $model->parent_id]); }, 'joinMode' => false]]; }
/** * Insert operation internal handler * @param bool $forward * @throws Exception */ protected function insertNearInternal($forward) { $this->checkNode(true); $this->owner->setAttribute($this->parentAttribute, $this->node->getAttribute($this->parentAttribute)); if ($this->sortable !== false) { if ($forward) { $this->behavior->moveAfter($this->node); } else { $this->behavior->moveBefore($this->node); } } }
/** * Insert operation internal handler * @param bool $forward * @throws Exception */ protected function insertNearInternal($forward) { $this->checkNode(true); $item = $this->owner->getAttribute($this->itemAttribute); if ($item !== null) { $path = $this->node->getParentPath(); $this->owner->setAttribute($this->pathAttribute, $path . $this->delimiter . $item); } $this->owner->setAttribute($this->depthAttribute, $this->node->getAttribute($this->depthAttribute)); if ($this->treeAttribute !== null) { $this->owner->setAttribute($this->treeAttribute, $this->node->getAttribute($this->treeAttribute)); } if ($this->sortable !== false) { if ($forward) { $this->behavior->moveAfter($this->node); } else { $this->behavior->moveBefore($this->node); } } }
/** * @param ActiveRecord $owner */ public function attach($owner) { parent::attach($owner); if ($this->sortable !== false) { $this->behavior = Yii::createObject(array_merge(['class' => SortableBehavior::className(), 'query' => [$this->parentAttribute]], $this->sortable)); $owner->attachBehavior('adjacency-list-sortable', $this->behavior); } }
/** * @inheritdoc */ public function behaviors() { return [['class' => SortableBehavior::className(), 'query' => ['parent_id']]]; }