tkt
This commit is contained in:
parent
432d7ba4de
commit
9e49da7775
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,39 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Edit Degree{% endblock %}
|
||||
{% block title %}Modifier un Diplôme{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Edit Degree</h1>
|
||||
<div class="container mx-auto p-6">
|
||||
<h1 class="text-4xl font-semibold text-gray-800 mb-6">Modifier le Diplôme</h1>
|
||||
|
||||
{{ include('degree/_form.html.twig', {'button_label': 'Update'}) }}
|
||||
<div class="bg-white shadow-md rounded-lg p-6">
|
||||
<h2 class="text-2xl font-medium text-gray-700 mb-6">Modifier les informations du diplôme</h2>
|
||||
|
||||
<a href="{{ path('app_degree_index') }}">back to list</a>
|
||||
{{ form_start(form) }}
|
||||
<div class="mb-4">
|
||||
<label for="degree_label" class="block text-lg font-medium text-gray-700 mb-2">Label du diplôme</label>
|
||||
<div class="mt-1">
|
||||
{{ 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'}}) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ include('degree/_delete_form.html.twig') }}
|
||||
<!-- Bouton de soumission -->
|
||||
<div class="mt-6">
|
||||
<button type="submit" class="bg-teal-500 hover:bg-teal-600 text-white py-2 px-4 rounded-full w-full">
|
||||
Mettre à jour
|
||||
</button>
|
||||
</div>
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
||||
<div class="mt-6 flex justify-between">
|
||||
<!-- Retour à la liste -->
|
||||
<a href="{{ path('app_degree_index') }}" class="text-teal-500 hover:text-teal-700 text-lg">
|
||||
<i class="fas fa-arrow-left"></i> Retour à la liste des diplômes
|
||||
</a>
|
||||
|
||||
<!-- Option de suppression du diplôme -->
|
||||
{{ include('degree/_delete_form.html.twig') }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -1,35 +1,57 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Degree index{% endblock %}
|
||||
{% block title %}List of Degrees{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Degree index</h1>
|
||||
<div class="container mx-auto p-6">
|
||||
<h1 class="text-3xl font-bold mb-4">Liste des Diplômes</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Label</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for degree in degrees %}
|
||||
<tr>
|
||||
<td>{{ degree.id }}</td>
|
||||
<td>{{ degree.label }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_degree_show', {'id': degree.id}) }}">show</a>
|
||||
<a href="{{ path('app_degree_edit', {'id': degree.id}) }}">edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="3">no records found</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Tableau des diplômes -->
|
||||
<div class="overflow-x-auto bg-white shadow-lg rounded-lg">
|
||||
<table class="min-w-full table-auto">
|
||||
<thead>
|
||||
<tr class="bg-gray-800 text-white">
|
||||
<th class="px-4 py-2 text-left">ID</th>
|
||||
<th class="px-4 py-2 text-left">Label</th>
|
||||
<th class="px-4 py-2 text-left">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for degree in degrees %}
|
||||
<tr class="border-b">
|
||||
<td class="px-4 py-2">{{ degree.id }}</td>
|
||||
<td class="px-4 py-2">{{ degree.label }}</td>
|
||||
<td class="px-4 py-2">
|
||||
<!-- Voir le diplôme -->
|
||||
<a href="{{ path('app_degree_show', {'id': degree.id}) }}" class="text-teal-500 hover:text-teal-700 mr-3">
|
||||
<i class="fas fa-eye"></i> Voir
|
||||
</a>
|
||||
|
||||
<a href="{{ path('app_degree_new') }}">Create new</a>
|
||||
<!-- Modifier le diplôme -->
|
||||
<a href="{{ path('app_degree_edit', {'id': degree.id}) }}" class="text-yellow-500 hover:text-yellow-700 mr-3">
|
||||
<i class="fas fa-edit"></i> Modifier
|
||||
</a>
|
||||
|
||||
<!-- Formulaire pour supprimer le diplôme -->
|
||||
<form method="post" action="{{ path('app_degree_delete', {'id': degree.id}) }}" style="display:inline;">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ degree.id) }}">
|
||||
<button type="submit" class="text-red-500 hover:text-red-700">
|
||||
<i class="fas fa-trash-alt"></i> Supprimer
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Lien pour ajouter un nouveau diplôme -->
|
||||
<div class="mt-4">
|
||||
<a href="{{ path('app_degree_new') }}" class="bg-teal-500 hover:bg-teal-600 text-white py-2 px-4 rounded-full">
|
||||
<i class="fas fa-plus-circle"></i> Ajouter un nouveau diplôme
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -1,37 +1,39 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Degrees{% endblock %}
|
||||
{% block title %}Détail du Diplôme{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>List of Degrees</h1>
|
||||
<div class="container mx-auto p-6">
|
||||
<h1 class="text-4xl font-semibold text-gray-800 mb-6">Détail du Diplôme</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Label</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for degree in degrees %}
|
||||
<tr>
|
||||
<td>{{ degree.id }}</td>
|
||||
<td>{{ degree.label }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_degree_show', {'id': degree.id}) }}" class="btn btn-info">View</a>
|
||||
<a href="{{ path('app_degree_edit', {'id': degree.id}) }}" class="btn btn-warning">Edit</a>
|
||||
<!-- Form for deleting a degree -->
|
||||
<form method="post" action="{{ path('app_degree_delete', {'id': degree.id}) }}" style="display:inline;">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ degree.id) }}">
|
||||
<button class="btn btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="bg-white shadow-md rounded-lg p-6">
|
||||
<table class="min-w-full">
|
||||
<tbody>
|
||||
<tr class="border-b">
|
||||
<th class="px-6 py-4 text-lg font-medium text-gray-700">ID</th>
|
||||
<td class="px-6 py-4 text-lg text-gray-900">{{ degree.id }}</td>
|
||||
</tr>
|
||||
<tr class="border-b">
|
||||
<th class="px-6 py-4 text-lg font-medium text-gray-700">Label</th>
|
||||
<td class="px-6 py-4 text-lg text-gray-900">{{ degree.label }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<a href="{{ path('app_degree_new') }}" class="btn btn-success">Add New Degree</a>
|
||||
<div class="mt-6 flex justify-between">
|
||||
<!-- Retour à la liste -->
|
||||
<a href="{{ path('app_degree_index') }}" class="text-teal-500 hover:text-teal-700 text-lg">
|
||||
<i class="fas fa-arrow-left"></i> Retour à la liste des diplômes
|
||||
</a>
|
||||
|
||||
<!-- Modifier le diplôme -->
|
||||
<a href="{{ path('app_degree_edit', {'id': degree.id}) }}" class="text-yellow-500 hover:text-yellow-700 text-lg">
|
||||
<i class="fas fa-edit"></i> Modifier ce diplôme
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Option de suppression du diplôme -->
|
||||
{{ include('degree/_delete_form.html.twig') }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user