public function insertRightOf(TreeModel &$siblingNode)
{
if ($siblingNode->lft >= $siblingNode->rgt) {
throw new TreeInvalidLftRgtSibling();
}
// Get a reference to the database
$db = $this->getDbo();
// Get the field names
$fldRgt = $db->qn($this->getFieldAlias('rgt'));
$fldLft = $db->qn($this->getFieldAlias('lft'));
// Nullify the PK, so a new record will be created
$this->{$this->idFieldName} = null;
// Get the value of the parent node's lft
$myRight = $siblingNode->rgt;
// Update my lft/rgt values
$this->lft = $myRight + 1;
$this->rgt = $myRight + 2;
$db->transactionStart();
try {
$db->setQuery($db->getQuery(true)->update($db->qn($this->tableName))->set($fldRgt . ' = ' . $fldRgt . '+2')->where($fldRgt . ' > ' . $db->q($myRight)))->execute();
$db->setQuery($db->getQuery(true)->update($db->qn($this->tableName))->set($fldLft . ' = ' . $fldLft . '+2')->where($fldLft . ' > ' . $db->q($myRight)))->execute();
$this->save();
// Commit the transaction
$db->transactionCommit();
} catch (\Exception $e) {
$db->transactionRollback();
throw $e;
}
return $this;
}