src/Controller/SearchController.php line 178

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Candidature;
  4. use App\Entity\Enum\Disponibility;
  5. use App\Entity\Enum\FrenchRegion;
  6. use App\Entity\Enum\Nationality;
  7. use App\Entity\Enum\UAERegion;
  8. use App\Entity\Enum\UAERegionNew;
  9. use App\Entity\Offer;
  10. use App\Entity\Profile;
  11. use App\Entity\User;
  12. use App\Form\FreelanceRegisterFormType;
  13. use App\Form\ResetPasswordRequestFormType;
  14. use App\Repository\CandidatureRepository;
  15. use App\Repository\OfferAlertRepository;
  16. use App\Repository\OfferRepository;
  17. use App\Repository\ProfileRepository;
  18. use App\Repository\ProfileVisitRepository;
  19. use App\Repository\SkillRepository;
  20. use App\Service\Forum\ForumUserService;
  21. use App\Service\LocationService;
  22. use App\Service\OfferService;
  23. use DateTime;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use Knp\Component\Pager\PaginatorInterface;
  26. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  27. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  31. use Symfony\Component\Routing\Annotation\Route;
  32. class SearchController extends AbstractController
  33. {
  34.     /* @changelog 2022-09-22 [FIX] (Anthony) Constante pour la recherche par mobilité */
  35.     const REGION 0;
  36.     const DEPARTMENT 1;
  37.     const FILTER_PERTINENCE 'pertinence';
  38.     const FILTER_DISPONIBILITY 'disponibilité';
  39.     const FILTER_CONNEXION 'connexion';
  40.     const substring "-jobs-in-";
  41.     private function formatCityName($city): string
  42.     {
  43.         if ($city == "all-uae") {
  44.             return "All UAE";
  45.         }
  46.         // Remplacer les tirets par des espaces
  47.         $formattedCity str_replace('-'' '$city);
  48.         // Mettre en majuscule la première lettre de chaque mot
  49.         $formattedCity ucwords($formattedCity);
  50.         return $formattedCity;
  51.     }
  52.     private function transformURL($maChaine): array
  53.     {
  54.         $resultat = [];
  55.         if (strpos($maChaineself::substring) !== false) {
  56.             // Séparer les parties de la chaîne en utilisant "-jobs-in-"
  57.             list($searchPart$locationsPart) = explode(self::substring$maChaine);
  58.             // Mettre la recherche en majuscule et séparer les mots par un espace
  59.             $resultat['search'] = str_replace('-'' '$searchPart);
  60.             // Séparer les emplacements (villes) en utilisant "-and-" et les stocker dans un tableau
  61.             $resultat['locations'] = array_map(array($this'formatCityName'), explode("-and-"$locationsPart));
  62.         } else {
  63.             $resultat['search'] = str_replace('-jobs'''$maChaine);
  64.             $resultat['search'] = str_replace('-'' '$resultat['search']);
  65.             $resultat['locations'] = [];
  66.         }
  67.         return $resultat;
  68.     }
  69.     /**
  70.      * @param array $location
  71.      * @param OfferRepository $offerRepository
  72.      * @param LocationService $locationService
  73.      * @return Offer[]
  74.      */
  75.     private function offerIfNofound(
  76.         array           $location,
  77.         OfferRepository $offerRepository,
  78.         LocationService $locationService
  79.     ): array
  80.     {
  81.         $defaultSearch "";
  82.         $defaultExperience = [];
  83.         $defaultCategorie '';
  84.         $defaultOrder 'pertinence';
  85.         /** @var Offer[] $defaultOffer */
  86.         $defaultOffer $offerRepository->findBySearch(
  87.             $defaultSearch,
  88.             $location,
  89.             $defaultExperience,
  90.             $defaultCategorie,
  91.             $defaultOrder
  92.         );
  93.         if (count($defaultOffer) == 0) {
  94.             $location $this->findParentCities($location$locationService->getSelectableArray());
  95.             $defaultOffer $offerRepository->findBySearch(
  96.                 $defaultSearch,
  97.                 $location,
  98.                 $defaultExperience,
  99.                 $defaultCategorie,
  100.                 $defaultOrder
  101.             );
  102.         }
  103.         return $defaultOffer;
  104.     }
  105.     /**
  106.      * @param array $citiesToFind
  107.      * @param array $countries
  108.      * @return array
  109.      */
  110.     private function findParentCities(array $citiesToFind, array $countries): array
  111.     {
  112.         $foundCountries = [];
  113.         if (in_array("All UAE"$citiesToFind)) {
  114.             return ["All UAE"];
  115.         }
  116.         foreach ($citiesToFind as $city) {
  117.             // Parcourir chaque pays dans le premier array
  118.             foreach ($countries as $country => $cities) {
  119.                 if ($country == $city) {
  120.                     $foundCountries[] = $country;
  121.                     break;
  122.                 }
  123.                 // Vérifier si la ville se trouve dans ce pays
  124.                 if (isset($cities[$city])) {
  125.                     $foundCountries[] = $country;
  126.                     break; // Sortir de la boucle dès qu'on a trouvé le pays
  127.                 }
  128.             }
  129.         }
  130.         return $foundCountries;
  131.     }
  132.     /**
  133.      * changelog 2022-09-27 [FIX] (Anthony) Modifier le recherche par mobilité et re developper les tri sur la recherche
  134.      *
  135.      * @Route("/{url_libelle}jobs{url_location}", name="mission_search", requirements={"url_libelle"=".*", "url_location"=".*"})
  136.      *
  137.      *
  138.      * @param Request $request
  139.      * @param OfferRepository $offerRepository
  140.      * @param OfferAlertRepository $offerAlertRepository
  141.      * @param PaginatorInterface $paginator
  142.      * @param CandidatureRepository $candidatureRepository
  143.      * @param OfferService $offerService
  144.      * @param LocationService $locationService
  145.      * @param EntityManagerInterface $entityManager
  146.      * @param SessionInterface $session
  147.      * @param string|null $url_libelle
  148.      * @param string|null $url_location
  149.      * @return Response
  150.      */
  151.     public function missions(
  152.         Request                $request,
  153.         OfferRepository        $offerRepository,
  154.         OfferAlertRepository   $offerAlertRepository,
  155.         PaginatorInterface     $paginator,
  156.         CandidatureRepository  $candidatureRepository,
  157.         OfferService           $offerService,
  158.         LocationService        $locationService,
  159.         EntityManagerInterface $entityManager,
  160.         SessionInterface       $session,
  161.         ForumUserService       $forumUserService,
  162.         ?string                $url_libelle "",
  163.         ?string                $url_location ""
  164.     ): Response
  165.     {
  166.         $currentDate = new DateTime();
  167.         /* @var User $user */
  168.         $user $this->getUser();
  169.         if ($user) {
  170.             if ($user->isFreelance()) {
  171.                 $currentProfil $user->getUniqueProfile();
  172.                 if (!$currentProfil->getNationalityMultiple()) {
  173.                     return $this->redirectToRoute('complete_resume_profile');
  174.                 }
  175.             }
  176.         }
  177.         // DEFAULT SEARCH
  178.         $defaultSearch "";
  179.         $defaultLocation = ['All UAE'];
  180.         $defaultExperience = [];
  181.         $defaultCategorie '';
  182.         $defaultOrder 'pertinence';
  183.         // DELETE SESSION
  184.         if ($request->getMethod() == 'GET'
  185.             && (!$url_libelle || $url_libelle == 'search')
  186.             && !$url_location
  187.             && !$request->query->get('page')) {
  188.             if ($session->has('s_location')) {
  189.                 $session->remove('s_location');
  190.             }
  191.             if ($session->has('s_categorie')) {
  192.                 $session->remove('s_categorie');
  193.             }
  194.             if ($session->has('s_experience')) {
  195.                 $session->remove('s_experience');
  196.             }
  197.             if ($session->has('s_order')) {
  198.                 $session->remove('s_order');
  199.             }
  200.         }
  201.         if ($request->getMethod() == "GET" && ($url_location || $url_libelle)) {
  202.             $urlData $this->transformURL($url_libelle "-jobs" $url_location);
  203.             $defaultSearch $urlData['search'] ?? "";
  204.             $defaultLocation $urlData['locations'] ?? ['All UAE'];
  205.             if ($url_libelle == "search" && !$url_location) {
  206.                 $defaultSearch "";
  207.                 $defaultLocation = ['All UAE'];
  208.             }
  209.             $page $request->query->getInt('page');
  210.             if ($page != 0) {
  211.                 // GET FROM SESSION
  212.                 $defaultLocation $session->get('s_location') ?? $defaultLocation;
  213.                 $defaultCategorie $session->get('s_categorie') ?? $defaultCategorie;
  214.                 $defaultExperience $session->get('s_experience') ?? $defaultExperience;
  215.                 $defaultOrder $session->get('s_order') ?? $defaultOrder;
  216.             }
  217.         }
  218.         $order $request->request->get('order'$defaultOrder);
  219.         /** @var string[] $location */
  220.         $location $request->request->get('location'$defaultLocation);
  221.         $keyword trim($request->request->get('search'$defaultSearch));
  222.         /** @var string[] $experience */
  223.         $experience $request->request->get('experience'$defaultExperience);
  224.         $category $request->request->get('category'$defaultCategorie);
  225.         $loc implode(', '$location);
  226.         // SET SESSION ON POST
  227.         if ($request->getMethod() == "POST") {
  228.             $session->set('s_location'$location);
  229.             $session->set('s_categorie'$category);
  230.             $session->set('s_experience'$experience);
  231.             $session->set('s_order'$order);
  232.         }
  233.         // FIND ALERT
  234.         $alert $offerAlertRepository->findOneBy([
  235.             'keyword' => $keyword,
  236.             'localisation' => $loc,
  237.             'typeSearch' => $category,
  238.             'user' => $user,
  239.         ]);
  240.         $knpPage $request->get('page'1);
  241.         $knpPerPage 10;
  242.         $offerViewed = [];
  243.         if ($user) {
  244.             $offerViewed array_map(
  245.                 function ($visit) {
  246.                     return $visit->getOffer()->getId();
  247.                 },
  248.                 $user->getOfferVisits()->toArray()
  249.             );
  250.         }
  251.         // FILTER LOCATION BY DEPARTEMENT
  252.         $locationByDepart $locationService->getUAEByArray($location);
  253.         $data $offerRepository->findBySearch($keyword$locationByDepart$experience$category$order);
  254.         if ($order == "pertinence" && $keyword) {
  255.             $data $this->filterOfferByPertinence($data$offerRepository$keyword);
  256.         }
  257.         // FILTER OFFER BY EXPIRED AT
  258.         $data $offerService->filterOfferByExpire($data);
  259.         // DEFAULT OFFER IF NO FOUND
  260.         $noFound false;
  261.         if (count($data) == 0) {
  262.             $noFound true;
  263.             $data $this->offerIfNofound($location$offerRepository$locationService);
  264.         }
  265.         $highlightedMissions $this->getHighLightMission($data$request->query->get('page'));
  266.         $otherBoostMissions $this->getOtherBoostMission($data$request->query->get('page'), $entityManager);
  267.         $highlightedMissions $offerService->filterOfferByExpire($highlightedMissions);
  268.         $otherBoostMissions $offerService->filterOfferByExpire($otherBoostMissions);
  269.         /** @var Offer[] $offers */
  270.         $offers $paginator->paginate(
  271.             $data,
  272.             $request->query->getInt('page'$knpPage),
  273.             $knpPerPage
  274.         );
  275.         /** @var Candidature $userCandidatures */
  276.         $userCandidatures = [];
  277.         $offerCandidatureIds = [];
  278.         if ($user) {
  279.             $userCandidatures $candidatureRepository->findBy(['profile' => $user->getUniqueProfile()]);
  280.             foreach ($userCandidatures as $candidature) {
  281.                 $offerCandidatureIds[] = $candidature->getOffer()->getId();
  282.             }
  283.         }
  284.         // FORM CREATE
  285.         $userJobseeker = new User();
  286.         $userJobseeker->setCreatedAt(new \DateTime());
  287.         $userJobseeker->setRoles(['ROLE_FREELANCE']);
  288.         $userJobseeker->setType('freelance');
  289.         $userJobseeker->setPhone('');
  290.         $formJobseeker $this->createForm(FreelanceRegisterFormType::class, $userJobseeker, [
  291.             'forumPseudo' => $forumUserService->getNextForumUserID()
  292.         ]);
  293.         $resetForm $this->createForm(ResetPasswordRequestFormType::class);
  294.         // FLUSH OTHER BOOST DATE
  295.         $entityManager->flush();
  296.         return $this->render('search/missions.html.twig', [
  297.             'regions' => $locationService->getSelectableArray(),
  298.             'offers' => $offers,
  299.             'order' => $order,
  300.             'keyword' => $keyword,
  301.             'location' => $location,
  302.             'category' => $category,
  303.             'experience' => $experience,
  304.             'offerViewed' => $offerViewed,
  305.             'keywordArray' => $keyword == '' ? [] : explode(','$keyword),
  306.             'isComing' => (bool)$this->getParameter('is_coming'),
  307.             'date_coming_soon' => $this->getParameter('date_coming_soon'),
  308.             'alert' => $alert,
  309.             'regionjson' => json_encode($locationService->getSelectableArray(), JSON_UNESCAPED_UNICODE),
  310.             'highlightedMissions' => $highlightedMissions ?? [],
  311.             'otherBoostMissions' => $otherBoostMissions ?? [],
  312.             'isFreelance' => $user $user->isFreelance() : false,
  313.             'offerCandidatureIds' => $offerCandidatureIds,
  314.             'formJobseeker2' => $formJobseeker->createView(),
  315.             'resetForm' => $resetForm->createView(),
  316.             'noFound' => $noFound,
  317.             'currentDate' => $currentDate,
  318.         ]);
  319.     }
  320.     /**
  321.      * changelog 2022-09-22 [FIX] (Anthony) Modifier le recherche par mobilité et re developper les tri sur la recherche
  322.      *
  323.      * @Route("/profile/search", name="freelance_search")
  324.      *
  325.      * @IsGranted("ROLE_SOCIETY")
  326.      *
  327.      * @param Request $request
  328.      * @param ProfileRepository $profileRepository
  329.      * @param ProfileVisitRepository $profileVisitRepository
  330.      * @param PaginatorInterface $paginator
  331.      * @param SkillRepository $skillRepository
  332.      *
  333.      * @return Response
  334.      */
  335.     public function freelance(
  336.         Request                $request,
  337.         ProfileRepository      $profileRepository,
  338.         ProfileVisitRepository $profileVisitRepository,
  339.         PaginatorInterface     $paginator,
  340.         SkillRepository        $skillRepository
  341.     ): Response
  342.     {
  343.         /* @var User $user */
  344.         $user $this->getUser();
  345.         if ($user && $user->isFreelance()) {
  346.             return $this->redirectToRoute('dashboard');
  347.         }
  348.         $order $request->get('order''pertinence');
  349.         $location $request->get('mobility', []);
  350.         $nationalities $request->get('nationality''');
  351.         $expNumber $request->get('exp_number'null);
  352.         $keywords $request->get('search''');
  353.         $max $request->get('max'0);
  354.         $type $request->get('type''Full-time');
  355.         $disponibility $request->get('disponibility''');
  356.         $knpPage $request->get('page'1);
  357.         $knpPerPage 10;
  358.         if (!$expNumber) {
  359.             $expNumber 0;
  360.         }
  361.         if (!$max) {
  362.             $max 0;
  363.         }
  364.         $data $profileRepository->findBySearch($keywords$expNumber$nationalities$max$order);
  365.         /* @changeLog 2022-11-02 [FIX] (Anthony) Mise en place des intercontrats en une */
  366.         $highlightedProfiles $this->getHighLightProfile($data$request->query->get('page'));
  367.         $profiles $paginator->paginate(
  368.             $data,
  369.             $request->query->getInt('page'$knpPage),
  370.             $knpPerPage
  371.         );
  372.         /* @changeLog 2022-11-10 [EVOL] (Anthony) Mise en place de la limitation de lecture de cv */
  373.         $society $user->getSociety();
  374.         $view $profileVisitRepository->countBySociety($society);
  375.         /* Limitation de l'abonnement */
  376.         $ProfilesVisit $profileVisitRepository->findBySociety($society);
  377.         $profileIds = [];
  378.         foreach ($ProfilesVisit as $visit) {
  379.             $profileIds[] = $visit['id'];
  380.         }
  381.         $profileView count(array_unique($profileIds));
  382.         /* Limitation journalière */
  383.         $startAt date("Y-m-d") . ' 00:00:01';
  384.         $endAt date("Y-m-d") . ' 23:59:59';
  385.         $ProfilesVisitDaily $profileVisitRepository->findBySocietyDaily($society$startAt$endAt);
  386.         $profileDailyIds = [];
  387.         foreach ($ProfilesVisitDaily as $visitDaily) {
  388.             $profileDailyIds[] = $visitDaily['id'];
  389.         }
  390.         $profileViewDaily count(array_unique($profileDailyIds));
  391.         $dayLimit 400;
  392.         $packageLimit = ($society->getProfileView());
  393.         $nationalitiesList Nationality::LIST;
  394.         return $this->render('search/freelance.html.twig', [
  395.             'profiles' => $profiles,
  396.             'keyword' => $keywords,
  397.             'location' => $location,
  398.             'max' => $max,
  399.             'order' => $order,
  400.             'type' => $type,
  401.             'keywordArray' => $keywords == '' ? [] : explode(','$keywords),
  402.             'regions' => FrenchRegion::REGION_DEPARTEMENT,
  403.             'regionjson' => json_encode(FrenchRegion::REGION_DEPARTEMENTJSON_UNESCAPED_UNICODE),
  404.             'disponibilities' => Disponibility::LIST,
  405.             'disponibility' => $disponibility,
  406.             'highlightedProfiles' => $highlightedProfiles ?? [],
  407.             'profileViewDaily' => $profileViewDaily,
  408.             'profileView' => $profileView,
  409.             'dayLimit' => $dayLimit,
  410.             //'dayLimit' => 4,
  411.             'packageLimit' => $packageLimit,
  412.             //'packageLimit' => 4,
  413.             'profileIds' => array_unique($profileIds),
  414.             'nationalitiesList' => $nationalitiesList,
  415.             'nationalities' => $nationalities,
  416.             'expNumber' => $expNumber
  417.         ]);
  418.     }
  419.     /**
  420.      * Récuperer la region et le departement
  421.      *
  422.      * @param $needle //"Le mot clé"
  423.      * @param $haystack //"Le tableau lequel on fait la recherche"
  424.      *
  425.      * @return array|bool
  426.      */
  427.     public function array_recursive_search_key_map($needle$haystack)
  428.     {
  429.         foreach ($haystack as $first_level_key => $value) {
  430.             if ($needle === $value) {
  431.                 return array($first_level_key);
  432.             } elseif (is_array($value)) {
  433.                 $callback $this->array_recursive_search_key_map($needle$value);
  434.                 if ($callback) {
  435.                     return array_merge(array($first_level_key), $callback);
  436.                 }
  437.             }
  438.         }
  439.         return false;
  440.     }
  441.     /**
  442.      * changelog 2022-09-28 [FIX] (Anthony) Formatter les données de la mobilité
  443.      *
  444.      * @param $haystack // Les region et departement à rechercher
  445.      * @param $mobilities // Les mobilités à rechercher
  446.      *
  447.      * @return array
  448.      */
  449.     private function getMobilities($haystack, array $mobilities = []): array
  450.     {
  451.         $results = ["Toute la France"];
  452.         if (count($mobilities) == && array_values($mobilities)[0] != "Toute la France" && in_array($mobilities[0], FrenchRegion::REGION)) {
  453.             foreach ($mobilities as $mobility) {
  454.                 $results[] = $mobility;
  455.             }
  456.         } else {
  457.             foreach ($mobilities as $mobility) {
  458.                 $regionAndDepartment $this->array_recursive_search_key_map($mobility$haystack);
  459.                 $results[] = $regionAndDepartment[self::REGION];
  460.                 $results[] = $regionAndDepartment[self::DEPARTMENT];
  461.             }
  462.         }
  463.         return $results;
  464.     }
  465.     /**
  466.      * changelog 2022-09-22 [FIX] (Anthony) Formatter les données de la mobilité
  467.      *
  468.      * @param array $datas //Les region et departement à rechercher
  469.      * @param $order //Filtre de la recherche
  470.      * @param ProfileRepository $profileRepository //La classe profile repository
  471.      * @param array $mobilities //Les mobilités à rechercher
  472.      *
  473.      * @return array
  474.      */
  475.     private function checkProfilesByMobility(
  476.         array             $datas,
  477.         ProfileRepository $profileRepository,
  478.                           $order,
  479.         array             $mobilities = []): array
  480.     {
  481.         $results = ["Toute la France"];
  482.         if (count($mobilities) == && array_values($mobilities)[0] == "Toute la France") {
  483.             $data $profileRepository->findByMobility($order$results);
  484.         } else if (count($mobilities) == && array_values($mobilities)[0] != "Toute la France" && in_array($mobilities[0], FrenchRegion::REGION)) {
  485.             foreach ($mobilities as $mobility) {
  486.                 $results[] = $mobility;
  487.             }
  488.             $data $profileRepository->findByMobility($order$results);
  489.         } else {
  490.             foreach ($mobilities as $mobility) {
  491.                 $regionAndDepartment $this->array_recursive_search_key_map($mobility$datas);
  492.                 $results[] = $regionAndDepartment[self::REGION];
  493.                 $results[] = $regionAndDepartment[self::DEPARTMENT];
  494.             }
  495.             $data $profileRepository->findByMobility($orderarray_unique($results));
  496.         }
  497.         return $data;
  498.     }
  499.     /**
  500.      * changelog 2022-09-27 [FIX] (Anthony) Formatter les données des missions par mot clé
  501.      *
  502.      * @param $keywords //Les mots clé à rechercher
  503.      * @param OfferRepository $offerRepository //La classe offer repository
  504.      * @param $order //Filtre de la recherche
  505.      *
  506.      * @return array
  507.      */
  508.     private function checkOfferByKeword(
  509.         $keywords,
  510.         OfferRepository $offerRepository,
  511.         $order): array
  512.     {
  513.         $data $offerRepository->findByKeyword($keywords$order);
  514.         return $data;
  515.     }
  516.     /**
  517.      * changelog 2022-09-26 [FIX] (Anthony) Formatter les données des freelances par mot clé
  518.      *
  519.      * @param $keywords //Les mots clé à rechercher
  520.      * @param ProfileRepository $profileRepository //La classe profile repository
  521.      * @param $order //Filtre de la recherche
  522.      *
  523.      * @return array
  524.      */
  525.     private function checkProfilesByKeword($keywordsProfileRepository $profileRepository$order): array
  526.     {
  527.         return $profileRepository->findByKeyword($keywords$order);
  528.     }
  529.     /**
  530.      * changelog 2022-09-26 [FIX] (Anthony) Formatter les données par type
  531.      *
  532.      * @param $type //Le type du profile
  533.      * @param ProfileRepository $profileRepository //La classe profile repository
  534.      * @param $order //Filtre de la recherche
  535.      *
  536.      * @return array
  537.      */
  538.     private function checkProfilesByType($typeProfileRepository $profileRepository$order): array
  539.     {
  540.         return $profileRepository->findByType($type$order);
  541.     }
  542.     /**
  543.      * changelog 2022-09-26 [FIX] (Anthony) Formater les données de la disponibilité
  544.      *
  545.      * @param $disponibility //La disponibilité du profile
  546.      * @param ProfileRepository $profileRepository //La classe profile repository
  547.      * @param $order //Filtre de la recherche
  548.      *
  549.      * @return array
  550.      */
  551.     private function checkProfilesByDisponibility(
  552.         $disponibility,
  553.         ProfileRepository $profileRepository,
  554.         $order
  555.     ): array
  556.     {
  557.         return $profileRepository->findByDisponibility($disponibility$order);
  558.     }
  559.     /**
  560.      * changelog 2022-09-26 [FIX] (Anthony) Formater les données de la TJM
  561.      *
  562.      * @param $cost //La TJM du profile
  563.      * @param ProfileRepository $profileRepository //La classe profile repository
  564.      * @param $order //Filtre de la recherche
  565.      *
  566.      * @return array
  567.      */
  568.     private function checkProfilesByCost($cost$profileRepository$order): array
  569.     {
  570.         $data $profileRepository->findByCost($cost$order);
  571.         return $data;
  572.     }
  573.     /**
  574.      * changelog 2022-09-23 [FIX] (Anthony) Supprimé les doublons du tableau d'objet
  575.      *
  576.      * @param       $array //Le tableau d'objet
  577.      * @param       $keep_key_assoc
  578.      *
  579.      * @return array
  580.      */
  581.     private function my_array_unique($array$keep_key_assoc false): array
  582.     {
  583.         $duplicate_keys = array();
  584.         $tmp = array();
  585.         foreach ($array as $key => $val) {
  586.             // convert objects to arrays, in_array() does not support objects
  587.             if (is_object($val))
  588.                 $val = (array)$val;
  589.             if (!in_array($val$tmp))
  590.                 $tmp[] = $val;
  591.             else
  592.                 $duplicate_keys[] = $key;
  593.         }
  594.         foreach ($duplicate_keys as $key)
  595.             unset($array[$key]);
  596.         return $keep_key_assoc $array array_values($array);
  597.     }
  598.     /**
  599.      * changelog 2022-09-23 [FIX] (Anthony) Filtrer les données freelances par mot clé par pertinence
  600.      *
  601.      * @param       $data //Les données à filtrer
  602.      * @param ProfileRepository $profileRepository //La classe profile repository
  603.      * @param SkillRepository $skillRepository //La classe skill repository
  604.      * @param       $keyword //Les mots clé
  605.      *
  606.      * @return array
  607.      */
  608.     private function filterDataKeywordByPertinence($data$profileRepository$skillRepository$keyword)
  609.     {
  610.         $dataTitle = [];
  611.         $dataName = [];
  612.         $dataAbout = [];
  613.         $keyword explode(' '$keyword);
  614.         foreach ($data as $profile) {
  615.             foreach ($keyword as $key) {
  616.                 $isCheckInTitle stripos($profile->title$key);
  617.                 if ($isCheckInTitle > -1) {
  618.                     $dataTitle[] = $profileRepository->find($profile->id);
  619.                     continue;
  620.                 }
  621.             }
  622.             $skillsData $skillRepository->findBy(['profile' => $profile]);
  623.             $skillName = [];
  624.             foreach ($skillsData as $skill) {
  625.                 $skillName[] = $skill->name;
  626.             }
  627.             $skillName implode(','$skillName);
  628.             foreach ($keyword as $key) {
  629.                 $isCheckInSkill stripos($skillName$key);
  630.                 if ($isCheckInSkill > -1) {
  631.                     $dataName[] = $profileRepository->find($profile->id);
  632.                     continue;
  633.                 }
  634.             }
  635.             if (!empty($profile->about)) {
  636.                 foreach ($keyword as $key) {
  637.                     $isCheckInAbout stripos($profile->about$key);
  638.                     if ($isCheckInAbout > -1) {
  639.                         $dataAbout[] = $profileRepository->find($profile->id);
  640.                         continue;
  641.                     }
  642.                 }
  643.             }
  644.             if (!empty($profile->cvText)) {
  645.                 foreach ($keyword as $key) {
  646.                     $isCheckInAbout stripos($profile->cvText$key);
  647.                     if ($isCheckInAbout > -1) {
  648.                         $dataAbout[] = $profileRepository->find($profile->id);
  649.                         continue;
  650.                     }
  651.                 }
  652.             }
  653.         }
  654.         $dataTitle $this->my_array_unique($dataTitle);
  655.         $dataName $this->my_array_unique($dataName);
  656.         $dataAbout $this->my_array_unique($dataAbout);
  657.         $dataTitleName array_merge($dataTitle$dataName);
  658.         $dataFilter array_merge($dataTitleName$dataAbout);
  659.         $dataFilter $this->my_array_unique($dataFilter);
  660.         return $dataFilter;
  661.     }
  662.     /**
  663.      * changelog 2022-09-27 [FIX] (Anthony) Filtrer les données freelances par mot clé par pertinence
  664.      *
  665.      * @param $data //Les données à filtrer
  666.      * @param OfferRepository $offerRepository // La classe offer repository
  667.      * @param $keyword //Les mots clé
  668.      *
  669.      * @return array
  670.      */
  671.     private function filterOfferByPertinence($dataOfferRepository $offerRepository$keyword): array
  672.     {
  673.         $dataTitle = [];
  674.         $dataDescription = [];
  675.         $keyword explode(' '$keyword);
  676.         foreach ($data as $offer) {
  677.             foreach ($keyword as $kwd) {
  678.                 $isCheckInTitle stripos($offer->title$kwd);
  679.                 if ($isCheckInTitle > -1) {
  680.                     $dataTitle[] = $offerRepository->find($offer->id);
  681.                     continue;
  682.                 }
  683.             }
  684.             if (!empty($offer->description)) {
  685.                 foreach ($keyword as $kwd) {
  686.                     $isCheckInDesc stripos($offer->description$kwd);
  687.                     if ($isCheckInDesc > -1) {
  688.                         $dataDescription[] = $offerRepository->find($offer->id);
  689.                         continue;
  690.                     }
  691.                 }
  692.             }
  693.         }
  694.         $dataTitle $this->my_array_unique($dataTitle);
  695.         $dataDescription $this->my_array_unique($dataDescription);
  696.         $dataFilter array_merge($dataTitle$dataDescription);
  697.         $dataFilter $this->my_array_unique($dataFilter);
  698.         return $dataFilter;
  699.     }
  700.     /**
  701.      * changelog 2022-09-23 [FIX] (Anthony) Filtrer les données par mobilité par pertinence
  702.      *
  703.      * @param       $data //Les données à filtrer
  704.      * @param ProfileRepository $profileRepository //La classe profile repository
  705.      * @param       $locations //Les mobilités
  706.      *
  707.      * @return array
  708.      */
  709.     private function filterDataMobilityByPertinence($dataProfileRepository $profileRepository$locations): array
  710.     {
  711.         $mobilities = [];
  712.         foreach ($locations as $mobility) {
  713.             $regionAndDepartment $this->array_recursive_search_key_map($mobilityFrenchRegion::REGION_DEPARTEMENT_WITH_ALL);
  714.             $mobilities['region'][] = $regionAndDepartment[self::REGION];
  715.             $mobilities['departement'][] = $regionAndDepartment[self::DEPARTMENT];
  716.         }
  717.         $dataDepartement = [];
  718.         $dataRegion = [];
  719.         $dataFrance = [];
  720.         foreach ($data as $profile) {
  721.             foreach ($mobilities['departement'] as $departement) {
  722.                 if (in_array($departement$profile->mobility)) {
  723.                     $dataDepartement[] = $profileRepository->find($profile->id);
  724.                     continue;
  725.                 }
  726.             }
  727.             foreach ($mobilities['region'] as $region) {
  728.                 if (in_array($region$profile->mobility)) {
  729.                     $dataRegion[] = $profileRepository->find($profile->id);
  730.                     continue;
  731.                 }
  732.             }
  733.             if (in_array('Toute la France'$profile->mobility)) {
  734.                 $dataFrance[] = $profileRepository->find($profile->id);
  735.                 continue;
  736.             }
  737.         }
  738.         $dataRegionDepartement array_merge($dataDepartement$dataRegion);
  739.         $dataFilter array_merge($dataRegionDepartement$dataFrance);
  740.         return $dataFilter;
  741.     }
  742.     private function shuffleData($data)
  743.     {
  744.         if (!is_array($data)) return $data;
  745.         $keys array_keys($data);
  746.         shuffle($keys);
  747.         $random = array();
  748.         foreach ($keys as $key)
  749.             $random[$key] = $data[$key];
  750.         return $random;
  751.     }
  752.     private function getHighLightProfile($data$page)
  753.     {
  754.         $highLightProfile = [];
  755.         foreach ($data as $profile) {
  756.             if (is_null($profile->isHighlight)) {
  757.                 continue;
  758.             }
  759.             $highLightProfile[] = $profile;
  760.         }
  761.         if (isset($page) && $page 1) {
  762.             $highLightProfile = [];
  763.         }
  764.         $highLightProfile $this->shuffleData($highLightProfile);
  765.         return array_slice($highLightProfile02);
  766.     }
  767.     /**
  768.      * @param Offer[] $data
  769.      * @param int|null $page
  770.      * @return Offer[]
  771.      */
  772.     private function getHighLightMission(array $data$page): array
  773.     {
  774.         $currentDate = new DateTime();
  775.         $highLightMission = [];
  776.         foreach ($data as $mission) {
  777.             if (!$mission->priorize || $mission->getExpireAt() < $currentDate) {
  778.                 continue;
  779.             }
  780.             $highLightMission[] = $mission;
  781.         }
  782.         if (isset($page) && $page 1) {
  783.             $highLightMission = [];
  784.         }
  785.         $highLightMission $this->shuffleData($highLightMission);
  786.         return array_slice($highLightMission02);
  787.     }
  788.     /**
  789.      * @param Offer[] $data
  790.      * @param int|null $page
  791.      * @param EntityManagerInterface $entityManager
  792.      * @return Offer[]
  793.      */
  794.     private function getOtherBoostMission(
  795.         array                  $data,
  796.         ?int                   $page,
  797.         EntityManagerInterface $entityManager
  798.     ): array
  799.     {
  800.         if (isset($page) && $page 1) {
  801.             return [];
  802.         }
  803.         $currentDate = new DateTime();
  804.         $otherBoostMission = [];
  805.         foreach ($data as $mission) {
  806.             if ($mission->getExpireAt() < $currentDate) {
  807.                 continue;
  808.             }
  809.             if (!$mission->getDaily() && !$mission->getWeekly()) {
  810.                 continue;
  811.             }
  812.             if (!$mission->getDateRemonter()) {
  813.                 $mission->setDateRemonter(new DateTime());
  814.                 $entityManager->persist($mission);
  815.             }
  816.             if ($mission->getDaily()) {
  817.                 $otherBoostMission[] = $mission;
  818.                 continue;
  819.             }
  820.             $testDate DateTime::createFromFormat("Ymd H:i"$mission->getDateRemonter()->format("Ymd H:i"));
  821.             if ($mission->getWeekly()) {
  822.                 $testDate->modify('+1 week');
  823.             }
  824.             if ($testDate $currentDate) {
  825.                 $otherBoostMission[] = $mission;
  826.             }
  827.         }
  828.         $otherBoostMission $this->shuffleData($otherBoostMission);
  829.         return array_slice($otherBoostMission05);
  830.     }
  831. }