ADD ответы на комментарии, запись уведомлений в ленту активности

This commit is contained in:
Krivchikov Dmitry 2015-11-14 15:18:17 +03:00
parent 9e84cd63eb
commit 6a9ac8f73c
7 changed files with 56 additions and 7 deletions

View File

@ -41,6 +41,7 @@ class CommentsController extends Controller
$ownerId = Point::model()->getByPK((int) $_POST['parentId'])->author; $ownerId = Point::model()->getByPK((int) $_POST['parentId'])->author;
} }
// Оповещение автору статьи или точки
if ($ownerId != App::$user->id) { if ($ownerId != App::$user->id) {
Notifications::model()->add(array( Notifications::model()->add(array(
'userId' => $ownerId, '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); App::redirect('/' . $_POST['parentType'] . '/' . $_POST['parentId'] . '#comment' . $comment->id);
} }

View File

@ -7,7 +7,7 @@ class Comment extends Model
{ {
$this->_tableName_ = 'comments'; $this->_tableName_ = 'comments';
parent::__construct($fromArray); parent::__construct($fromArray);
$this->setRelation('refUser', 'userId', 'User', 'id', self::TO_ONE); $this->setRelation('RefUser', 'userId', 'User', 'id', self::TO_ONE);
} }
static function model() static function model()

View File

@ -1,6 +1,7 @@
<h3>Комментарии:</h3> <h3>Комментарии:</h3>
<?php <?php
self::addStyle('/css/comments.css'); self::addStyle('/css/comments.css');
self::addScript('/js/comment.js');
$comments = Comment::model()->getAll(array('where'=>'`parentType`="'.$parentType.'" AND `parentId`="'.$parentId.'"')); $comments = Comment::model()->getAll(array('where'=>'`parentType`="'.$parentType.'" AND `parentId`="'.$parentId.'"'));

View File

@ -1,12 +1,16 @@
<div class="singleComment"> <div class="singleComment">
<a name="comment<?= $comment->id ?>"></a> <a name="comment<?= $comment->id ?>"></a>
<img src="/img/avatars/<?= $comment->refUser->id ?>.jpg" class="avatar"/> <img src="/img/avatars/<?= $comment->RefUser->id ?>.jpg" class="avatar"/>
<div class="info"> <div class="info">
<a href="/user/<?= $comment->refUser->id ?>"><b><?= $comment->refUser->nick ?></b></a>&nbsp; <a href="/user/<?= $comment->RefUser->id ?>"><b><?= $comment->RefUser->nick ?></b></a>&nbsp;
<?= date('H:i d-m-Y',$comment->addDate) ?> <?= date('H:i d-m-Y',$comment->addDate) ?>
<a href="#comment<?= $comment->id ?>" name="#comment<?= $comment->id ?>" class="anchor">#</a> <?php if ($comment->answerTo): ?>
(<a href="#comment<?= $comment->answerTo ?>" title="Посмотреть комментарий">ответ на <span class="glyphicon glyphicon-hand-up"></span></a>)
<?php endif; ?>
<a href="#commentForm" title="Ответить" onclick="reply(<?= $comment->id ?>, '<?= $comment->RefUser->nick ?>');return false;" class="anchor"><span class="glyphicon glyphicon-share-alt"></span></a>
<a href="#comment<?= $comment->id ?>" title="Ссылка на комментарий" class="anchor">#</a>
<?php if (App::$user && $comment->userId == App::$user->id): ?> <?php if (App::$user && $comment->userId == App::$user->id): ?>
<a href="/comments/del/id/<?= $comment->id ?>" title="Удалить комментарий" class="anchor"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a> <a href="/comments/del/id/<?= $comment->id ?>" title="Удалить комментарий" class="anchor"><span class="glyphicon glyphicon-trash"></span></a>
<?php endif; ?> <?php endif; ?>
</div> </div>
<br/> <br/>

View File

@ -1,9 +1,15 @@
<div class="commentForm"> <div class="commentForm">
<a name="commentForm"></a>
<div id="reply" style="display: none;">
<span class="glyphicon glyphicon-share-alt"></span> ответ на <a href="" id="replyGoToComment">комментарий</a> пользователя
<span id="replyNick"></span>
<span class="glyphicon glyphicon-remove btn btn-link" onclick="noReply()"></span>
</div>
<form action="/comments/add" method="POST"> <form action="/comments/add" method="POST">
<input type="hidden" name="answerTo" value="0" /> <input type="hidden" name="answerTo" id="answerTo" value="0" />
<input type="hidden" name="parentType" value="<?= $parentType ?>" /> <input type="hidden" name="parentType" value="<?= $parentType ?>" />
<input type="hidden" name="parentId" value="<?= $parentId ?>" /> <input type="hidden" name="parentId" value="<?= $parentId ?>" />
<textarea name="text" style="width: 100%;" rows="5"></textarea> <textarea name="text" id="commentFormTextarea" style="width: 100%;" rows="5"></textarea>
<br/> <br/>
<span class="btn btn-info pull-right" title="Подсказка по разметке" onclick="$('#articleInfoModal').modal('show');"><span class="glyphicon glyphicon-info-sign"></span></span> <span class="btn btn-info pull-right" title="Подсказка по разметке" onclick="$('#articleInfoModal').modal('show');"><span class="glyphicon glyphicon-info-sign"></span></span>
<div class="buttons"> <div class="buttons">

View File

@ -1,6 +1,8 @@
<?php <?php
setlocale(LC_ALL, 'ru_RU.UTF-8'); setlocale(LC_ALL, 'ru_RU.UTF-8');
if ($notification->readed == 0) {print '<b>';}
switch ($notification->type) { switch ($notification->type) {
case Notifications::typePointConfirmed: case Notifications::typePointConfirmed:
print strftime('%d %b %H:%M', $notification->date).' — Ваша точка <a href="/point/'.$notification->objectId.'">"'.$notification->RefPoint->name.'"</a> прошла модерацию.'; print strftime('%d %b %H:%M', $notification->date).' — Ваша точка <a href="/point/'.$notification->objectId.'">"'.$notification->RefPoint->name.'"</a> прошла модерацию.';
@ -15,6 +17,13 @@ switch ($notification->type) {
$article = Article::model()->getByPK($comment->parentId); $article = Article::model()->getByPK($comment->parentId);
print strftime('%d %b %H:%M', $notification->date).' — Новый <a href="/article/'.$article->id.'#comment'.$comment->id.'">комментарий</a> к статье <a href="/article/'.$article->id.'">"'.$article->title.'"</a>.'; print strftime('%d %b %H:%M', $notification->date).' — Новый <a href="/article/'.$article->id.'#comment'.$comment->id.'">комментарий</a> к статье <a href="/article/'.$article->id.'">"'.$article->title.'"</a>.';
break; break;
case Notifications::typeReply:
$comment = $notification->RefComment;
$article = Article::model()->getByPK($comment->parentId);
print strftime('%d %b %H:%M', $notification->date).' — '.$comment->RefUser->nick.' <a href="/article/'.$article->id.'#comment'.$comment->id.'">ответил</a> на ваш комментарий к статье <a href="/article/'.$article->id.'">"'.$article->title.'"</a>.';
break;
default: default:
break; break;
} }
if ($notification->readed == 0) {print '</b>';}

15
public/js/comment.js Normal file
View File

@ -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);
}