ADD уведомления на добаление комментария к точке

This commit is contained in:
Krivchikov Dmitry 2015-11-14 11:28:04 +03:00
parent 22426d5e8a
commit 12876c8f56
3 changed files with 22 additions and 2 deletions

View File

@ -34,6 +34,24 @@ class CommentsController extends Controller
'html' => $html, 'html' => $html,
)); ));
$comment->save(); $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); App::redirect('/' . $_POST['parentType'] . '/' . $_POST['parentId'] . '#comment' . $comment->id);
} }

View File

@ -16,6 +16,7 @@ class Notifications extends Model
$this->setRelation('RefUser', 'userId', 'User', 'id', self::TO_ONE); $this->setRelation('RefUser', 'userId', 'User', 'id', self::TO_ONE);
$this->setRelation('RefFromUser', 'fromUserId', '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('RefPoint', 'objectId', 'Point', 'id', self::TO_ONE);
$this->setRelation('RefComment', 'objectId', 'Comment', 'id', self::TO_ONE);
} }
static function model() static function model()

View File

@ -6,8 +6,9 @@ switch ($notification->type) {
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> прошла модерацию.';
break; break;
case Notifications::typeNewCommentPoint: case Notifications::typeNewCommentPoint:
$comment = $notification->RefComment;
$point = Point::model()->getByPK($comment->parentId);
print strftime('%d %b %H:%M', $notification->date).' — Новый <a href="/point/'.$point->id.'#comment'.$comment->id.'">комментарий</a> к точке <a href="/point/'.$point->id.'">"'.$point->name.'"</a>.';
break; break;
default: default:
break; break;