diff --git a/ground/controllers/CommentsController.php b/ground/controllers/CommentsController.php index 6f81da3..87a7fe8 100644 --- a/ground/controllers/CommentsController.php +++ b/ground/controllers/CommentsController.php @@ -41,6 +41,7 @@ class CommentsController extends Controller $ownerId = Point::model()->getByPK((int) $_POST['parentId'])->author; } + // Оповещение автору статьи или точки if ($ownerId != App::$user->id) { Notifications::model()->add(array( 'userId' => $ownerId, @@ -51,6 +52,19 @@ class CommentsController extends Controller )); } + // Оповещение тому, на чей комментарий отвечают + if (intval($_POST['answerTo']) > 0) { + $parentComment = Comment::model()->getByPK(intval($_POST['answerTo'])); + if ($parentComment->userId != App::$user->id) { + Notifications::model()->add(array( + 'userId' => $parentComment->userId, + 'fromUserId' => App::$user->id, + 'objectId' => $comment->id, + 'type' => Notifications::typeReply, + 'date' => time(), + )); + } + } App::redirect('/' . $_POST['parentType'] . '/' . $_POST['parentId'] . '#comment' . $comment->id); } diff --git a/ground/models/Comment.php b/ground/models/Comment.php index dd6476a..8346f6e 100644 --- a/ground/models/Comment.php +++ b/ground/models/Comment.php @@ -7,7 +7,7 @@ class Comment extends Model { $this->_tableName_ = 'comments'; parent::__construct($fromArray); - $this->setRelation('refUser', 'userId', 'User', 'id', self::TO_ONE); + $this->setRelation('RefUser', 'userId', 'User', 'id', self::TO_ONE); } static function model() diff --git a/ground/views/comments/all.php b/ground/views/comments/all.php index 218648d..5488f39 100644 --- a/ground/views/comments/all.php +++ b/ground/views/comments/all.php @@ -1,6 +1,7 @@

Комментарии:

getAll(array('where'=>'`parentType`="'.$parentType.'" AND `parentId`="'.$parentId.'"')); diff --git a/ground/views/comments/comment.php b/ground/views/comments/comment.php index b46815f..a6f2748 100644 --- a/ground/views/comments/comment.php +++ b/ground/views/comments/comment.php @@ -1,12 +1,16 @@
- +
- refUser->nick ?>  + RefUser->nick ?>  addDate) ?> - # + answerTo): ?> + (ответ на ) + + + # userId == App::$user->id): ?> - +

diff --git a/ground/views/comments/form.php b/ground/views/comments/form.php index ff39d29..6c67e03 100644 --- a/ground/views/comments/form.php +++ b/ground/views/comments/form.php @@ -1,9 +1,15 @@
+ +
- + - +
diff --git a/ground/views/user/notification.php b/ground/views/user/notification.php index e19b108..058542d 100644 --- a/ground/views/user/notification.php +++ b/ground/views/user/notification.php @@ -1,6 +1,8 @@ readed == 0) {print '';} + switch ($notification->type) { case Notifications::typePointConfirmed: print strftime('%d %b %H:%M', $notification->date).' — Ваша точка "'.$notification->RefPoint->name.'" прошла модерацию.'; @@ -15,6 +17,13 @@ switch ($notification->type) { $article = Article::model()->getByPK($comment->parentId); print strftime('%d %b %H:%M', $notification->date).' — Новый комментарий к статье "'.$article->title.'".'; break; + case Notifications::typeReply: + $comment = $notification->RefComment; + $article = Article::model()->getByPK($comment->parentId); + print strftime('%d %b %H:%M', $notification->date).' — '.$comment->RefUser->nick.' ответил на ваш комментарий к статье "'.$article->title.'".'; + break; default: break; } + +if ($notification->readed == 0) {print '';} diff --git a/public/js/comment.js b/public/js/comment.js new file mode 100644 index 0000000..ba35265 --- /dev/null +++ b/public/js/comment.js @@ -0,0 +1,15 @@ +function reply(id, nick) +{ + $('#answerTo').val(id); + $('#replyGoToComment').attr('href', '#comment'+id); + $('#replyNick').text(nick); + $('#reply').show(); + $('#commentFormTextarea').focus(); + return false; +} + +function noReply() +{ + $('#answerTo').val(0); + $('#reply').hide(200); +}