render('representation/index.html.twig', [ 'representations' => $representationRepository->findAll(), ]); } #[Route('/new', name: '_new', methods: ['GET', 'POST'])] public function new(Request $request, EntityManagerInterface $entityManager, RideRepository $rideRepository): Response { $representation = new Representation(); $form = $this->createForm(RepresentationType::class, $representation); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $ride = $rideRepository->find($representation->getRide()); $newCount = $ride->getCount() + $representation->getCount(); $ride->setCount($newCount); $entityManager->persist($representation); $entityManager->flush(); // return $this->redirectToRoute('representation_index', [], Response::HTTP_SEE_OTHER); } return $this->render('representation/new.html.twig', [ 'representation' => $representation, 'form' => $form, ]); } #[Route('/{employee}', name: '_show', methods: ['GET'])] public function show(Representation $representation): Response { return $this->render('representation/show.html.twig', [ 'representation' => $representation, ]); } #[Route('/{employee}/edit', name: '_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Representation $representation, EntityManagerInterface $entityManager): Response { $form = $this->createForm(RepresentationType::class, $representation); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->flush(); return $this->redirectToRoute('representation_index', [], Response::HTTP_SEE_OTHER); } return $this->render('representation/edit.html.twig', [ 'representation' => $representation, 'form' => $form, ]); } #[Route('/{employee}', name: '_delete', methods: ['POST'])] public function delete(Request $request, Representation $representation, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$representation->getEmployee(), $request->getPayload()->getString('_token'))) { $entityManager->remove($representation); $entityManager->flush(); } return $this->redirectToRoute('representation_index', [], Response::HTTP_SEE_OTHER); } }