src/Service/ProfileService.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Constant\Common;
  4. use App\Entity\Notification;
  5. use App\Entity\Role;
  6. use App\Entity\Status;
  7. use App\Entity\Profile;
  8. use App\Entity\ProfileNote;
  9. use App\Entity\Campaign;
  10. use App\Repository\ProfileRepository;
  11. use App\Exception\BadRequestException;
  12. use App\Misc\ArrayHelper;
  13. use Symfony\Component\Security\Http\SecurityEvents;
  14. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  17. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  18. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  19. use Symfony\Contracts\HttpClient\HttpClientInterface;
  20. /**
  21.  * Class ProfileService
  22.  * @package App\Service
  23.  */
  24. class ProfileService extends BaseService
  25. {
  26.     /**
  27.      * ProfileService constructor.
  28.      * @param ProfileRepository $repository
  29.      */
  30.     public function __construct(
  31.         ProfileRepository $repository,
  32.         BaseService $baseService,
  33.         SessionInterface $session,
  34.         TranslatorInterface $translator,
  35.         EventDispatcherInterface $dispatcher,
  36.         HttpClientInterface $httpClient
  37.     ) {
  38.         $this->reflectFromParent($baseService);
  39.         $this->repository $repository;
  40.         $this->session $session;
  41.         $this->translator $translator;
  42.         $this->dispatcher $dispatcher;
  43.         $this->httpClient $httpClient;
  44.     }
  45.     public function getById($id)
  46.     {
  47.         return $this->repository->getOneBy(
  48.             [
  49.                 'filter_id' => $id
  50.             ]
  51.         );
  52.     }
  53.     public function getProfileByUserId($userId)
  54.     {
  55.         return $this->repository->getProfileByUserId($userId);
  56.     }
  57.     public function addProfile($request$DTO null)
  58.     {
  59.         $user $this->userService->addUser(array_merge(
  60.             $request->get("user"),
  61.             [
  62.                 'password' => $this->container->getParameter('default_user_password'),
  63.                 'subRoles' => [Role::ROLE_USER]
  64.             ]
  65.         ), 'ENTITY');
  66.         if($user && $DTO){
  67.             $this->userService->updateProfileUser($request$user);
  68.         }
  69.         $request->request->set('user'$user->getId());
  70.         if ($this->session->get('trackingCode')) {
  71.             $mediaChannel $this->MediaChannelRepo->findOneBy(
  72.                 [
  73.                     'name' => $this->session->get('trackingCode')
  74.                 ]
  75.             );
  76.             if ($mediaChannel) {
  77.                 $input['mediaChannel'] = $mediaChannel;
  78.             }
  79.         }
  80.         // Add Profile
  81.         if($request->get('programs') && is_array($request->get('programs'))){
  82.             $input['selectedProgram'] =  $request->get('programs')[0];
  83.         }
  84.         if($request->get('campus1')){
  85.             $request->request->set('campus'$request->get('campus1'));
  86.             $randCommercial $this->getRandomComercialOfcampus($request->get('campus1'));
  87.             if($randCommercial){
  88.                 $request->request->set('commercial'$randCommercial);
  89.             }
  90.         }
  91.         $input['status'] = Status::STATUS_NEED_CONTACT;
  92.         $profile $this->add($request$input$DTO'ENTITY'false, [], true);
  93.         if ($profile->getCampaign()) {
  94.             if ($profile->getCampaign()->getId() == Campaign::APPLICATION) {
  95.                 $this->userService->sendWelcomeEmail($profile);
  96.             }else if($profile->getCampaign()->getId() == Campaign::DOCUMENT){
  97.                 $this->userService->sendDocumentEmail($profile);
  98.             }
  99.         }
  100.         // set profile sources
  101.         if ($request->get('openDay')) {
  102.             $openDay $this->openDayRepo->findOneBy(['id' => $request->get('openDay')]);
  103.             if($openDay) {
  104.                 $this->profileSourceService->checkandAddProfileSource($profile$openDay->getName());
  105.             }
  106.         }else if($request->get('landingpage')) {
  107.             $landingpage $this->landingpageRepo->findOneBy(['id' => $request->get('landingpage')]);
  108.             if($landingpage) {
  109.                 if($landingpage->isIsAgent()){
  110.                     $this->profileSourceService->checkandAddProfileSource($profile'LPA: ' .$landingpage->getName());
  111.                 }else{
  112.                     $this->profileSourceService->checkandAddProfileSource($profile'LP: ' .$landingpage->getName());
  113.                 }
  114.             }
  115.         }else if($request->get('campaign')) {
  116.             $campaign $this->campaignRepo->findOneBy(['id' => $request->get('campaign')]);
  117.             if($campaign) {
  118.                 $this->profileSourceService->checkandAddProfileSource($profile$campaign->getName());
  119.             }
  120.         }
  121.         // clear tracking code
  122.         $this->session->remove('trackingCode');
  123.         $token = new UsernamePasswordToken($usernull'main'$user->getSubRoleNames());
  124.         $this->tokenStorage->setToken($token);
  125.         if(!$DTO){
  126.             $event = new SecurityEvents($request);
  127.             $this->dispatcher->dispatch($eventSecurityEvents::INTERACTIVE_LOGIN);
  128.         }
  129.         return $profile;
  130.     }
  131.     public function updateProfile($request$DTO 'App\DTO\Profile\UpdateProfileInput'$step4 null )
  132.     {
  133.         if($this->getUser()){
  134.             $profile $this->getUser()->getProfiles()[0];
  135.         }elseif( $request->get('profileId')){
  136.             $profile $this->get($request->get('profileId'));
  137.         } else {
  138.             throw new NotFoundHttpException($this->translator->trans('profile_not_found'));
  139.         }
  140.         if(!$profile) throw new NotFoundHttpException($this->translator->trans('profile_not_found'));   
  141.         if($step4 && $profile->getStatus()->getId() < Status::STATUS_APPLICATION_RECEIVED){
  142.             $request->request->set('status'Status::STATUS_APPLICATION_RECEIVED);
  143.             if(!$request->get('isSent')){
  144.                 $request->request->set('isSent'1);
  145.                 
  146.                 //set profile sources
  147.                 $campaign $this->campaignService->get(Campaign::APPLICATION);
  148.                 if($campaign) {
  149.                     $this->profileSourceService->checkandAddProfileSource($profile$campaign->getName());
  150.                 }
  151.             }
  152.         }
  153.         // set profile sources
  154.         if ($request->get('openDay')) {
  155.             $openDay $this->openDayRepo->findOneBy(['id' => $request->get('openDay')]);
  156.             if($openDay) {
  157.                 $this->profileSourceService->checkandAddProfileSource($profile$openDay->getName());
  158.             }
  159.         }else if($request->get('landingpage')) {
  160.             $landingpage $this->landingpageRepo->findOneBy(['id' => $request->get('landingpage')]);
  161.             if($landingpage) {
  162.                 if($landingpage->isIsAgent()){
  163.                     $this->profileSourceService->checkandAddProfileSource($profile'LPA: ' .$landingpage->getName());
  164.                 }else{
  165.                     $this->profileSourceService->checkandAddProfileSource($profile'LP: ' .$landingpage->getName());
  166.                 }
  167.             }
  168.         }else if($request->get('campaign')) {
  169.             $campaign $this->campaignRepo->findOneBy(['id' => $request->get('campaign')]);
  170.             if($campaign) {
  171.                 $this->profileSourceService->checkandAddProfileSource($profile$campaign->getName());
  172.             }
  173.         }
  174.         if($request->get('campus1') && $request->get('campus1') != $profile->getCampus1()->getId()){
  175.             $request->request->set('campus'$request->get('campus1'));
  176.             $randCommercial $this->getRandomComercialOfcampus($request->get('campus1'));
  177.             if($randCommercial){
  178.                 $request->request->set('commercial'$randCommercial);
  179.             }
  180.         }
  181.         if($request->get('programs')){
  182.             $request->request->set('selectedProgram'$request->get('programs')[0]);
  183.         }
  184.         if($profile->isIsSent() && $request->get('campus1') != $profile->getCampus1()->getId()){
  185.             //send email change campus
  186.             if(isset(Common::listEmailAdmission()[$request->get('campus1')])){
  187.                 $this->userService->sendCampusEmail($profileCommon::listEmailAdmission()[$request->get('campus1')]);
  188.             }
  189.         }
  190.         return $this->update($profile$requestnull$DTO'ENTITY'falsetrue);
  191.     }
  192.     public function updateSelectedProgram($request$DTO 'App\DTO\Profile\AdminUpdateProfileSelectedProgramInput')
  193.     {
  194.         $profile $this->get($request->get('id'));
  195.         return $this->update($profile$requestnull$DTO'App\DTO\Profile\ProfileOutput'falsetrue);
  196.     }
  197.     public function handleSendMail($statusOld$profile)
  198.     {
  199.         // Send Mail if status update
  200.         if (
  201.             $statusOld != ($profile->status)['id']
  202.             && ($profile->status)['id'] >= Status::STATUS_APPLICATION_RECEIVED
  203.             && !$profile->isAgent
  204.         ) {
  205.             $this->userService->sendNotificationEmailUpdateStatus($profile);
  206.         }
  207.     }
  208.     public function updateProfileAdmin($request)
  209.     {
  210.         $profile $this->get($request->get('id'));
  211.         if (!$profile) throw new NotFoundHttpException($this->translator->trans('profile_not_found'));
  212.         $statusOld $profile->getStatus()->getId();
  213.         $input = [];
  214.         if ($request->get('jury')) {
  215.             $input['juryDate'] = new \DateTime('now');
  216.         }
  217.         if ($request->get('oraux')) {
  218.             $input['orauxDate'] = new \DateTime('now');
  219.         }
  220.         if($request->get('status') == Status::STATUS_JURY_ACCEPTED){
  221.             if($profile->getSelectedProgram()->getSpecialityId() && !$profile->getQcmToken()){
  222.                 $user $profile->getUser();
  223.                 $now = new \DateTime('now');
  224.                 $data = [
  225.                     'civility' => $user->getGender() == 'mrs' 'mr' ,
  226.                     'firstName' => $user->getFirstName(),
  227.                     'lastName' => $user->getLastName(),
  228.                     'email' => $user->getEmail(),
  229.                     'birthDate' => $user->getBirthDay() ? $user->getBirthDay()->format('Y-m-d') : $now->format('Y-m-d'),
  230.                     'phone' => $user->getPhone(),
  231.                     'speciality' => $profile->getSelectedProgram()->getSpecialityId()
  232.                 ];
  233.                 $responseQcm $this->callQcmApi($data'/auth/external/register''POST');
  234.                 if($responseQcm['success'] == true && $responseQcm['data']){
  235.                     $profile->setQcmToken($responseQcm['data']['password']);
  236.                     $dataQcmResults = [
  237.                         'isDoneTest' => $responseQcm['data']['isDoneTest'],
  238.                         'questions' => $responseQcm['data']['questions']
  239.                     ];
  240.                     $profile->setQcmResults($dataQcmResults);
  241.                 }
  242.             }elseif ($profile->getSelectedProgram()->getSpecialityId() && $profile->getQcmToken()){
  243.                 $data = [
  244.                     'email' => $profile->getUser()->getEmail(),
  245.                     'password' => $profile->getQcmToken(),
  246.                     'speciality' => $profile->getSelectedProgram()->getSpecialityId()
  247.                 ];
  248.                 $responseQcm $this->callQcmApi($data'/auth/external/user/update-speciality''PATCH');  
  249.                 $dataQcmResults = [
  250.                     'isDoneTest' => $responseQcm['data']['isDoneTest'],
  251.                     'questions' => $responseQcm['data']['questions']
  252.                 ];
  253.                 $profile->setQcmResults($dataQcmResults);
  254.             }
  255.         }
  256.         if($request->get('status') == Status::STATUS_INTERVIEW_INVITED && $profile->getQcmMethod() == Profile::QCM_LOCAL){
  257.             if($profile->getOraux()){
  258.                 $dateStartQCM $profile->getOraux()->getDate()->format('Y-m-d');
  259.                 $timeStartQCM $profile->getOraux()->getHour() ? $profile->getOraux()->getHour()->format(' H:i:s') : '';
  260.             }
  261.             if(!isset($timeStartQCM)){
  262.                 $orauxSelected $this->orauxService->get($request->get('oraux'));
  263.                 $dateStartQCM $orauxSelected->getDate()->format('Y-m-d');
  264.                 $timeStartQCM $orauxSelected->getHour() ? $orauxSelected->getHour()->format(' H:i:s') : '';
  265.             }
  266.             $data = [
  267.                 'email' => $profile->getUser()->getEmail(),
  268.                 'password' => $profile->getQcmToken(),
  269.                 'startTestAt' => (new \DateTime($dateStartQCM.$timeStartQCM, new \DateTimeZone($this->container->getParameter('fallback_timezone'))))->format(DATE_ATOM)
  270.             ];
  271.             $this->callQcmApi($data'/auth/external/user/update-start-test''PATCH');
  272.         }
  273.         if( $request->get('status') == Status::STATUS_STUDENT_ENROLLED ) {
  274.             $profile->setEnrolledDate(new \DateTime('now'));
  275.         }
  276.         // Check campus selected in list campus of commercial
  277.         // if ($inputCampus = $request->get('campus')) {
  278.         //     if ($commercial = $profile->getCommercial()) {
  279.         //         $campuses = [];
  280.         //         foreach ($commercial->getCampuses() as $campus) {
  281.         //             $campuses[] = $campus->getId();
  282.         //         }
  283.         //         if (!in_array($inputCampus, $campuses)) {
  284.         //             $input['commercial'] = 'isNull';
  285.         //         }
  286.         //     }
  287.         // }
  288.         $profile $this->update(
  289.             $profile,
  290.             $request,
  291.             $input,
  292.             'App\DTO\Profile\AdminUpdateProfileInput',
  293.             'App\DTO\Profile\ProfileOutput',
  294.             false,
  295.             true
  296.         );
  297.         $this->handleSendMail($statusOld$profile);
  298.         if($request->get('campus') && $request->get('campus') != $profile->campus1['id']){
  299.             if(isset(Common::listEmailAdmission()[$request->get('campus')])){
  300.                 $this->userService->sendCampusEmail($profileCommon::listEmailAdmission()[$request->get('campus')]);
  301.             }
  302.         }
  303.         return $profile;
  304.     }
  305.     public function updateProgramsAdmin($request)
  306.     {
  307.         $profile $this->get($request->get('id'));
  308.         if (!$profile) throw new NotFoundHttpException($this->translator->trans('profile_not_found'));
  309.         $statusOld $profile->getStatus()->getId();
  310.         $profile $this->update(
  311.             $profile,
  312.             $request,
  313.             null,
  314.             'App\DTO\Profile\AdminUpdateProgramsProfileInput',
  315.             'App\DTO\Profile\ProfileOutput',
  316.             false,
  317.             true
  318.         );
  319.         $this->handleSendMail($statusOld$profile);
  320.         return $profile;
  321.     }
  322.     public function duplicateProfile($request){
  323.         $profile $this->repository->find($request->get('id'));
  324.         $programSelected $this->programRepo->find($request->get('programId'));
  325.         $campusSelected $this->campusRepo->find($request->get('campusId'));
  326.         $cloneCV                    $profile->getFileCv() ? clone $profile->getFileCv() : null;
  327.         $cloneFileContract          $profile->getFileContract() ? clone $profile->getFileContract() : null;
  328.         $cloneLetter                $profile->getFileLetter() ? clone $profile->getFileLetter() : null;
  329.         $cloneFileReportCard1       $profile->getFileReportCard1() ? clone $profile->getFileReportCard1() : null;
  330.         $cloneFileReportCard2       $profile->getFileReportCard2() ? clone $profile->getFileReportCard2() : null;
  331.         $cloneFileReportCard3       $profile->getFileReportCard3() ? clone $profile->getFileReportCard3() : null;
  332.         $cloneFileIdentity          $profile->getFileIdentity() ? clone $profile->getFileIdentity() : null;
  333.         $cloneFileResidencePermit   $profile->getFileResidencePermit() ? clone $profile->getFileResidencePermit() : null;
  334.         $cloneFilePhoto             $profile->getFilePhoto() ? clone $profile->getFilePhoto() : null;
  335.         $cloneFileHandicap          $profile->getFileHandicap() ? clone $profile->getFileHandicap() : null;
  336.         $profileDuplicate = clone $profile;
  337.         $profileDuplicate->setFileCv($cloneCV);
  338.         $profileDuplicate->setFileContract($cloneFileContract);
  339.         $profileDuplicate->setFileLetter($cloneLetter);
  340.         $profileDuplicate->setFileReportCard1($cloneFileReportCard1);
  341.         $profileDuplicate->setFileReportCard2($cloneFileReportCard2);
  342.         $profileDuplicate->setFileReportCard3($cloneFileReportCard3);
  343.         $profileDuplicate->setFileIdentity($cloneFileIdentity);
  344.         $profileDuplicate->setFileResidencePermit($cloneFileResidencePermit);
  345.         $profileDuplicate->setFilePhoto($cloneFilePhoto);
  346.         $profileDuplicate->setFileHandicap($cloneFileHandicap);
  347.         $profileDuplicate->setSelectedProgram($programSelected);
  348.         $profileDuplicate->addProgram($programSelected);
  349.         $profileDuplicate->setCampus($campusSelected);
  350.         $profileDuplicate->setCampus1($campusSelected);
  351.         $profileDuplicate->setCampus2(null);
  352.         $profileDuplicate->setCampus3(null);
  353.         $year date("Y");
  354.         if(date("Y-m-d") > date("Y").'-10-01'){
  355.             $session date('Y'strtotime('+1 year')).'-'date('Y'strtotime('+2 year'));
  356.         }else{
  357.             $session $year.'-'date('Y'strtotime('+1 year'));
  358.         }
  359.         $profileDuplicate->setYear($session);
  360.         if($profile->getProfileNotes()){
  361.             foreach($profile->getProfileNotes() as $note){
  362.                 $profileDuplicate->addProfileNote(clone $note);
  363.             }
  364.         }
  365.         if($profile->getProfileFiles()){
  366.             foreach($profile->getProfileFiles() as $file){
  367.                 $profileDuplicate->addProfileFile(clone $file);
  368.             }
  369.         }
  370.         $profileDuplicate->setIsDuplicate(1);
  371.         $this->repository->save($profileDuplicate);
  372.         return $this->autoMapper->map($profileDuplicate'App\DTO\Profile\ProfileOutput');
  373.     }
  374.     public function updateProfileNotesAdmin($request)
  375.     {
  376.         $profile $this->get($request->get('id'));
  377.         if (!$profile) throw new NotFoundHttpException($this->translator->trans('profile_not_found'));
  378.         $statusOld $profile->getStatus()->getId();
  379.         $profile $this->update(
  380.             $profile,
  381.             $request,
  382.             null,
  383.             'App\DTO\Profile\AdminUpdateProfileNotesProfileInput',
  384.             'App\DTO\Profile\ProfileOutput',
  385.             false,
  386.             true
  387.         );
  388.         $this->handleSendMail($statusOld$profile);
  389.         return $profile;
  390.     }
  391.     public function checkProfileExpired(){
  392.         $profiles $this->repository->findAll();
  393.         foreach($profiles as $profile){
  394.             if(!$profile->getExpireIdentity() && !$profile->getExpireResidencePermit()) continue;
  395.             if($profile->getExpireIdentity()){
  396.                 $expireIdentity null;
  397.                 if($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+60 days'))){
  398.                     $expireIdentity Notification::EXPRIRE_TYPE_TWO_MONTH;
  399.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+30 days'))){
  400.                     $expireIdentity Notification::EXPRIRE_TYPE_ONE_MONTH;
  401.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+21 days'))){
  402.                     $expireIdentity Notification::EXPRIRE_TYPE_THREE_WEEK;
  403.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+14 days'))){
  404.                     $expireIdentity Notification::EXPRIRE_TYPE_TWO_WEEK;
  405.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+7 days'))){
  406.                     $expireIdentity Notification::EXPRIRE_TYPE_ONE_WEEK;
  407.                 }
  408.                 if($expireIdentity){
  409.                     $notification $this->notificationRepo->findOneBy(['profile' => $profile'type' => Notification::TYPE_IDENTITY]);
  410.                     if(!$notification){
  411.                         $notification = new Notification;
  412.                         $notification->setProfile($profile);
  413.                     }
  414.                     
  415.                     $notification->setType(Notification::TYPE_IDENTITY);
  416.                     $notification->setExpireType($expireIdentity);
  417.                     $notification->setIsSeen(null);
  418.                     $this->notificationService->repository->save($notification);
  419.                 }
  420.             }
  421.             if($profile->getExpireResidencePermit()){
  422.                 $expireResidencePermit null;
  423.                 if($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+60 days'))){
  424.                     $expireResidencePermit Notification::EXPRIRE_TYPE_TWO_MONTH;
  425.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+30 days'))){
  426.                     $expireResidencePermit Notification::EXPRIRE_TYPE_ONE_MONTH;
  427.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+21 days'))){
  428.                     $expireResidencePermit Notification::EXPRIRE_TYPE_THREE_WEEK;
  429.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+14 days'))){
  430.                     $expireResidencePermit Notification::EXPRIRE_TYPE_TWO_WEEK;
  431.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+7 days'))){
  432.                     $expireResidencePermit Notification::EXPRIRE_TYPE_ONE_WEEK;
  433.                 }
  434.                 if($expireResidencePermit){
  435.                     $notification $this->notificationRepo->findOneBy(['profile' => $profile'type' => Notification::TYPE_RESIDENCE_PERMIT]);
  436.                     if(!$notification){
  437.                         $notification = new Notification;
  438.                         $notification->setProfile($profile);
  439.                     }
  440.                     
  441.                     $notification->setType(Notification::TYPE_RESIDENCE_PERMIT);
  442.                     $notification->setExpireType($expireResidencePermit);
  443.                     $notification->setIsSeen(null);
  444.                     $this->notificationService->repository->save($notification);
  445.                 }
  446.             }
  447.         }
  448.     }
  449.     public function checkRegister(){
  450.         $profiles $this->repository->findAll();
  451.         foreach($profiles as $profile){
  452.             if($profile->getPercent() > 25 ) continue;
  453.             $day null;
  454.             if($profile->getCreatedDate()->format('Y-m-d') == date('Y-m-d',strtotime('-1 days'))){
  455.                 $day 1;
  456.             } elseif($profile->getCreatedDate()->format('Y-m-d') == date('Y-m-d',strtotime('-3 days'))){
  457.                 $day 3;
  458.             } elseif($profile->getCreatedDate()->format('Y-m-d') == date('Y-m-d',strtotime('-7 days'))){
  459.                 $day 7;
  460.             }
  461.             if($day){
  462.                 $this->userService->sendNotificationRegisterEmail($profile$day);
  463.             }
  464.         }
  465.     }
  466.     private function callQcmApi($data$url$method){
  467.         $requestJson json_encode($dataJSON_THROW_ON_ERROR);
  468.         $response $this->httpClient->request($method$this->container->getParameter('qcm_api_url').$url, [
  469.             'headers' => [
  470.                 'Content-Type: application/json',
  471.                 'Accept: application/json',
  472.             ],
  473.             'body' => $requestJson,
  474.         ]);
  475.         $responseJson $response->getContent();
  476.         $responseData json_decode($responseJsontrue);
  477.         return $responseData;
  478.     }
  479.     public function getQcmUrl($profile){
  480.         $data = [
  481.                 'email' => $profile['user']['email'],
  482.                 'password' => $profile['qcmToken']
  483.             ];
  484.         $requestJson json_encode($dataJSON_THROW_ON_ERROR);
  485.         $response $this->httpClient->request('POST'$this->container->getParameter('qcm_api_url').'/auth/one-time-token', [
  486.             'headers' => [
  487.                 'Content-Type: application/json',
  488.                 'Accept: application/json',
  489.             ],
  490.             'body' => $requestJson,
  491.         ]);
  492.         $responseJson $response->getContent();
  493.         $responseData json_decode($responseJsontrue);
  494.         $redirectUrl null;
  495.         if($responseData['success'] == true){
  496.             $redirectUrl $responseData['redirectUrl'];
  497.         }
  498.         return $redirectUrl;
  499.     }
  500.     public function getRandomComercialOfcampus($campusId)
  501.     {
  502.         $commercials $this->campusService->getListUsersActive($campusId);
  503.         if (empty($commercials) || count($commercials->toArray()) == 0) {
  504.             return null;
  505.         }
  506.         $randomKey array_rand($commercials->toArray());
  507.         $randomCommercial $commercials[$randomKey];
  508.         return $randomCommercial->getId() ?? null;
  509.     }
  510. }