<?php
namespace App\EventListener;
use App\Controller\MainController;
use App\Entity\Education;
use App\Entity\ProfilSkills;
use App\Entity\User;
use App\Entity\WorkExperience;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
class JwtCreatedSubscriber extends MainController {
public function updateJwtData(JWTCreatedEvent $event)
{
// 1. récupérer l'utilisateur pour avoir ces infos
/**
* @var $user User
*/
$user =$event->getUser();
$count = 0;
$countEnt = 0;
//2.enrecir les data pour qu'elles contiennent ces données
$data = $event->getData();
$data['id'] = $user->getId();
$data['username'] = $user->getUserName();
$data['isActive'] = $user->getIsActive();
if($user->getProfil()) {
$skill = $this->em->getRepository(ProfilSkills::class)->findBy(["profil" => $user->getProfil()->getId()]);
$experience = $this->em->getRepository(WorkExperience::class)->findBy(["profil" => $user->getProfil()->getId()]);
$education = $this->em->getRepository(Education::class)->findBy(["profils" => $user->getProfil()->getId()]);
$language = $user->getProfil()->getLangues();
if (!empty($user->getProfil())) {
if($user->getProfil()->getPoste() != null){
$count += 0.5;
}
if($user->getProfil()->getPhone() != null){
$count += 0.5;
}
if($user->getProfil()->getTarif() != null){
$count += 0.5;
}
if($user->getProfil()->getCity() != null){
$count += 0.5;
}
}
if (!empty($skill)) {
$count += 2;
}
if (!empty($experience)) {
$count += 2;
}
if (!empty($education)) {
$count += 2;
}
if (!empty($language)) {
$count += 2;
}
$data['profil'] = $count * 100 / 10;
}
if($user->getEntreprise()) {
$entreprise = $user->getEntreprise();
if ($entreprise->getEmail()) {
$countEnt++;
}
if ($entreprise->getLink()) {
$countEnt++;
}
if ($entreprise->getUrl()) {
$countEnt++;
}
if ($entreprise->getAddress()) {
$countEnt++;
}
if ($entreprise->getStartAt()) {
$countEnt++;
}
if ($entreprise->getFinishAt()) {
$countEnt++;
}
if ($entreprise->getPhoneNumber()) {
$countEnt++;
}
if ($entreprise->getCountry()) {
$countEnt++;
}
if ($entreprise->getDescription()) {
$countEnt++;
}
if ($entreprise->getPoste()) {
$countEnt++;
}
$data['recruteur'] = $countEnt * 100 / 10;
}
$event->setData($data);
}
}