src/EventListener/JwtCreatedSubscriber.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Controller\MainController;
  4. use App\Entity\Education;
  5. use App\Entity\ProfilSkills;
  6. use App\Entity\User;
  7. use App\Entity\WorkExperience;
  8. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
  9. class JwtCreatedSubscriber extends  MainController {
  10.     public function updateJwtData(JWTCreatedEvent $event)
  11.     {
  12.         // 1. récupérer l'utilisateur pour avoir ces infos
  13.         /**
  14.          * @var $user User
  15.          */
  16.         $user =$event->getUser();
  17.         $count 0;
  18.         $countEnt 0;
  19.         //2.enrecir les data pour qu'elles contiennent ces données
  20.         $data $event->getData();
  21.         $data['id'] = $user->getId();
  22.         $data['username'] = $user->getUserName();
  23.         $data['isActive'] = $user->getIsActive();
  24.         if($user->getProfil()) {
  25.             $skill $this->em->getRepository(ProfilSkills::class)->findBy(["profil" => $user->getProfil()->getId()]);
  26.             $experience $this->em->getRepository(WorkExperience::class)->findBy(["profil" => $user->getProfil()->getId()]);
  27.             $education $this->em->getRepository(Education::class)->findBy(["profils" => $user->getProfil()->getId()]);
  28.             $language $user->getProfil()->getLangues();
  29.             if (!empty($user->getProfil())) {
  30.                 if($user->getProfil()->getPoste() != null){
  31.                     $count += 0.5;
  32.                 }
  33.                 if($user->getProfil()->getPhone() != null){
  34.                     $count += 0.5;
  35.                 }
  36.                 if($user->getProfil()->getTarif() != null){
  37.                     $count += 0.5;
  38.                 }
  39.                 if($user->getProfil()->getCity() != null){
  40.                     $count += 0.5;
  41.                 }
  42.             }
  43.             if (!empty($skill)) {
  44.                 $count += 2;
  45.             }
  46.             if (!empty($experience)) {
  47.                 $count += 2;
  48.             }
  49.             if (!empty($education)) {
  50.                 $count += 2;
  51.             }
  52.             if (!empty($language)) {
  53.                 $count += 2;
  54.             }
  55.             $data['profil'] = $count 100 10;
  56.         }
  57.         if($user->getEntreprise()) {
  58.             $entreprise $user->getEntreprise();
  59.             if ($entreprise->getEmail()) {
  60.                 $countEnt++;
  61.             }
  62.             if ($entreprise->getLink()) {
  63.                 $countEnt++;
  64.             }
  65.             if ($entreprise->getUrl()) {
  66.                 $countEnt++;
  67.             }
  68.             if ($entreprise->getAddress()) {
  69.                 $countEnt++;
  70.             }
  71.             if ($entreprise->getStartAt()) {
  72.                 $countEnt++;
  73.             }
  74.             if ($entreprise->getFinishAt()) {
  75.                 $countEnt++;
  76.             }
  77.             if ($entreprise->getPhoneNumber()) {
  78.                 $countEnt++;
  79.             }
  80.             if ($entreprise->getCountry()) {
  81.                 $countEnt++;
  82.             }
  83.             if ($entreprise->getDescription()) {
  84.                 $countEnt++;
  85.             }
  86.             if ($entreprise->getPoste()) {
  87.                 $countEnt++;
  88.             }
  89.             $data['recruteur'] = $countEnt 100 10;
  90.         }
  91.         $event->setData($data);
  92.     }
  93. }