merge
This commit is contained in:
@@ -3,8 +3,10 @@
|
|||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Participant;
|
use App\Entity\Participant;
|
||||||
|
use App\Entity\Site;
|
||||||
use App\Entity\Ville;
|
use App\Entity\Ville;
|
||||||
use App\Repository\ParticipantRepository;
|
use App\Repository\ParticipantRepository;
|
||||||
|
use App\Repository\SiteRepository;
|
||||||
use App\Repository\VilleRepository;
|
use App\Repository\VilleRepository;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@@ -33,6 +35,53 @@ class AdminController extends AbstractController
|
|||||||
'controller_name' => 'AdminController',
|
'controller_name' => 'AdminController',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
#[Route('/admin/user/disable/{id}', name: 'app_adminUserDisable')]
|
||||||
|
public function disableParticipant(string $id, ParticipantRepository $participantRepository, EntityManagerInterface $entityManager): RedirectResponse
|
||||||
|
{
|
||||||
|
// Récupérer le participant à partir de l'id
|
||||||
|
$participant = $participantRepository->find($id);
|
||||||
|
|
||||||
|
// Vérifier si le participant existe
|
||||||
|
if (!$participant) {
|
||||||
|
$this->addFlash('error', 'Le participant demandé n\'existe pas.');
|
||||||
|
return $this->redirectToRoute('app_adminUser'); // Redirigez vers une liste ou une autre page
|
||||||
|
}
|
||||||
|
|
||||||
|
// Désactiver le participant (par exemple, définir une propriété "isActive" à false)
|
||||||
|
if ($participant->isActif()){
|
||||||
|
$participant->setActif(false);
|
||||||
|
}else{
|
||||||
|
$participant->setActif(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sauvegarder la modification en base de données
|
||||||
|
$entityManager->persist($participant);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
// Ajouter un message de succès et rediriger
|
||||||
|
$this->addFlash('success', 'Participant désactivé avec succès.');
|
||||||
|
return $this->redirectToRoute('app_adminUser');
|
||||||
|
}
|
||||||
|
#[Route('/admin/user/delete/{id}', name: 'app_adminUserDelete')]
|
||||||
|
public function deleteUser(string $id, ParticipantRepository $participantRepository, EntityManagerInterface $entityManager): RedirectResponse
|
||||||
|
{
|
||||||
|
// Récupérer l'utilisateur ou le participant à partir de l'id
|
||||||
|
$participant = $participantRepository->find($id);
|
||||||
|
|
||||||
|
// Vérifier si l'utilisateur existe
|
||||||
|
if (!$participant) {
|
||||||
|
$this->addFlash('error', 'L\'utilisateur demandé n\'existe pas.');
|
||||||
|
return $this->redirectToRoute('app_adminUser'); // Redirigez vers une liste ou une autre page
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supprimer l'utilisateur
|
||||||
|
$entityManager->remove($participant);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
// Ajouter un message de succès et rediriger
|
||||||
|
$this->addFlash('success', 'Utilisateur supprimé avec succès.');
|
||||||
|
return $this->redirectToRoute('app_adminUser'); // Redirigez vers la liste des utilisateurs
|
||||||
|
}
|
||||||
#[Route('/admin/user/import', name: 'participant_import', methods: ['POST'])]
|
#[Route('/admin/user/import', name: 'participant_import', methods: ['POST'])]
|
||||||
public function import(Request $request, EntityManagerInterface $em): Response
|
public function import(Request $request, EntityManagerInterface $em): Response
|
||||||
{
|
{
|
||||||
@@ -44,30 +93,32 @@ class AdminController extends AbstractController
|
|||||||
$participant = new Participant();
|
$participant = new Participant();
|
||||||
$participant->setNom($row[0]);
|
$participant->setNom($row[0]);
|
||||||
$participant->setPrenom($row[1]);
|
$participant->setPrenom($row[1]);
|
||||||
$participant->setTelephone($row[2]);
|
$participant->setPseudo($row[2]);
|
||||||
$participant->setEmail($row[3]);
|
$participant->setTelephone($row[3]);
|
||||||
$participant->setAdministrateur((bool)$row[4]);
|
$participant->setEmail($row[4]);
|
||||||
$participant->setActif((bool)$row[5]);
|
$participant->setAdministrateur((bool)$row[5]);
|
||||||
$participant->setRoles(explode('|', $row[6]));
|
$participant->setActif((bool)$row[6]);
|
||||||
$participant->setPassword(password_hash($row[7], PASSWORD_BCRYPT));
|
$participant->setRoles(explode('|', $row[7]));
|
||||||
|
$participant->setPassword(password_hash($row[8], PASSWORD_BCRYPT));
|
||||||
$em->persist($participant);
|
$em->persist($participant);
|
||||||
}
|
}
|
||||||
$em->flush();
|
$em->flush();
|
||||||
}
|
}
|
||||||
return $this->redirectToRoute('participant_index');
|
return $this->redirectToRoute('app_adminUser');
|
||||||
}
|
}
|
||||||
#[Route('/admin/user/export', name: 'participant_export')]
|
#[Route('/admin/user/export', name: 'participant_export')]
|
||||||
public function export(ParticipantRepository $participantRepository): Response
|
public function export(ParticipantRepository $participantRepository): Response
|
||||||
{
|
{
|
||||||
$participants = $participantRepository->findAll();
|
$participants = $participantRepository->findAll();
|
||||||
$csv = "Nom,Prénom,Téléphone,Email,Administrateur,Actif,Rôles,Password\n";
|
$csv = "Nom,Prénom,Pseudo,Téléphone,Email,Administrateur,Actif,Rôles,Password\n";
|
||||||
foreach ($participants as $participant) {
|
foreach ($participants as $participant) {
|
||||||
$csv .= sprintf(
|
$csv .= sprintf(
|
||||||
"%s,%s,%s,%s,%s,%s,%s,%s\n",
|
"%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
|
||||||
$participant->getNom(),
|
$participant->getNom(),
|
||||||
$participant->getPrenom(),
|
$participant->getPrenom(),
|
||||||
|
$participant->getPseudo(),
|
||||||
$participant->getTelephone(),
|
$participant->getTelephone(),
|
||||||
$participant->getMail(),
|
$participant->getEmail(),
|
||||||
$participant->isAdministrateur() ? '1' : '0',
|
$participant->isAdministrateur() ? '1' : '0',
|
||||||
$participant->isActif() ? '1' : '0',
|
$participant->isActif() ? '1' : '0',
|
||||||
implode('|', $participant->getRoles()),
|
implode('|', $participant->getRoles()),
|
||||||
@@ -77,7 +128,6 @@ class AdminController extends AbstractController
|
|||||||
$response = new Response($csv);
|
$response = new Response($csv);
|
||||||
$response->headers->set('Content-Type', 'text/csv');
|
$response->headers->set('Content-Type', 'text/csv');
|
||||||
$response->headers->set('Content-Disposition', 'attachment;filename="participants.csv"');
|
$response->headers->set('Content-Disposition', 'attachment;filename="participants.csv"');
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +141,7 @@ class AdminController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
#[Route('/admin/city/add', name: 'app_adminCityAdd', methods: ['POST'])]
|
#[Route('/admin/city/add', name: 'app_adminCityAdd', methods: ['POST'])]
|
||||||
public function adminCityAdd(Request $request, EntityManagerInterface $entityManager, VilleRepository $villeRepository): RedirectResponse
|
public function adminCityAdd(Request $request, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Récupérer les données envoyées par le formulaire
|
// Récupérer les données envoyées par le formulaire
|
||||||
@@ -118,11 +168,11 @@ class AdminController extends AbstractController
|
|||||||
return $this->redirectToRoute('app_adminCity');
|
return $this->redirectToRoute('app_adminCity');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[Route('/admin/city/delete', name: 'app_adminCityDelete')]
|
#[Route('/admin/city/delete/{id}', name: 'app_adminCityDelete')]
|
||||||
public function adminCityDelete(String $id, EntityManagerInterface $entityManager): RedirectResponse
|
public function adminCityDelete(string $id, VilleRepository $villeRepository, EntityManagerInterface $entityManager): RedirectResponse
|
||||||
{
|
{
|
||||||
// Récupérer la ville à supprimer
|
// Récupérer la ville à supprimer
|
||||||
$city = $entityManager->getRepository(Ville::class)->find($id);
|
$city = $villeRepository->find($id);
|
||||||
|
|
||||||
// Vérifier si la ville existe
|
// Vérifier si la ville existe
|
||||||
if (!$city) {
|
if (!$city) {
|
||||||
@@ -139,4 +189,40 @@ class AdminController extends AbstractController
|
|||||||
$this->addFlash('success', 'Ville supprimée avec succès.');
|
$this->addFlash('success', 'Ville supprimée avec succès.');
|
||||||
return $this->redirectToRoute('app_adminCity');
|
return $this->redirectToRoute('app_adminCity');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gestion des sites
|
||||||
|
#[Route('/admin/site', name: 'app_adminSite')]
|
||||||
|
public function adminSite(SiteRepository $siteRepository): Response
|
||||||
|
{
|
||||||
|
return $this->render('admin/site.html.twig', [
|
||||||
|
'sites' => $siteRepository->findAll(),
|
||||||
|
'controller_name' => 'AdminController',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
#[Route('/admin/site/add', name: 'app_adminSiteAdd', methods: ['POST'])]
|
||||||
|
public function adminSiteAdd(Request $request, EntityManagerInterface $entityManager): Response
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Récupérer les données envoyées par le formulaire
|
||||||
|
$nom = $request->request->get('nom');
|
||||||
|
|
||||||
|
// Vérifier que les champs ne sont pas vides
|
||||||
|
if (!$nom) {
|
||||||
|
return new Response('Tous les champs sont requis.', Response::HTTP_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Créer une nouvelle entité City et définir ses propriétés
|
||||||
|
$site = new Site();
|
||||||
|
$site->setNom($nom);
|
||||||
|
|
||||||
|
// Enregistrer la ville dans la base de données
|
||||||
|
$entityManager->persist($site);
|
||||||
|
$entityManager->flush();
|
||||||
|
$this->addFlash('success', "Site ajouté !");
|
||||||
|
return $this->redirectToRoute('app_adminSite');
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$this->addFlash('error', "Erreur : " . $e->getMessage());
|
||||||
|
return $this->redirectToRoute('app_adminSite');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="#" class="block text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded">
|
<a href="{{ path('app_adminSite') }}" class="block text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded">
|
||||||
📍 Sites
|
📍 Sites
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
81
templates/admin/site.html.twig
Normal file
81
templates/admin/site.html.twig
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{% extends 'main/base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}📣 Sortie.com Admin Site 🔊{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="flex">
|
||||||
|
{% include 'admin/sidebar.html.twig' %}
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<div class="ml-64 p-8 w-full">
|
||||||
|
<h1 class="text-2xl font-semibold mb-4">Gestion des sites</h1>
|
||||||
|
|
||||||
|
<!-- Actions: Ajouter -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<!-- Bouton pour ouvrir la modale -->
|
||||||
|
<button id="openModal" class="inline-block bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-700">
|
||||||
|
Ajouter un site
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Participants Table -->
|
||||||
|
<div class="overflow-x-auto bg-white rounded shadow">
|
||||||
|
<table class="min-w-full bg-white divide-y divide-gray-200">
|
||||||
|
<thead class="bg-gray-50">
|
||||||
|
<tr>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Site</th>
|
||||||
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-gray-200">
|
||||||
|
{% for site in sites %}
|
||||||
|
<tr>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ site.nom }}</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||||
|
<a href="{{ path('app_adminSiteDelete', {'id': city.idSite}) }}" class="text-red-600 hover:text-red-900 ml-4">Supprimer</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="8" class="px-6 py-4 text-center text-gray-500">Aucun site trouvée</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modale pour ajouter une ville -->
|
||||||
|
<div id="siteModal" class="fixed inset-0 z-50 hidden bg-gray-900 bg-opacity-50">
|
||||||
|
<div class="flex justify-center items-center min-h-screen">
|
||||||
|
<div class="bg-white p-6 rounded shadow-md w-1/3">
|
||||||
|
<h2 class="text-xl font-semibold mb-4">Ajouter un site</h2>
|
||||||
|
<form id="addSiteForm" method="POST" action="{{ path('app_adminSiteAdd') }}">
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="nom" class="block text-sm font-medium text-gray-700">Nom</label>
|
||||||
|
<input id="nom" name="nom" type="text" class="mt-1 block w-full px-4 py-2 border rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-700">Ajouter</button>
|
||||||
|
<button type="button" id="closeModal" class="ml-2 bg-gray-500 text-white px-4 py-2 rounded hover:bg-gray-700">Annuler</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Ouvrir la modale
|
||||||
|
document.getElementById('openModal').addEventListener('click', function() {
|
||||||
|
document.getElementById('siteModal').classList.remove('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fermer la modale
|
||||||
|
document.getElementById('closeModal').addEventListener('click', function() {
|
||||||
|
document.getElementById('siteModal').classList.add('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -41,6 +41,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom</th>
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Prénom</th>
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Prénom</th>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Pseudo</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Téléphone</th>
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Téléphone</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Administrateur</th>
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Administrateur</th>
|
||||||
@@ -54,8 +55,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.nom }}</td>
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.nom }}</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.prenom }}</td>
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.prenom }}</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.pseudo }}</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.telephone }}</td>
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.telephone }}</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.mail }}</td>
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.email }}</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||||
{{ participant.administrateur ? 'Oui' : 'Non' }}
|
{{ participant.administrateur ? 'Oui' : 'Non' }}
|
||||||
</td>
|
</td>
|
||||||
@@ -66,8 +68,10 @@
|
|||||||
{{ participant.roles|join(', ') }}
|
{{ participant.roles|join(', ') }}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||||
<a href="{{ path('participant_edit', {'id': participant.id}) }}" class="text-indigo-600 hover:text-indigo-900">Modifier</a>
|
<a href="{{ path('app_adminUserDisable', {'id': participant.idParticipant}) }}" class="text-indigo-600 hover:text-indigo-900">
|
||||||
<a href="{{ path('participant_delete', {'id': participant.id}) }}" class="text-red-600 hover:text-red-900 ml-4">Supprimer</a>
|
{{ participant.actif ? 'Activer' : 'Désactiver' }}
|
||||||
|
</a>
|
||||||
|
<a href="{{ path('app_adminUserDelete', {'id': participant.idParticipant}) }}" class="text-red-600 hover:text-red-900 ml-4">Supprimer</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
Reference in New Issue
Block a user