Skip to content

Dhaythem #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions assets/assets/js/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 68 additions & 7 deletions src/Controller/FormationController.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,84 @@
<?php
namespace App\Controller;

use App\Entity\Formation;
use App\Form\FormationType;
use App\Repository\FormationRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

#[Route('/formations')]
final class FormationController extends AbstractController
{
#[Route('/back-office/formations', name: 'back.formations.index')]
public function index(): Response
#[Route(name: 'app_formations_index', methods: ['GET'])]
public function index(FormationRepository $formationRepository): Response
{
return $this->render('back_office/formations/index.html.twig', [
'controller_name' => 'FormationController',
return $this->render('formations/index.html.twig', [
'formations' => $formationRepository->findAll(),
]);
}

#[Route('/back-office/formations/add', name: 'back.formations.add')]
public function add(): Response
#[Route('/new', name: 'app_formations_new', methods: ['GET', 'POST'])]
public function new (Request $request, EntityManagerInterface $entityManager): Response
{
return $this->render('back_office/formations/add.html.twig');
$formation = new Formation();
$form = $this->createForm(FormationType::class, $formation);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($formation);
$entityManager->flush();

$this->addFlash('success', 'The training has been created successfully.');

return $this->redirectToRoute('app_formations_index', [], Response::HTTP_SEE_OTHER);
}

return $this->render('formations/new.html.twig', [
'formation' => $formation,
'form' => $form,
]);
}

#[Route('/{id}', name: 'app_formations_show', methods: ['GET'])]
public function show(Formation $formation): Response
{
return $this->render('formations/show.html.twig', [
'formation' => $formation,
]);
}

#[Route('/{id}/edit', name: 'app_formations_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Formation $formation, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(FormationType::class, $formation);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();

return $this->redirectToRoute('app_formations_index', [], Response::HTTP_SEE_OTHER);
}

return $this->render('formations/edit.html.twig', [
'formation' => $formation,
'form' => $form,
]);
}

#[Route('/{id}', name: 'app_formations_delete', methods: ['POST'])]
public function delete(Request $request, Formation $formation, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete' . $formation->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($formation);
$entityManager->flush();
}

$this->addFlash('success', 'The training has been deleted successfully.');

return $this->redirectToRoute('app_formations_index', [], Response::HTTP_SEE_OTHER);
}
}
80 changes: 0 additions & 80 deletions src/Controller/FormationControllerV2Controller.php

This file was deleted.

Loading