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;
 }
 /**
  * Проверка на соответсвие коментария родительскому коментарию
  *
  * @param ModuleTopic_EntityTopic $oTopic
  * @param string $sText
  * @param ModuleComment_EntityComment $oCommentParent
  *
  * @return bool result
  */
 protected function CheckParentComment($oTopic, $sText, $oCommentParent)
 {
     $sParentId = 0;
     if ($oCommentParent) {
         $sParentId = $oCommentParent->GetCommentId();
     }
     $bOk = true;
     /**
      * Проверям на какой коммент отвечаем
      */
     if (!func_check($sParentId, 'id')) {
         $this->Message_AddErrorSingle($this->Lang_Get('common.error.system.base'), $this->Lang_Get('common.error.error'));
         $bOk = false;
     }
     if ($sParentId) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!$oCommentParent) {
             $this->Message_AddErrorSingle($this->Lang_Get('common.error.system.base'), $this->Lang_Get('common.error.error'));
             $bOk = false;
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oTopic->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('common.error.system.base'), $this->Lang_Get('common.error.error'));
             $bOk = false;
         }
     } else {
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oTopic->getId(), 'topic', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic.comments.notices.spam'), $this->Lang_Get('common.error.error'));
         $bOk = false;
     }
     $this->Hook_Run('comment_check_parent', array('oTopic' => $oTopic, 'sText' => $sText, 'oCommentParent' => $oCommentParent, 'bOk' => &$bOk));
     return $bOk;
 }