set admin V3 User
This commit is contained in:
@@ -33,6 +33,53 @@ class AdminController extends AbstractController
|
||||
'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'])]
|
||||
public function import(Request $request, EntityManagerInterface $em): Response
|
||||
{
|
||||
@@ -44,30 +91,32 @@ class AdminController extends AbstractController
|
||||
$participant = new Participant();
|
||||
$participant->setNom($row[0]);
|
||||
$participant->setPrenom($row[1]);
|
||||
$participant->setTelephone($row[2]);
|
||||
$participant->setEmail($row[3]);
|
||||
$participant->setAdministrateur((bool)$row[4]);
|
||||
$participant->setActif((bool)$row[5]);
|
||||
$participant->setRoles(explode('|', $row[6]));
|
||||
$participant->setPassword(password_hash($row[7], PASSWORD_BCRYPT));
|
||||
$participant->setPseudo($row[2]);
|
||||
$participant->setTelephone($row[3]);
|
||||
$participant->setEmail($row[4]);
|
||||
$participant->setAdministrateur((bool)$row[5]);
|
||||
$participant->setActif((bool)$row[6]);
|
||||
$participant->setRoles(explode('|', $row[7]));
|
||||
$participant->setPassword(password_hash($row[8], PASSWORD_BCRYPT));
|
||||
$em->persist($participant);
|
||||
}
|
||||
$em->flush();
|
||||
}
|
||||
return $this->redirectToRoute('participant_index');
|
||||
return $this->redirectToRoute('app_adminUser');
|
||||
}
|
||||
#[Route('/admin/user/export', name: 'participant_export')]
|
||||
public function export(ParticipantRepository $participantRepository): Response
|
||||
{
|
||||
$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) {
|
||||
$csv .= sprintf(
|
||||
"%s,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
"%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
$participant->getNom(),
|
||||
$participant->getPrenom(),
|
||||
$participant->getPseudo(),
|
||||
$participant->getTelephone(),
|
||||
$participant->getMail(),
|
||||
$participant->getEmail(),
|
||||
$participant->isAdministrateur() ? '1' : '0',
|
||||
$participant->isActif() ? '1' : '0',
|
||||
implode('|', $participant->getRoles()),
|
||||
@@ -77,7 +126,6 @@ class AdminController extends AbstractController
|
||||
$response = new Response($csv);
|
||||
$response->headers->set('Content-Type', 'text/csv');
|
||||
$response->headers->set('Content-Disposition', 'attachment;filename="participants.csv"');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user