From 6a9ac8f73cafc17184d3273c08906a4d8385e8c1 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sat, 14 Nov 2015 15:18:17 +0300 Subject: [PATCH] =?UTF-8?q?ADD=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=8B=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B8,=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20?= =?UTF-8?q?=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20=D0=BB=D0=B5=D0=BD=D1=82=D1=83=20=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/CommentsController.php | 14 ++++++++++++++ ground/models/Comment.php | 2 +- ground/views/comments/all.php | 1 + ground/views/comments/comment.php | 12 ++++++++---- ground/views/comments/form.php | 10 ++++++++-- ground/views/user/notification.php | 9 +++++++++ public/js/comment.js | 15 +++++++++++++++ 7 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 public/js/comment.js 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); +}