Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id name left right
- //
- * -- create new space for subtree
- * UPDATE tags SET lpos = lpos + :width WHERE lpos >= :newpos
- * UPDATE tags SET rpos = rpos + :width WHERE rpos >= :newpos
- *
- * -- move subtree into new space
- * UPDATE tags SET lpos = lpos + :distance, rpos = rpos + :distance
- * WHERE lpos >= :tmppos AND rpos < :tmppos + :width
- *
- * -- remove old space vacated by subtree
- * UPDATE tags SET lpos = lpos - :width WHERE lpos > :oldrpos
- * UPDATE tags SET rpos = rpos - :width WHERE rpos > :oldrpos
- */
- // calculate position adjustment variables
- int width = node.getRpos() - node.getLpos() + 1;
- int distance = newpos - node.getLpos();
- int tmppos = node.getLpos();
- // backwards movement must account for new space
- if (distance < 0) {
- distance -= width;
- tmppos += width;
- }
- $step = 1+ $this->_categoriesTable->rgt
- - $this->_categoriesTable->lft;
- $lft = $this->_categoriesTable->lft;
- $rgt = $this->_categoriesTable->rgt;
- $id = $this->_categoriesTable->id;
- $distance = $lft - $parentLeft - 1;
- $query = '
- UPDATE %s SET lft=-lft, rgt=-rgt
- WHERE lft>=%d AND lft<=%d;
- UPDATE %s SET lft=lft+%d WHERE lft>%d AND lft<%d;
- UPDATE %s SET rgt=rgt+%d WHERE rgt>%d AND rgt<%d;
- UPDATE %s SET lft=-lft-%d, rgt=-rgt-%d WHERE lft<=-%d
- AND lft>=-%d;
- UPDATE %s SET parent_id=%d, title=%s, description=%s,
- metadescription=%s WHERE id=%s';
- $query = sprintf($query,
- $this->_db->nameQuote('#__categories'),
- $lft, $rgt,
- $this->_db->nameQuote('#__categories'), $step,
- $parentLeft, $lft,
- $this->_db->nameQuote('#__categories'), $step,
- $parentLeft, $lft,
- $this->_db->nameQuote('#__categories'), $distance,
- $distance, $lft, $rgt,
- $this->_db->nameQuote('#__categories'),
- $data['parent_id'],
- $this->_db->Quote($this->_categoriesTable->title),
- $this->_db->Quote($this->_categoriesTable->description),
- $this->_db->Quote(
- $this->_categoriesTable->metadescription),
- $this->_db->Quote($id));
- // and for the moving to the "right" case
- $step = 1+ $this->_categoriesTable->rgt
- - $this->_categoriesTable->lft;
- $distance = $parentLeft - $this->_categoriesTable->rgt;
- // Memorize this because we bind and we need the old values
- $lft = $this->_categoriesTable->lft;
- $rgt = $this->_categoriesTable->rgt;
- $id = $this->_categoriesTable->id;
- $query = sprintf($query,
- $this->_db->nameQuote('#__categories'),
- $lft, $rgt,
- $this->_db->nameQuote('#__categories'), $step,
- $rgt, $parentLeft,
- $this->_db->nameQuote('#__categories'), $step,
- $rgt, $parentLeft,
- $this->_db->nameQuote('#__categories'), $distance,
- $distance, $lft, $rgt,
- $this->_db->nameQuote('#__categories'),
- $data['parent_id'],
- $this->_db->Quote($this->_categoriesTable->title),
- $this->_db->Quote($this->_categoriesTable->description),
- $this->_db->Quote(
- $this->_categoriesTable->metadescription),
- $this->_db->Quote($id));
- #Set IDs
- SET @dirId := :dirId; #folder (subtree) you wanna move
- SET @targetId := :folderId; #target
- #get datas
- SELECT rgt, lft, rgt-lft+1, level INTO @dir_rgt, @dir_lft, @dir_size, @dir_level FROM files WHERE id = @dirId;
- #put the moving tree aside (lft and rgt columns must allow negative int)
- UPDATE files SET lft = 0-lft, rgt = 0-rgt WHERE lft BETWEEN @dir_lft AND @dir_rgt;
- #fill the empty space
- UPDATE files SET rgt = rgt-@dir_size WHERE rgt > @dir_rgt;
- UPDATE files SET lft = lft-@dir_size WHERE lft > @dir_rgt;
- #get datas of the target-folder
- SELECT lft, level INTO @target_lft, @target_level FROM files WHERE id = @targetId;
- #create space in the target-folder
- UPDATE files SET rgt = rgt+@dir_size WHERE rgt >= @target_lft;
- UPDATE files SET lft = lft+@dir_size WHERE lft > @target_lft;
- #edit all nodes in the moving-tree
- UPDATE files SET
- lft = 0 - lft - (@dir_lft - @target_lft - 1), #this formula fits for all moving directions
- rgt = 0 - rgt - (@dir_lft - @target_lft - 1),
- level = level - (@dir_level - @target_level) + 1
- WHERE
- lft < 0; #that could be more precise...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement