/** * Show action * * @param Solution $solution Solution * @param Request $request Request * * @return Response * * @Method("GET") * @Route("/{id}/show", name="solution_show") * @ParamConverter("solution", class="ApplicationCoreBundle:Solution") */ public function showAction(Solution $solution, Request $request) { $solutionRatingRepository = $this->getDoctrine()->getRepository('ApplicationCoreBundle:SolutionRating'); $solutionRating = $solutionRatingRepository->findOneBySolution($solution); if (!$solutionRating instanceof SolutionRating) { $solutionRating = new SolutionRating(); $solutionRating->setSolution($solution); } $ratingForm = $this->createForm(new SolutionRatingType(), $solutionRating); return $this->render('ApplicationCoreBundle:Solution:show.html.twig', ['solution' => $solution, 'rating_form' => $ratingForm->createView()]); }
/** * Show task * * @param Task $task Task * * @return Response * * @Method({"GET"}) * @Route("/{id}", name="show_task") * @ParamConverter("task", class="ApplicationCoreBundle:Task") */ public function showAction(Task $task) { /** @var \Application\Bundle\CoreBundle\Repository\SolutionRepository $solutionRepository */ $solutionRepository = $this->getDoctrine()->getRepository('ApplicationCoreBundle:Solution'); /** @var array|Solution[] $solutions */ $solutions = $solutionRepository->findBy(['task' => $task]); $ratingsForms = []; foreach ($solutions as $solution) { $data = new SolutionRating(); $data->setSolution($solution); $ratingsForms[] = $this->get('form.factory')->createNamed('solution_rating_' . $solution->getId(), new SolutionRatingType(), $data)->createView(); } $solution = $solutionRepository->getSolutionByUserAndTask($task, $this->getUser()); return $this->render('ApplicationCoreBundle:Task:show.html.twig', ['task' => $task, 'ratings_forms' => $ratingsForms, 'is_user_solution' => is_null($solution) ? false : true, 'solution' => $solution]); }