Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Commit

Permalink
Prevent duplicate comment error when editing a comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
akrabat committed Feb 4, 2015
1 parent b563adf commit d617fa0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/system/application/controllers/talk.php
Expand Up @@ -611,6 +611,11 @@ function view($id, $add_act = null, $code = null)
$claim_user_ids[] = $claim_item->userid;
}

$current_comment_id = 0;
if ($this->input->post('edit_comment')) {
$current_comment_id = $this->input->post('edit_comment');
}

// comment form validation rules:
// rating:
// 1. rating_check to ensure between 0 and 5
Expand All @@ -623,7 +628,7 @@ function view($id, $add_act = null, $code = null)

$rules = array(
'rating' => $rating_rule,
'comment' => "callback_duplicate_comment_check[$id]",
'comment' => "callback_duplicate_comment_check[$id!$current_comment_id]",
);

$fields = array(
Expand Down Expand Up @@ -1154,17 +1159,20 @@ function rating_check($str)
*
* @return bool
*/
function duplicate_comment_check($str, $talkId)
function duplicate_comment_check($str, $params)
{
$newComment = trim($str);
list($talkId, $currentCommentId) = explode('!', $params);

if ($this->user_model->isAuth()) {
// Find out if there is at least 1 comment that is made by our
// user for this talk
$userId = $this->user_model->getId();
foreach ($this->talks_model->getUserComments($userId) as $comment) {
if ($comment->talk_id == $talkId) {
$thisCommentId = $comment->ID;
$thisComment = trim($comment->comment);
if ($thisComment == $newComment) {
if ($thisComment == $newComment && $thisCommentId != $currentCommentId) {
$this->validation->set_message(
'duplicate_comment_check',
'Duplicate comment.'
Expand Down

0 comments on commit d617fa0

Please sign in to comment.