67 lines
2.7 KiB
PHP
67 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Controller\Dashboard;
|
||
|
|
|
||
|
|
use App\Controller\EntityManagerInterface;
|
||
|
|
use App\Entity\Account;
|
||
|
|
use App\Entity\AccountResetPasswordRequest;
|
||
|
|
use App\Form\RequestPasswordConfirmType;
|
||
|
|
use App\Form\RequestPasswordRequestType;
|
||
|
|
use App\Repository\AccountRepository;
|
||
|
|
use App\Service\ResetPassword\Event\ResetPasswordConfirmEvent;
|
||
|
|
use App\Service\ResetPassword\Event\ResetPasswordEvent;
|
||
|
|
use App\Service\Search\Client;
|
||
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||
|
|
use Symfony\Component\HttpFoundation\Request;
|
||
|
|
use Symfony\Component\HttpFoundation\Response;
|
||
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||
|
|
use Symfony\Component\Routing\Attribute\Route;
|
||
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||
|
|
|
||
|
|
|
||
|
|
class SearchController extends AbstractController
|
||
|
|
{
|
||
|
|
#[Route(path: '/crm/recherche', name: 'app_crm_search', options: ['sitemap' => false], methods: ['GET'])]
|
||
|
|
public function crmSearch(
|
||
|
|
AccountRepository $accountRepository,
|
||
|
|
Client $client,
|
||
|
|
Request $request
|
||
|
|
): Response {
|
||
|
|
$query = $request->query->get('q', '');
|
||
|
|
$unifiedResults = [];
|
||
|
|
|
||
|
|
if (!empty($query)) {
|
||
|
|
$response = $client->searchGlobal($query, 20);
|
||
|
|
|
||
|
|
foreach ($response['results'] as $resultGroup) {
|
||
|
|
// On vérifie si l'index correspond aux administrateurs
|
||
|
|
if (str_contains($resultGroup['indexUid'], 'intranet_ludikevent_admin')) {
|
||
|
|
|
||
|
|
// Extraction des IDs pour éviter les requêtes en boucle
|
||
|
|
$ids = array_map(fn($h) => $h['id'], $resultGroup['hits']);
|
||
|
|
$accounts = $accountRepository->findBy(['id' => $ids]);
|
||
|
|
|
||
|
|
foreach ($accounts as $account) {
|
||
|
|
$unifiedResults[] = [
|
||
|
|
'title' => $account->getName() . " " . $account->getFirstName(),
|
||
|
|
'subtitle' => $account->getEmail(),
|
||
|
|
'link' => $this->generateUrl('app_crm_administrateur_view', ['id' => $account->getId()]),
|
||
|
|
'type' => 'Administrateur',
|
||
|
|
'id' => $account->getId(),
|
||
|
|
'initials' => strtoupper(substr($account->getName(), 0, 1) . substr($account->getFirstName(), 0, 1))
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->render('dashboard/search.twig', [
|
||
|
|
'results' => $unifiedResults,
|
||
|
|
'query' => $query
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|