Skip to content

Commit

Permalink
Update moveUp too
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Feb 8, 2015
1 parent d3afee6 commit c7983b2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -570,6 +570,8 @@ protected function _moveUp($node, $number)
}

$edge = $this->_getMax();
$width = $node->{$right} - $node->{$left};

while ($number-- > 0) {
list($nodeLeft, $nodeRight) = array_values($node->extract([$left, $right]));

Expand All @@ -590,14 +592,10 @@ protected function _moveUp($node, $number)
$this->_sync($nodeLeft - $nextNode->{$left}, '-', "BETWEEN {$nodeLeft} AND {$nodeRight}");
$this->_sync($edge - $nextNode->{$left} - ($nodeRight - $nodeLeft), '-', "> {$edge}");

$newLeft = $nodeLeft;
if ($nodeLeft >= $nextNode->{$left} || $nodeLeft <= $nextNode->{$right}) {
$newLeft -= $edge - $nextNode->{$left} + 1;
}
$newLeft = $nodeLeft - ($nodeLeft - $nextNode->{$left});
$shift = $node->{$right} - $nextNode->{$right};

$node->set($left, $newLeft);
$node->set($right, $newLeft + ($nodeRight - $nodeLeft));
$node->set($right, $node->{$left} + $width - $shift);
$node->set($left, $node->{$left} - $shift);
}

$node->dirty($left, false);
Expand Down Expand Up @@ -673,10 +671,10 @@ protected function _moveDown($node, $number)
$this->_sync($nextNode->{$left} - $nodeLeft, '-', "BETWEEN {$nextNode->{$left}} AND {$nextNode->{$right}}");
$this->_sync($edge - $nodeLeft - ($nextNode->{$right} - $nextNode->{$left}), '-', "> {$edge}");

$move = $nextNode->{$right} - $node->{$right};
$shift = $nextNode->{$right} - $node->{$right};

$node->set($right, $node->{$left} + $width + $move);
$node->set($left, $node->{$left} + $move);
$node->set($right, $node->{$left} + $width + $shift);
$node->set($left, $node->{$left} + $shift);
}

$node->dirty($left, false);
Expand Down

0 comments on commit c7983b2

Please sign in to comment.