em = $em; $this->stateRepository = $stateRepository; $this->broadcastRepository = $broadcastRepository; $this->investigationRepository = $investigationRepository; } #[Route('/index', name: 'app_broadcast_index')] public function index(): Response { $investigations = $this->investigationRepository->findInvestigationAdminValidated($this->getUser()); $broadcasts = $this->broadcastRepository->findByUser($this->getUser()); return $this->render('broadcast/index.html.twig', [ 'investigations' => $investigations, 'broadcasts' => $broadcasts, ]); } #[Route('/add/{id}', name: 'app_broadcast_add')] public function add(Request $request, Investigation $investigation): Response { $form = $this->createForm(BroadcastType::class); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $broadcast = $form->getData(); $broadcast->setInvestigation($investigation); $broadcast->setCreateBy($this->getUser()); $broadcast->setCost(150); $this->em->persist($broadcast); $this->em->flush(); $investigation->setLastState(31); $this->em->persist($investigation); $this->em->flush(); $this->stateRepository->addState($investigation, 3, 1, $broadcast); $this->addFlash('danger', " Well done! You successfully read this important alert message."); return $this->redirectToRoute('app_broadcast_index'); } return $this->render('broadcast/add.html.twig', [ 'form' => $form->createView(), 'investigation' => $investigation, ]); } }