From 6f1066d3b9c6156504a54716749358a00bcd335d Mon Sep 17 00:00:00 2001 From: qw5414 Date: Sat, 23 Jan 2016 23:12:12 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8C=93=EA=B8=80=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=B4=EC=84=9C=EB=8F=84=20=EC=B6=94=EC=B2=9C,=20=EB=B9=84?= =?UTF-8?q?=EC=B6=94=EC=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/board/skins/xedition/_comment.html | 5 +- modules/comment/comment.controller.php | 97 ++++++++++++++++++- modules/comment/comment.item.php | 23 +++++ modules/comment/conf/module.xml | 2 + modules/comment/lang/lang.xml | 6 ++ .../comment/queries/deleteCommentVotedLog.xml | 1 + .../comment/queries/getCommentVotedLog.xml | 15 +++ modules/document/document.controller.php | 4 + modules/document/document.item.php | 2 +- 9 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 modules/comment/queries/getCommentVotedLog.xml diff --git a/modules/board/skins/xedition/_comment.html b/modules/board/skins/xedition/_comment.html index 3830e0a11..fabb798c7 100644 --- a/modules/board/skins/xedition/_comment.html +++ b/modules/board/skins/xedition/_comment.html @@ -34,7 +34,10 @@

- {$lang->cmd_vote}:{$comment->get('voted_count')?$comment->get('voted_count'):0} + {$lang->cmd_vote}{$comment->get('voted_count')} + {$lang->cmd_vote}{$comment->get('voted_count')} + {$lang->cmd_vote_down}{$comment->get('blamed_count')} + {$lang->cmd_vote_down}{$comment->get('blamed_count')} {$lang->cmd_reply} {$lang->cmd_modify} {$lang->cmd_delete} diff --git a/modules/comment/comment.controller.php b/modules/comment/comment.controller.php index 7204a8bf2..997f7c091 100644 --- a/modules/comment/comment.controller.php +++ b/modules/comment/comment.controller.php @@ -59,6 +59,29 @@ class commentController extends comment return $output; } + function procCommentVoteUpCancel() + { + if(!Context::get('logged_info')) return new Object(-1, 'msg_invalid_request'); + + $comment_srl = Context::get('target_srl'); + if(!$comment_srl) return new Object(-1, 'msg_invalid_request'); + + $oCommentModel = getModel('comment'); + $oComment = $oCommentModel->getComment($comment_srl, FALSE, FALSE); + if($oComment->get('voted_count') <= 0) + { + return new Object(-1, 'msg_comment_voted_cancel_not'); + } + $point = 1; + $output = $this->updateVotedCountCancel($comment_srl, $oComment, $point); + + $output = new Object(); + $output->setMessage('success_voted_canceled'); + + return $output; + } + + /** * Action to handle recommendation votes on comments (Down) * @return Object @@ -97,6 +120,74 @@ class commentController extends comment return $output; } + function procCommentVoteDownCancel() + { + if(!Context::get('logged_info')) return new Object(-1, 'msg_invalid_request'); + + $comment_srl = Context::get('target_srl'); + if(!$comment_srl) return new Object(-1, 'msg_invalid_request'); + + $oCommentModel = getModel('comment'); + $oComment = $oCommentModel->getComment($comment_srl, FALSE, FALSE); + if($oComment->get('blamed_count') >= 0) + { + return new Object(-1, 'msg_comment_blamed_cancel_not'); + } + $point = -1; + $output = $this->updateVotedCountCancel($comment_srl, $oComment, $point); + + $output = new Object(); + $output->setMessage('success_voted_canceled'); + + return $output; + } + + function updateVotedCountCancel($comment_srl, $oComment, $point) + { + $logged_info = Context::get('logged_info'); + + $args = new stdClass(); + $d_args = new stdClass(); + $args->comment_srl = $d_args->comment_srl = $comment_srl; + $d_args->member_srl = $logged_info->member_srl; + if($point > 0) + { + $args->voted_count = $oComment->get('voted_count') - $point; + $output = executeQuery('comment.updateVotedCount', $args); + } + else + { + $args->blamed_count = $oComment->get('blamed_count') - $point; + $output = executeQuery('comment.updateBlamedCount', $args); + } + $d_output = executeQuery('comment.deleteCommentVotedLog', $d_args); + if(!$d_output->toBool()) return $d_output; + + //session reset + $_SESSION['voted_comment'][$comment_srl] = false; + + // begin transaction + $oDB = DB::getInstance(); + $oDB->begin(); + + $obj = new stdClass(); + $obj->member_srl = $oComment->get('member_srl'); + $obj->module_srl = $oComment->get('module_srl'); + $obj->comment_srl = $oComment->get('comment_srl'); + $obj->update_target = ($point < 0) ? 'blamed_count' : 'voted_count'; + $obj->point = $point; + $obj->before_point = ($point < 0) ? $oComment->get('blamed_count') : $oComment->get('voted_count'); + $obj->after_point = ($point < 0) ? $args->blamed_count : $args->voted_count; + $obj->cancel = 1; + $trigger_output = ModuleHandler::triggerCall('comment.updateVotedCountCancel', 'after', $obj); + if(!$trigger_output->toBool()) + { + $oDB->rollback(); + return $trigger_output; + } + return $output; + } + /** * Action to be called when a comment posting is reported * @return void|Object @@ -1163,11 +1254,14 @@ class commentController extends comment // update the number of votes if($point < 0) { + // leave into session information + $_SESSION['voted_comment'][$comment_srl] = $point; $args->blamed_count = $oComment->get('blamed_count') + $point; $output = executeQuery('comment.updateBlamedCount', $args); } else { + $_SESSION['voted_comment'][$comment_srl] = $point; $args->voted_count = $oComment->get('voted_count') + $point; $output = executeQuery('comment.updateVotedCount', $args); } @@ -1193,9 +1287,6 @@ class commentController extends comment $oDB->commit(); - // leave into session information - $_SESSION['voted_comment'][$comment_srl] = TRUE; - // Return the result $output = new Object(0, $success_message); if($point > 0) diff --git a/modules/comment/comment.item.php b/modules/comment/comment.item.php index ea4076962..397645051 100644 --- a/modules/comment/comment.item.php +++ b/modules/comment/comment.item.php @@ -281,6 +281,29 @@ class commentItem extends Object return htmlspecialchars($this->get('nick_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); } + function getVote() + { + if(!$this->comment_srl) return false; + if($_SESSION['voted_comment'][$this->comment_srl]) + { + return $_SESSION['voted_comment'][$this->comment_srl]; + } + + $logged_info = Context::get('logged_info'); + + $args = new stdClass(); + $args->member_srl = $logged_info->member_srl; + $args->comment_srl = $this->comment_srl; + $output = executeQuery('comment.getCommentVotedLog', $args); + + if($output->data->point) + { + return $output->data->point; + } + + return false; + } + /** * Return content with htmlspecialchars * @return string diff --git a/modules/comment/conf/module.xml b/modules/comment/conf/module.xml index 960344c37..d13854c26 100644 --- a/modules/comment/conf/module.xml +++ b/modules/comment/conf/module.xml @@ -23,6 +23,8 @@ + +

diff --git a/modules/comment/lang/lang.xml b/modules/comment/lang/lang.xml index 4c3f44e6f..ed45f3151 100644 --- a/modules/comment/lang/lang.xml +++ b/modules/comment/lang/lang.xml @@ -81,6 +81,12 @@ + + + + + + diff --git a/modules/comment/queries/deleteCommentVotedLog.xml b/modules/comment/queries/deleteCommentVotedLog.xml index 06ac9b320..5b3c64b85 100644 --- a/modules/comment/queries/deleteCommentVotedLog.xml +++ b/modules/comment/queries/deleteCommentVotedLog.xml @@ -4,5 +4,6 @@ + diff --git a/modules/comment/queries/getCommentVotedLog.xml b/modules/comment/queries/getCommentVotedLog.xml new file mode 100644 index 000000000..3468f0741 --- /dev/null +++ b/modules/comment/queries/getCommentVotedLog.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php index 3c9a81cae..2a8c8e55e 100644 --- a/modules/document/document.controller.php +++ b/modules/document/document.controller.php @@ -162,6 +162,10 @@ class documentController extends document //session reset $_SESSION['voted_document'][$document_srl] = false; + // begin transaction + $oDB = DB::getInstance(); + $oDB->begin(); + $obj = new stdClass(); $obj->member_srl = $oDocument->get('member_srl'); $obj->module_srl = $oDocument->get('module_srl'); diff --git a/modules/document/document.item.php b/modules/document/document.item.php index f78475e84..94bd205b1 100644 --- a/modules/document/document.item.php +++ b/modules/document/document.item.php @@ -371,7 +371,7 @@ class documentItem extends Object function getVoted() { - if(!$this->document_srl) return; + if(!$this->document_srl) return false; if($_SESSION['voted_document'][$this->document_srl]) { return $_SESSION['voted_document'][$this->document_srl];