render('admin/index.html.twig', [ 'counters' => $counterRepository->findAll() ]); } #[Route('/new', name: 'app_admin_new', methods: ['GET', 'POST'])] public function new(Request $request, CounterManager $counterManager): Response { $counter = new Counter(); $form = $this->createForm(CounterType::class, $counter); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->countdownStateMachine->getMarking($counter); return $this->redirectToRoute('app_admin_index', [], Response::HTTP_SEE_OTHER); } return $this->render('admin/new.html.twig', [ 'counter' => $counter, 'form' => $form, ]); } #[Route('{id}/reset', name: 'app_admin_reset', methods: ['GET'])] public function reset(Counter $counter): RedirectResponse { try { $this->countdownStateMachine->apply($counter, Counter::TRANSITION_TO_READY); } catch (LogicException $e) { } return $this->redirectToRoute('app_admin_index'); } #[Route('/{id}/start', name: 'app_admin_start', methods: ['GET'])] public function start(Counter $counter): RedirectResponse { try { $this->countdownStateMachine->apply($counter, Counter::TRANSITION_TO_STARTED); } catch(LogicException $e) { } return $this->redirectToRoute('app_admin_index'); } #[Route('/{id}', name: 'app_admin_show', methods: ['GET'])] public function show(Counter $counter): Response { return $this->render('admin/show.html.twig', [ 'counter' => $counter, ]); } #[Route('/{id}/edit', name: 'app_admin_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Counter $counter, EntityManagerInterface $entityManager): Response { $form = $this->createForm(CounterType::class, $counter); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->flush(); return $this->redirectToRoute('app_admin_index', [], Response::HTTP_SEE_OTHER); } return $this->render('admin/edit.html.twig', [ 'counter' => $counter, 'form' => $form, ]); } #[Route('/{id}', name: 'app_admin_delete', methods: ['POST'])] public function delete(Request $request, Counter $counter, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$counter->getId(), $request->request->get('_token'))) { $entityManager->remove($counter); $entityManager->flush(); } return $this->redirectToRoute('app_admin_index', [], Response::HTTP_SEE_OTHER); } }