diff --git a/src/Controller/DegreeController.php b/src/Controller/DegreeController.php index 90cebd4..28c9b5e 100644 --- a/src/Controller/DegreeController.php +++ b/src/Controller/DegreeController.php @@ -2,6 +2,7 @@ namespace App\Controller; +// Importations use App\Entity\Degree; use App\Form\DegreeType; use App\Repository\DegreeRepository; @@ -9,7 +10,7 @@ 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; +use Symfony\Component\Routing\Annotation\Route; #[Route('/degree')] final class DegreeController extends AbstractController @@ -17,8 +18,13 @@ final class DegreeController extends AbstractController #[Route(name: 'app_degree_index', methods: ['GET'])] public function index(DegreeRepository $degreeRepository): Response { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + // Récupère tous les diplômes + $degrees = $degreeRepository->findAll(); + + // Affiche la vue avec les diplômes return $this->render('degree/index.html.twig', [ - 'degrees' => $degreeRepository->findAll(), + 'degrees' => $degrees, ]); } @@ -30,21 +36,24 @@ final class DegreeController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + // Sauvegarde le nouveau diplôme dans la base $entityManager->persist($degree); $entityManager->flush(); + // Redirection vers la liste des diplômes return $this->redirectToRoute('app_degree_index', [], Response::HTTP_SEE_OTHER); } return $this->render('degree/new.html.twig', [ 'degree' => $degree, - 'form' => $form, + 'form' => $form->createView(), ]); } #[Route('/{id}', name: 'app_degree_show', methods: ['GET'])] public function show(Degree $degree): Response { + // Affiche les détails d'un diplôme spécifique return $this->render('degree/show.html.twig', [ 'degree' => $degree, ]); @@ -53,27 +62,28 @@ final class DegreeController extends AbstractController #[Route('/{id}/edit', name: 'app_degree_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Degree $degree, EntityManagerInterface $entityManager): Response { + // Création du formulaire de modification $form = $this->createForm(DegreeType::class, $degree); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + // Sauvegarde des modifications dans la base $entityManager->flush(); + // Redirection vers la liste des diplômes après modification return $this->redirectToRoute('app_degree_index', [], Response::HTTP_SEE_OTHER); } return $this->render('degree/edit.html.twig', [ 'degree' => $degree, - 'form' => $form, + 'form' => $form->createView(), ]); } #[Route('/{id}', name: 'app_degree_delete', methods: ['POST'])] public function delete(Request $request, Degree $degree, EntityManagerInterface $entityManager): Response { - // Vérification du token CSRF pour la sécurité - if ($this->isCsrfTokenValid('delete'.$degree->getId(), $request->request->get('_token'))) { - // Suppression du diplôme + if ($this->isCsrfTokenValid('delete' . $degree->getId(), $request->request->get('_token'))) { $entityManager->remove($degree); $entityManager->flush(); } @@ -81,4 +91,6 @@ final class DegreeController extends AbstractController return $this->redirectToRoute('app_degree_index', [], Response::HTTP_SEE_OTHER); } + } + diff --git a/templates/degree/edit.html.twig b/templates/degree/edit.html.twig index 73e9f09..48cd886 100644 --- a/templates/degree/edit.html.twig +++ b/templates/degree/edit.html.twig @@ -1,13 +1,39 @@ {% extends 'base.html.twig' %} -{% block title %}Edit Degree{% endblock %} +{% block title %}Modifier un Diplôme{% endblock %} {% block body %} -

Edit Degree

+
+

Modifier le Diplôme

- {{ include('degree/_form.html.twig', {'button_label': 'Update'}) }} +
+

Modifier les informations du diplôme

- back to list + {{ form_start(form) }} +
+ +
+ {{ form_widget(form.label, {'attr': {'class': 'block w-full p-2 border rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-teal-500'}}) }} +
+
- {{ include('degree/_delete_form.html.twig') }} + +
+ +
+ {{ form_end(form) }} + + +
+ + + Retour à la liste des diplômes + + + + {{ include('degree/_delete_form.html.twig') }} +
+
{% endblock %} diff --git a/templates/degree/index.html.twig b/templates/degree/index.html.twig index 67172f7..670e9c5 100644 --- a/templates/degree/index.html.twig +++ b/templates/degree/index.html.twig @@ -1,35 +1,57 @@ {% extends 'base.html.twig' %} -{% block title %}Degree index{% endblock %} +{% block title %}List of Degrees{% endblock %} {% block body %} -

Degree index

+
+

Liste des Diplômes

- - - - - - - - - - {% for degree in degrees %} - - - - - - {% else %} - - - - {% endfor %} - -
IdLabelactions
{{ degree.id }}{{ degree.label }} - show - edit -
no records found
+ +
+ + + + + + + + + + {% for degree in degrees %} + + + + + + {% endfor %} + +
IDLabelActions
{{ degree.id }}{{ degree.label }} + + + Voir + - Create new + + + Modifier + + + +
+ + + +
+
+
+ + + +
{% endblock %} diff --git a/templates/degree/show.html.twig b/templates/degree/show.html.twig index 41d349d..a660d66 100644 --- a/templates/degree/show.html.twig +++ b/templates/degree/show.html.twig @@ -1,37 +1,39 @@ {% extends 'base.html.twig' %} -{% block title %}Degrees{% endblock %} +{% block title %}Détail du Diplôme{% endblock %} {% block body %} -

List of Degrees

+
+

Détail du Diplôme

- - - - - - - - - - {% for degree in degrees %} - - - - - - {% endfor %} - -
IdLabelActions
{{ degree.id }}{{ degree.label }} - View - Edit - -
- - - -
-
+
+ + + + + + + + + + + +
ID{{ degree.id }}
Label{{ degree.label }}
+
- Add New Degree + + + + {{ include('degree/_delete_form.html.twig') }} +
{% endblock %}