/** * Retrieves a specific comment * * @ApiDoc( * resource=true, * requirements={ * {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="comment id"} * }, * output={"class"="Sonata\NewsBundle\Model\Comment", "groups"="sonata_api_read"}, * statusCodes={ * 200="Returned when successful", * 404="Returned when comment is not found" * } * ) * * @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true) * * @param $id * * @return Comment * @throws NotFoundHttpException */ public function getCommentAction($id) { $comment = $this->commentManager->findOneBy(array('id' => $id)); if (null === $comment) { throw new NotFoundHttpException(sprintf("Comment (%d) not found", $id)); } return $comment; }
/** * {@inheritdoc} */ public function execute(BlockContextInterface $blockContext, Response $response = null) { $criteria = array('mode' => $blockContext->getSetting('mode')); $parameters = array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'pager' => $this->manager->getPager($criteria, 1, $blockContext->getSetting('number')), 'admin_pool' => $this->adminPool); if ($blockContext->getSetting('mode') === 'admin') { return $this->renderPrivateResponse($blockContext->getTemplate(), $parameters, $response); } return $this->renderResponse($blockContext->getTemplate(), $parameters, $response); }
/** * Updates a comment. * * @ApiDoc( * requirements={ * {"name"="postId", "dataType"="integer", "requirement"="\d+", "description"="post identifier"}, * {"name"="commentId", "dataType"="integer", "requirement"="\d+", "description"="comment identifier"} * }, * input={"class"="sonata_news_api_form_comment", "name"="", "groups"={"sonata_api_write"}}, * output={"class"="Sonata\NewsBundle\Model\Comment", "groups"={"sonata_api_read"}}, * statusCodes={ * 200="Returned when successful", * 400="Returned when an error has occurred while comment update", * 404="Returned when unable to find comment" * } * ) * * @Route(requirements={"_format"="json|xml"}) * * @param int $postId A post identifier * @param int $commentId A comment identifier * @param Request $request A Symfony request * * @return Comment * * @throws NotFoundHttpException * @throws HttpException */ public function putPostCommentsAction($postId, $commentId, Request $request) { $post = $this->getPost($postId); if (!$post->isCommentable()) { throw new HttpException(403, sprintf('Post (%d) not commentable', $postId)); } $comment = $this->commentManager->find($commentId); if (null === $comment) { throw new NotFoundHttpException(sprintf('Comment (%d) not found', $commentId)); } $comment->setPost($post); $form = $this->formFactory->createNamed(null, 'sonata_news_api_form_comment', $comment, array('csrf_protection' => false)); $form->bind($request); if ($form->isValid()) { $comment = $form->getData(); $this->commentManager->save($comment); $view = \FOS\RestBundle\View\View::create($comment); $serializationContext = SerializationContext::create(); $serializationContext->setGroups(array('sonata_api_read')); $serializationContext->enableMaxDepthChecks(); $view->setSerializationContext($serializationContext); return $view; } return $form; }
/** * Returns a comment entity instance * * @param integer $id A comment identifier * * @return Comment * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function getComment($id) { $comment = $this->commentManager->find($id); if (null === $comment) { throw new NotFoundHttpException(sprintf("Comment (%d) not found", $id)); } return $comment; }
/** * Update the count comment. */ private function updateCountsComment() { $this->commentManager->updateCommentsCount(); }