public function batchAction() { if (!$this->request->isPut()) { return $this->showErrorMessageAsJson(405, 'ERR_REQUEST_METHOD_NOT_ALLOW'); } $idArray = $this->request->getPut('id'); if (!is_array($idArray) || count($idArray) < 1) { return $this->showErrorMessageAsJson(401, 'ERR_REQUEST_PARAMS_INCORRECT'); } $status = $this->request->getPut('status'); $comments = array(); $commentManager = new Models\CommentManager(); try { foreach ($idArray as $id) { $comment = $commentManager->findCommentById($id); if ($comment) { $commentManager->updateCommentStatus($comment, $status); $comments[] = $comment; } } } catch (\Exception $e) { return $this->showExceptionAsJson($e, $comment->getMessages()); } return $this->response->setJsonContent($comments); }
public function downAction($commentId) { if ($user = $this->getUserInfo()) { $userId = $user['id']; } else { return false; } $commentManage = new CommentManager(); $comment = $commentManage->findCommentById($commentId); $vote = $commentManage->createVote($comment, $userId, Votes::TYPE_DOWN); $commentManage->saveVote($vote, $comment); echo json_encode($vote); $this->view->disable(); }
/** * Checks if a comment belongs to a thread. Returns the comment if it does. * * @param ThreadInterface $thread Thread object * @param mixed $commentId Id of the comment. * * @return CommentInterface|null The comment. */ private function getValidCommentParent($thread, $commentId) { if (!empty($commentId)) { $commentManager = new CommentManager(); $comment = $commentManager->findCommentById($commentId); if (!$comment) { //todo throw exception exit(sprintf('Parent comment with identifier "%s" does not exist', $commentId)); // throw new NotFoundHttpException(sprintf('Parent comment with identifier "%s" does not exist', $commentId)); } // if ($comment->getThread() !== $thread) { // exit('Parent comment is not a comment of the given thread.'); //// throw new NotFoundHttpException('Parent comment is not a comment of the given thread.'); // } return $comment; } }
/** * * @SWG\Api( * path="/comments/{commentId}", * description="Comment related api", * produces="['application/json']", * @SWG\Operations( * @SWG\Operation( * method="GET", * summary="Find comment by ID", * notes="Returns a comment based on ID", * @SWG\Parameters( * @SWG\Parameter( * name="commentId", * description="ID of comment", * paramType="path", * required=true, * type="integer" * ) * ) * ) * ) * ) */ public function getAction() { $id = $this->dispatcher->getParam('id'); $commentManger = new Models\CommentManager(); $comment = $commentManger->findCommentById($id); if (!$comment) { throw new Exception\ResourceNotFoundException('Request commment not exist'); } $comment = $comment->dump(Entities\Comments::$defaultDump); return $this->response->setJsonContent($comment); }