/** * @param integer $value * @param integer $depth */ protected function moveNode($value, $depth) { $leftValue = $this->owner->getAttribute($this->leftAttribute); $rightValue = $this->owner->getAttribute($this->rightAttribute); $depthValue = $this->owner->getAttribute($this->depthAttribute); $depth = $this->node->getAttribute($this->depthAttribute) - $depthValue + $depth; if ($this->treeAttribute === false || $this->owner->getAttribute($this->treeAttribute) === $this->node->getAttribute($this->treeAttribute)) { $delta = $rightValue - $leftValue + 1; $this->shiftLeftRightAttribute($value, $delta); if ($leftValue >= $value) { $leftValue += $delta; $rightValue += $delta; } $condition = ['and', [$this->leftAttribute => ['$gte' => $leftValue]], [$this->rightAttribute => ['$lte' => $rightValue]]]; $this->applyTreeAttributeCondition($condition); $this->owner->updateAll(['$inc' => [$this->depthAttribute => $depth]], $condition); foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) { $condition = ['and', [$attribute => ['$gte' => $leftValue]], [$attribute => ['$lte' => $rightValue]]]; $this->applyTreeAttributeCondition($condition); $this->owner->updateAll(['$inc' => [$attribute => $value - $leftValue]], $condition); } $this->shiftLeftRightAttribute($rightValue + 1, -$delta); } else { $nodeRootValue = $this->node->getAttribute($this->treeAttribute); foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) { $this->owner->updateAll(['$inc' => [$attribute => $rightValue - $leftValue + 1]], ['and', [$attribute => ['$gte' => $value]], [$this->treeAttribute => $nodeRootValue]]); } $delta = $value - $leftValue; $this->owner->updateAll(['$inc' => [$this->leftAttribute => $delta, $this->rightAttribute => $delta, $this->depthAttribute => $depth], '$set' => [$this->treeAttribute => $nodeRootValue]], ['and', [$this->leftAttribute => ['$gte' => $leftValue]], [$this->rightAttribute => ['$lte' => $rightValue]], [$this->treeAttribute => $this->owner->getAttribute($this->treeAttribute)]]); $this->shiftLeftRightAttribute($rightValue + 1, $leftValue - $rightValue - 1); } }