From 12876c8f565d4abb04b28f1159ccee4f347cb29b Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sat, 14 Nov 2015 11:28:04 +0300 Subject: [PATCH] =?UTF-8?q?ADD=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D1=8F=20=D0=BA=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/CommentsController.php | 18 ++++++++++++++++++ ground/models/Notifications.php | 1 + ground/views/user/notification.php | 5 +++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ground/controllers/CommentsController.php b/ground/controllers/CommentsController.php index 7ee30c6..6f81da3 100644 --- a/ground/controllers/CommentsController.php +++ b/ground/controllers/CommentsController.php @@ -34,6 +34,24 @@ class CommentsController extends Controller 'html' => $html, )); $comment->save(); + + if ($_POST['parentType'] == 'article') { + $ownerId = Article::model()->getByPK((int) $_POST['parentId'])->author; + } else { + $ownerId = Point::model()->getByPK((int) $_POST['parentId'])->author; + } + + if ($ownerId != App::$user->id) { + Notifications::model()->add(array( + 'userId' => $ownerId, + 'fromUserId' => App::$user->id, + 'objectId' => $comment->id, + 'type' => ($_POST['parentType'] == 'article') ? Notifications::typeNewCommentArticle : Notifications::typeNewCommentPoint, + 'date' => time(), + )); + } + + App::redirect('/' . $_POST['parentType'] . '/' . $_POST['parentId'] . '#comment' . $comment->id); } diff --git a/ground/models/Notifications.php b/ground/models/Notifications.php index b35c108..8ede5e9 100644 --- a/ground/models/Notifications.php +++ b/ground/models/Notifications.php @@ -16,6 +16,7 @@ class Notifications extends Model $this->setRelation('RefUser', 'userId', 'User', 'id', self::TO_ONE); $this->setRelation('RefFromUser', 'fromUserId', 'User', 'id', self::TO_ONE); $this->setRelation('RefPoint', 'objectId', 'Point', 'id', self::TO_ONE); + $this->setRelation('RefComment', 'objectId', 'Comment', 'id', self::TO_ONE); } static function model() diff --git a/ground/views/user/notification.php b/ground/views/user/notification.php index 77d5cd9..d661d5b 100644 --- a/ground/views/user/notification.php +++ b/ground/views/user/notification.php @@ -6,8 +6,9 @@ switch ($notification->type) { print strftime('%d %b %H:%M', $notification->date).' — Ваша точка "'.$notification->RefPoint->name.'" прошла модерацию.'; break; case Notifications::typeNewCommentPoint: - - + $comment = $notification->RefComment; + $point = Point::model()->getByPK($comment->parentId); + print strftime('%d %b %H:%M', $notification->date).' — Новый комментарий к точке "'.$point->name.'".'; break; default: break;