метод для обмена двух узлов:
Код:
function SwapNodes($categoryID1, $categoryID2)
{
if ($this->getNodeInfo($categoryID1) == 0)
{
$nodeInfo1 = $this->nodeInfo;
}
if ($this->getNodeInfo($categoryID2) == 0)
{
$nodeInfo2 = $this->nodeInfo;
}
// todo:
// check for rule: both nodes must have same parentID
$db = new MySql(null, "mport4", null, null);
$db->MySql_Connect();
$db->MySql_SelectDb();
$updateQuery = "update categories set
cat_LEFT = case
when cat_LEFT between " . $nodeInfo1["left"] . " and " . $nodeInfo1["right"] . " then " .
$nodeInfo2["right"] . "+cat_LEFT-" . $nodeInfo1["right"] .
" when cat_LEFT between " . $nodeInfo2["left"] . " and " . $nodeInfo2["right"] . " then " .
$nodeInfo1["left"] . "+cat_LEFT-" . $nodeInfo2["left"] . " else " .
$nodeInfo1["left"] . "+" . $nodeInfo2["right"] . "+cat_LEFT-" . $nodeInfo1["right"] . "-" . $nodeInfo2["left"] . " end," .
" cat_RIGHT = case
when cat_RIGHT between " . $nodeInfo1["left"] . " and " . $nodeInfo1["right"] . " then " .
$nodeInfo2["right"] . "+cat_RIGHT-" . $nodeInfo1["right"] .
" when cat_RIGHT between " . $nodeInfo2["left"] . " and " . $nodeInfo2["right"] . " then " .
$nodeInfo1["left"] . "+cat_RIGHT-" . $nodeInfo2["left"] . " else " .
$nodeInfo1["left"] . "+" . $nodeInfo2["right"] . "+cat_RIGHT-" . $nodeInfo1["right"] . "-" . $nodeInfo2["left"] . " end " .
" where cat_LEFT between " . $nodeInfo1["left"] . " and " . $nodeInfo2["right"] .
" and " . $nodeInfo1["left"] . "<" . $nodeInfo1["right"] .
" and " . $nodeInfo1["right"] . "<" . $nodeInfo2["left"] .
" and " . $nodeInfo2["left"] . "<" . $nodeInfo2["right"];
$db->MySql_QueryDb($updateQuery);
if (mysql_affected_rows($db->dbConn) > 0)
{
return 0;
}
return -1;
}
p.s. нужно добавить проверки.