public function postAction() { $postId = $this->dispatcher->getParam('postId'); $threadManager = new ThreadManager(); $uniqueKey = 'post_' . $postId; $thread = $threadManager->findThreadByUniqueKey($uniqueKey); if (!$thread) { throw new Exception\ResourceNotFoundException('ERR_COMMENT_THREAD_NOT_FOUND'); } $form = new ThreadForm(); $form->setModel($thread); if ($this->request->isPost()) { $data = $this->request->getPost(); if (!$form->isFullValid($data)) { return $this->displayInvalidMessages($form); } try { $form->save(); } catch (\Exception $e) { return $this->displayException($e, $form->getModel()->getMessages()); } $this->flashSession->success('SUCCESS_UPDATED'); return $this->redirectHandler('/admin/thread/post/' . $postId); } $this->view->setVar('form', $form); $this->view->setVar('thread', $thread); }
/** * {@inheritdoc} */ public function saveComment(Comments $comment) { $thread = $comment->getThread(); if (null === $thread) { throw new InvalidArgumentException('The comment must have a thread'); } $comment->save(); $threadManager = new ThreadManager(); $threadManager->addCommentNumber($thread); return true; }
/** * Creates a new Comment for the Thread from the submitted data. * * @param string $uniqueKey The id of the thread * @throws \Exception */ public function postThreadCommentsAction($uniqueKey) { $threadManager = new ThreadManager(); $thread = $threadManager->findThreadByUniqueKey($uniqueKey); if (!$thread) { throw new \Exception(sprintf('Thread with identifier of "%s" does not exist', $uniqueKey)); } // if (!$thread->isCommentable()) { // throw new \Exception(sprintf('Thread "%s" is not commentable', $uniqueKey)); // } $parentId = $this->request->getPost('parentId'); $parent = $this->getValidCommentParent($thread, $parentId); $content = $this->request->getPost('content'); $username = $this->request->getPost('username'); $commentManager = new CommentManager(); $comment = $commentManager->createComment($thread, $parent); // if ($form->isValid()) { $comment->content = $content; // if(!empty($username)) $comment->username = $username; $user = new LoginModel(); if ($user->isUserLoggedIn()) { $userinfo = $user->getCurrentUser(); $comment->userId = $userinfo['id']; $comment->username = $userinfo['username']; } $commentManager->filterContent($comment); //政治敏感词过滤 if ($commentManager->saveComment($comment) !== false) { $errors = $comment->getMessages(); p($errors); // return $this->getViewHandler()->handle($this->onCreateCommentSuccess($form, $id, $parent)); } $this->view->pick('thread/comment'); $this->view->setVars(array('comment' => $comment, 'thread' => $thread)); }
/** * * @SWG\Api( * path="/comments/counter", * description="Comment related api", * produces="['application/json']", * @SWG\Operations( * @SWG\Operation( * method="GET", * summary="count comment by thread unique key", * notes="Returns number", * @SWG\Parameters( * @SWG\Parameter( * name="ids", * description="unique key of thread", * paramType="query", * required=true, * type="string" * ) * ) * ) * ) * ) */ public function counterAction() { $ids = $this->request->getQuery('ids'); if (!is_array($ids)) { $ids = array($ids); } $threadManager = new ThreadManager(); $data = array(); foreach ($ids as $uniqueKey) { $thread = $threadManager->findThreadByUniqueKey($uniqueKey); if ($thread) { $data['threads'][] = array('uniqueKey' => $uniqueKey, 'numComments' => $thread->numComments); } } echo json_encode($data); $this->view->disable(); }