set user site

This commit is contained in:
jleroy2023
2024-11-21 10:18:52 +01:00
parent e84adff833
commit 131bde64c2
2 changed files with 39 additions and 18 deletions

View File

@@ -9,7 +9,6 @@ use App\Entity\Ville;
use App\Repository\ParticipantRepository; use App\Repository\ParticipantRepository;
use App\Repository\SiteRepository; use App\Repository\SiteRepository;
use App\Repository\VilleRepository; use App\Repository\VilleRepository;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -26,8 +25,10 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
class AdminController extends AbstractController class AdminController extends AbstractController
{ {
private ParticipantRepository $participantRepository; private ParticipantRepository $participantRepository;
public function __construct(ParticipantRepository $participantRepository){ private SiteRepository $siteRepository;
public function __construct(ParticipantRepository $participantRepository, SiteRepository $siteRepository){
$this->participantRepository = $participantRepository; $this->participantRepository = $participantRepository;
$this->siteRepository = $siteRepository;
} }
#[Route('/admin', name: 'app_admin')] #[Route('/admin', name: 'app_admin')]
public function index(TokenStorageInterface $tokenStorage): Response public function index(TokenStorageInterface $tokenStorage): Response
@@ -47,9 +48,11 @@ class AdminController extends AbstractController
$token = $tokenStorage->getToken(); $token = $tokenStorage->getToken();
$userConnect = $token?->getUser(); $userConnect = $token?->getUser();
$participants = $this->participantRepository->findAll(); $participants = $this->participantRepository->findAll();
$sites = $this->siteRepository->findAll();
return $this->render('admin/user.html.twig', [ return $this->render('admin/user.html.twig', [
'profile' => $userConnect, 'profile' => $userConnect,
'participants' => $participants, 'participants' => $participants,
'sites' => $sites,
'controller_name' => 'AdminController', 'controller_name' => 'AdminController',
]); ]);
} }
@@ -388,17 +391,19 @@ class AdminController extends AbstractController
return $this->redirectToRoute('app_adminSite'); return $this->redirectToRoute('app_adminSite');
} }
#[Route('/admin/accept', name: 'app_acceptUser')] #[Route('/admin/accept', name: 'app_acceptUser', methods: ['POST'])]
public function acceptUser(Request $request, EntityManagerInterface $entityManager, ParticipantRepository $participantRepository): Response public function acceptUser(Request $request, EntityManagerInterface $entityManager, ParticipantRepository $participantRepository, SiteRepository $siteRepository): Response
{ {
try { try {
$user = $participantRepository->findOneBy(["idParticipant" => $request->get('id')]); $user = $participantRepository->findOneBy(["idParticipant" => $request->request->get('id')]);
$site = $siteRepository->findOneBy(['idSite' => $request->request->get('site')]);
if(!$user) { if(!$user || !$site) {
$this->addFlash('error', 'Le utilisateur n\'existe pas.'); $this->addFlash('error', 'L\'utilisateur ou le site n\'existe pas.');
return $this->redirectToRoute('app_adminUser'); return $this->redirectToRoute('app_adminUser');
} }
$user->setSite($site);
$user->setPending(false); $user->setPending(false);
$entityManager->persist($user); $entityManager->persist($user);
$entityManager->flush(); $entityManager->flush();

View File

@@ -104,6 +104,7 @@
<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">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">Site</th>
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th> <th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr> </tr>
</thead> </thead>
@@ -111,17 +112,32 @@
{% for participant in participants %} {% for participant in participants %}
{% if participant.pending %} {% if participant.pending %}
<tr> <tr>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.nom }}</td> <form method="POST" action="{{ path('app_acceptUser') }}">
<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.nom }}</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.prenom }}</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.pseudo }}</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">{{ participant.telephone }}</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ participant.email }}</td>
<a href="{{ path('app_acceptUser', {'id': participant.idParticipant}) }}" class="text-indigo-600 hover:text-indigo-900"> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
Accepter <label>
</a> <select name="site" class="form-select bg-white border border-gray-300 rounded-md text-sm">
<a href="{{ path('app_denyUser', {'id': participant.idParticipant}) }}" class="text-red-600 hover:text-red-900 ml-4">Refuser</a> <option value="0">Sélectionner un site</option>
</td> {% for site in sites %}
<option value="{{ site.idSite }}">{{ site.nom }}</option>
{% endfor %}
</select>
</label>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<label>
<input type="hidden" name="id" value="{{ participant.idParticipant }}" />
</label>
<button type="submit"
class="text-indigo-600 hover:text-indigo-900">Accepter</button>
<a href="{{ path('app_denyUser', {'id': participant.idParticipant}) }}"
class="text-red-600 hover:text-red-900 ml-4">Refuser</a>
</td>
</form>
</tr> </tr>
{% endif %} {% endif %}
{% else %} {% else %}