set user site
This commit is contained in:
@@ -9,7 +9,6 @@ use App\Entity\Ville;
|
||||
use App\Repository\ParticipantRepository;
|
||||
use App\Repository\SiteRepository;
|
||||
use App\Repository\VilleRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
@@ -26,8 +25,10 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
class AdminController extends AbstractController
|
||||
{
|
||||
private ParticipantRepository $participantRepository;
|
||||
public function __construct(ParticipantRepository $participantRepository){
|
||||
private SiteRepository $siteRepository;
|
||||
public function __construct(ParticipantRepository $participantRepository, SiteRepository $siteRepository){
|
||||
$this->participantRepository = $participantRepository;
|
||||
$this->siteRepository = $siteRepository;
|
||||
}
|
||||
#[Route('/admin', name: 'app_admin')]
|
||||
public function index(TokenStorageInterface $tokenStorage): Response
|
||||
@@ -47,9 +48,11 @@ class AdminController extends AbstractController
|
||||
$token = $tokenStorage->getToken();
|
||||
$userConnect = $token?->getUser();
|
||||
$participants = $this->participantRepository->findAll();
|
||||
$sites = $this->siteRepository->findAll();
|
||||
return $this->render('admin/user.html.twig', [
|
||||
'profile' => $userConnect,
|
||||
'participants' => $participants,
|
||||
'sites' => $sites,
|
||||
'controller_name' => 'AdminController',
|
||||
]);
|
||||
}
|
||||
@@ -388,17 +391,19 @@ class AdminController extends AbstractController
|
||||
return $this->redirectToRoute('app_adminSite');
|
||||
}
|
||||
|
||||
#[Route('/admin/accept', name: 'app_acceptUser')]
|
||||
public function acceptUser(Request $request, EntityManagerInterface $entityManager, ParticipantRepository $participantRepository): Response
|
||||
#[Route('/admin/accept', name: 'app_acceptUser', methods: ['POST'])]
|
||||
public function acceptUser(Request $request, EntityManagerInterface $entityManager, ParticipantRepository $participantRepository, SiteRepository $siteRepository): Response
|
||||
{
|
||||
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) {
|
||||
$this->addFlash('error', 'Le utilisateur n\'existe pas.');
|
||||
if(!$user || !$site) {
|
||||
$this->addFlash('error', 'L\'utilisateur ou le site n\'existe pas.');
|
||||
return $this->redirectToRoute('app_adminUser');
|
||||
}
|
||||
|
||||
$user->setSite($site);
|
||||
$user->setPending(false);
|
||||
$entityManager->persist($user);
|
||||
$entityManager->flush();
|
||||
|
||||
@@ -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">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">Site</th>
|
||||
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -111,17 +112,32 @@
|
||||
{% for participant in participants %}
|
||||
{% if participant.pending %}
|
||||
<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.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.email }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="{{ path('app_acceptUser', {'id': participant.idParticipant}) }}" class="text-indigo-600 hover:text-indigo-900">
|
||||
Accepter
|
||||
</a>
|
||||
<a href="{{ path('app_denyUser', {'id': participant.idParticipant}) }}" class="text-red-600 hover:text-red-900 ml-4">Refuser</a>
|
||||
</td>
|
||||
<form method="POST" action="{{ path('app_acceptUser') }}">
|
||||
<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.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.email }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
<label>
|
||||
<select name="site" class="form-select bg-white border border-gray-300 rounded-md text-sm">
|
||||
<option value="0">Sélectionner un site</option>
|
||||
{% 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>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
|
||||
Reference in New Issue
Block a user