entityManager = $entityManager; } /** * @Route("/", name="index", methods={"GET"}) * @param DonRepository $donRepository * PaginatorInterface $paginator * Request $request */ public function index(DonRepository $donRepository, PaginatorInterface $paginator, Request $request): Response { $els = $paginator->paginate( $donRepository->createQueryBuilder('a')->getQuery(), $request->query->getInt('page', 1), 10 ); return $this->render('admin/crud/index.html.twig', [ 'els'=>$els, 'paginator'=>true, 'search'=>true, 'class'=> Don::class, 'route'=> 'admin_app_don', 'breadcrumb'=>[ [ 'text'=>'tous les éléments' ] ], 'fields' => [ 'Id' => 'Id', 'GiftNumber' => 'GiftNumber', 'Categorie' => 'DonCat', 'Donneur' => 'Donneur', ], 'title' => 'Tous les élements', 'add_button_label'=>'Ajouter un élément' ]); } /** * @Route("/new", name="new", methods={"GET","POST"}) * @param Request $request * @param DonHandler $donHandler * @param Tools $tools * @return Response */ public function new(Request $request, Tools $tools, DonHandler $donHandler): Response { $don = new Don(); $form = $this->createForm(DonType::class, $don); if ($donHandler->new($form, $request)) { return $this->redirectToRoute('admin_app_don_index'); } return $this->render('admin/crud/_form.html.twig', [ 'form'=>$form->createView(), 'el'=>$don, 'button_label'=>'Créer', 'route'=>'admin_app_don', 'title'=>'Ajouter un élément', 'breadcrumb'=>[ [ 'route'=>'admin_app_don_index', 'text'=>'tous les éléments' ], [ 'text'=>'ajouter un élément' ] ], ]); } /** * @Route("/edit/{id}", name="edit") * @param Request $request * @param Don $don * @param Tools $tools * @return Response */ public function edit(Request $request, Don $don, Tools $tools, DonHandler $donHandler): Response { $form = $this->createForm(DonType::class, $don); if ($donHandler->edit($form, $request)) { return $this->redirectToRoute('admin_app_don_edit', ['id'=>$don->getId()]); } return $this->render('admin/crud/_form.html.twig', [ 'el' => $don, 'route'=> 'admin_app_don', 'form' => $form->createView(), 'button_label' => 'Mettre à jour', 'title' => 'Edition', 'breadcrumb'=>[ [ 'route'=>'admin_app_don_index', 'text'=>'dons' ], [ 'text'=>'édition ' ] ], ]); } /** * @Route("/{id}", name="delete", methods={"DELETE"}) * @param Request $request * @return Response */ public function delete(Request $request,Don $don): Response { if ($this->isCsrfTokenValid('delete'.$don->getId(), $request->request->get('_token'))) { $this->entityManager->remove($don); $this->entityManager->flush(); } return $this->redirectToRoute('admin_app_don_index'); } }