/** * Возвращает CommentCount * @return int */ public function getCommentCount() { if (is_null($this->comment_count)) { $this->comment_count = PostCommentModel::getCommentCount($this); } return $this->comment_count; }
public function actionSaveComment($post_id) { $post = PostModel::get($post_id); $input = \System\Engine::getInput(); $data = $input->getArray("data"); $data = array_intersect_key($data, array_flip(["name", "message"])); $user = UserModel::isAuthorized(); $data['post_id'] = $post_id; $data['message'] = strip_tags($data['message']); if ($user) { $data['user_id'] = $user->id; } else { $data['name'] = strip_tags($data['name']); } try { $comment = new PostCommentModel(); $comment->setData($data); $comment->save(); $this->redirect("/post/show/{$post->id}#comments"); } catch (Exception $e) { $this->redirect("/post/show/{$post->id}#comments", $e->getMessage()); } }