public function AddComment(ModuleComment_EntityComment $oComment) { $sql = "INSERT INTO " . Config::Get('db.table.comment') . " \n\t\t\t(comment_pid,\n\t\t\ttarget_id,\n\t\t\ttarget_type,\n\t\t\ttarget_parent_id,\n\t\t\tuser_id,\n\t\t\tcomment_text,\n\t\t\tcomment_date,\n\t\t\tcomment_user_ip,\n\t\t\tcomment_text_hash,\n guest_name,\n guest_email\t\t\n\t\t\t)\n\t\t\tVALUES(?, ?d, ?, ?d, ?d, ?, ?, ?, ?, ?, ?)\n\t\t"; if ($iId = $this->oDb->query($sql, $oComment->getPid(), $oComment->getTargetId(), $oComment->getTargetType(), $oComment->getTargetParentId(), $oComment->getUserId(), $oComment->getText(), $oComment->getDate(), $oComment->getUserIp(), $oComment->getTextHash(), $oComment->getGuestName(), $oComment->getGuestEmail())) { return $iId; } return false; }
/** * Добавляет коммент в дерево nested set * * @param ModuleComment_EntityComment $oComment Объект комментария * @return bool|int */ public function AddCommentTree(ModuleComment_EntityComment $oComment) { $this->oDb->transaction(); if ($oComment->getPid() and $oCommentParent = $this->GetCommentsByArrayId(array($oComment->getPid()))) { $oCommentParent = $oCommentParent[0]; $iLeft = $oCommentParent->getRight(); $iLevel = $oCommentParent->getLevel() + 1; $sql = "UPDATE " . Config::Get('db.table.comment') . " SET comment_left=comment_left+2 WHERE target_id=?d and target_type=? and comment_left>? ;"; $this->oDb->query($sql, $oComment->getTargetId(), $oComment->getTargetType(), $iLeft - 1); $sql = "UPDATE " . Config::Get('db.table.comment') . " SET comment_right=comment_right+2 WHERE target_id=?d and target_type=? and comment_right>? ;"; $this->oDb->query($sql, $oComment->getTargetId(), $oComment->getTargetType(), $iLeft - 1); } else { if ($oCommentLast = $this->GetCommentLast($oComment->getTargetId(), $oComment->getTargetType())) { $iLeft = $oCommentLast->getRight() + 1; } else { $iLeft = 1; } $iLevel = 0; } if ($iId = $this->AddComment($oComment)) { $sql = "UPDATE " . Config::Get('db.table.comment') . " SET comment_left = ?d, comment_right = ?d, comment_level = ?d WHERE comment_id = ? ;"; $this->oDb->query($sql, $iLeft, $iLeft + 1, $iLevel, $iId); $this->oDb->commit(); return $iId; } if (strtolower(Config::Get('db.tables.engine')) == 'innodb') { $this->oDb->rollback(); } return false; }