要点:

  1. 撑宽目标node的宽度 shift R && L Values
$first = $parent_manual['node']['l']+1; //The dst node l value

$delta  = $current_manual['rgt'] - $current_manual['lft']+1;

mysql_query('START TRANSACTION');
  $result_a = mysql_query("UPDATE ".$thandle['table']." SET ".$thandle['lvalname']."=".$thandle['lvalname']."+$delta WHERE ".$thandle['lvalname'].">=$first ");
  $result_b = mysql_query("UPDATE ".$thandle['table']." SET ".$thandle['rvalname']."=".$thandle['rvalname']."+$delta WHERE ".$thandle['rvalname'].">=$first ");
	/*IF UPDATE IS SUCCESS ,THEN DO COMMIT*/
	if ($result_a && $result_b) {
		mysql_query('COMMIT');
	} else {
		mysql_query('ROLLBACK');
	}

  1. 复制的操作
$delta  = $parent_manual['node']['l'] - $current_manual['lft'] + 1;

	foreach ($tree as  $manual) {
	$manual['description'] = '';
	$manual['lft'] += $delta;
	$manual['rgt'] += $delta ;
	$manual['root_id'] = $root_id;
	copy_one_item($manual, $root_id, $thandle);
}

  • 其实最重要的就是$first和$delta的计算方法.

转载请注明:韦旭红的点点滴滴 » Nested set model: Copy SubTree