request->getPost(); $user = $this->getLoginUser(); $validator = new UserLimitValidator(); $validator->checkDailyCommentLimit($user); $validator = new CommentValidator(); $validator->checkItemType($post['item_type']); $comment = new CommentModel(); $data = [ 'owner_id' => $user->id, 'published' => 1, ]; $data['content'] = $validator->checkContent($post['content']); if (isset($post['to_user_id'])) { $toUser = $validator->checkToUser($post['to_user_id']); $data['to_user_id'] = $toUser->id; } if ($post['item_type'] == CommentModel::ITEM_ARTICLE) { $article = $this->checkArticle($post['item_id']); $this->incrArticleCommentCount($article); } $comment->create($data); $this->incrUserDailyCommentCount($user); return $comment; } protected function incrArticleCommentCount(ArticleModel $article) { $article->comment_count += 1; $article->update(); } protected function incrUserDailyCommentCount(UserModel $user) { $this->eventsManager->fire('UserDailyCounter:incrCommentCount', $this, $user); } }