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;
 }
Beispiel #3
0
 /**
  * Проверка на редактирование комментария
  *
  * @param ModuleComment_EntityComment $oComment
  * @param ModuleUser_EntityUser $oUser
  *
  * @return bool
  */
 public function IsAllowEditComment($oComment, $oUser)
 {
     if (!$oUser) {
         return false;
     }
     if (!in_array($oComment->getTargetType(), (array) Config::Get('module.comment.edit_target_allow'))) {
         return false;
     }
     if ($oUser->isAdministrator()) {
         return true;
     }
     if ($oComment->getUserId() == $oUser->getId() and $oUser->getRating() >= Config::Get('acl.update.comment.rating')) {
         /**
          * Проверяем на лимит времени
          */
         if (!Config::Get('acl.update.comment.limit_time') or time() - strtotime($oComment->getDate()) <= Config::Get('acl.update.comment.limit_time')) {
             return true;
         }
     }
     return false;
 }
Beispiel #4
0
 /**
  * Проверяет может ли пользователь голосовать за конкретный комментарий
  *
  * @param ModuleUser_EntityUser $oUser	Пользователь
  * @param ModuleComment_EntityComment $oComment	Комментарий
  * @return bool
  */
 public function CanVoteComment(ModuleUser_EntityUser $oUser, ModuleComment_EntityComment $oComment)
 {
     //if ($oUser->getRating()<Config::Get('acl.vote.comment.rating')) {
     //	return false;
     //}
     if ($oComment->getTargetType() == 'talk') {
         return false;
     }
     if (!in_array($oComment->getTarget()->getBlogId(), $this->ModuleBlog_GetAccessibleBlogsByUser($oUser)) and $oComment->getTarget()->getBlog()->getType() != "open") {
         return false;
     }
     return true;
 }