/** * @Template() * @ParamConverter("user", class="CoreUserBundle:User", options={"mapping":{"user_username" = "username"}}) * @ParamConverter("idea", class="AppBundle:Idea", options={"mapping":{"idea_slug" = "slug"}}) */ public function viewAction(Request $request, User $user, Idea $idea, $comment_id) { $doctrine = $this->getDoctrine(); $security = $this->get('security.authorization_checker'); $formService = $this->get('core.base.form'); $repository = $doctrine->getRepository('AppBundle:Comment'); $loggedUser = $security->isGranted('IS_AUTHENTICATED_FULLY') ? $this->getUser()->getId() : null; $hashUser = $formService->getUserHash($request); $comment = $repository->getById($comment_id, $loggedUser, $hashUser); $comment['comment_type'] = Comment::types[$comment['comment_type']]; if ($idea->getUserId() !== $user->getId() || $comment['idea_id'] !== $idea->getId()) { throw new $this->createNotFoundException(); } $viewData = []; $viewData['ideaUser'] = $user; $viewData['idea'] = $idea; $viewData['comment'] = $comment; $viewData['userHash'] = $hashUser; if ($comment['user_id'] && $this->getUser() && $comment['user_id'] == $this->getUser()->getId() || $security->isGranted('ROLE_MANAGER')) { $comment = $repository->find($comment['comment_id']); $formData = $request->request->get(CommentType::name); $responseData = $this->get('app.model.comment')->edit($formData, $comment); $viewData['commentForm'] = $responseData['form']->createView(); if ($responseData['valid']) { return $this->redirectToRoute('app_comment_view', ['user_username' => $user->getUsername(), 'idea_slug' => $idea->getSlug(), 'comment_id' => $responseData['embedded']['comment']['id']]); } } return $viewData; }