src/Service/ProfileService.php line 44

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.         }
  138.         if($step4 && $profile->getStatus()->getId() < Status::STATUS_APPLICATION_RECEIVED){
  139.             $request->request->set('status'Status::STATUS_APPLICATION_RECEIVED);
  140.             if(!$request->get('isSent')){
  141.                 $request->request->set('isSent'1);
  142.                 
  143.                 //set profile sources
  144.                 $campaign $this->campaignService->get(Campaign::APPLICATION);
  145.                 if($campaign) {
  146.                     $this->profileSourceService->checkandAddProfileSource($profile$campaign->getName());
  147.                 }
  148.             }
  149.         }
  150.         // set profile sources
  151.         if ($request->get('openDay')) {
  152.             $openDay $this->opendayRepo->findOneBy(['id' => $request->get('openDay')]);
  153.             if($openDay) {
  154.                 $this->profileSourceService->checkandAddProfileSource($profile$openDay->getName());
  155.             }
  156.         }else if($request->get('landingpage')) {
  157.             $landingpage $this->landingpageRepo->findOneBy(['id' => $request->get('landingpage')]);
  158.             if($landingpage) {
  159.                 if($landingpage->isIsAgent()){
  160.                     $this->profileSourceService->checkandAddProfileSource($profile'LPA: ' .$landingpage->getName());
  161.                 }else{
  162.                     $this->profileSourceService->checkandAddProfileSource($profile'LP: ' .$landingpage->getName());
  163.                 }
  164.             }
  165.         }else if($request->get('campaign')) {
  166.             $campaign $this->campaignRepo->findOneBy(['id' => $request->get('campaign')]);
  167.             if($campaign) {
  168.                 $this->profileSourceService->checkandAddProfileSource($profile$campaign->getName());
  169.             }
  170.         }
  171.         if($request->get('campus1') && $request->get('campus1') != $profile->getCampus1()->getId()){
  172.             $request->request->set('campus'$request->get('campus1'));
  173.             $randCommercial $this->getRandomComercialOfcampus($request->get('campus1'));
  174.             if($randCommercial){
  175.                 $request->request->set('commercial'$randCommercial);
  176.             }
  177.         }
  178.         if($request->get('programs')){
  179.             $request->request->set('selectedProgram'$request->get('programs')[0]);
  180.         }
  181.         if($profile->isIsSent() && $request->get('campus1') != $profile->getCampus1()->getId()){
  182.             //send email change campus
  183.             if(isset(Common::listEmailAdmission()[$request->get('campus1')])){
  184.                 $this->userService->sendCampusEmail($profileCommon::listEmailAdmission()[$request->get('campus1')]);
  185.             }
  186.         }
  187.         return $this->update($profile$requestnull$DTO'ENTITY'falsetrue);
  188.     }
  189.     public function updateSelectedProgram($request$DTO 'App\DTO\Profile\AdminUpdateProfileSelectedProgramInput')
  190.     {
  191.         $profile $this->get($request->get('id'));
  192.         return $this->update($profile$requestnull$DTO'App\DTO\Profile\ProfileOutput'falsetrue);
  193.     }
  194.     public function handleSendMail($statusOld$profile)
  195.     {
  196.         // Send Mail if status update
  197.         if (
  198.             $statusOld != ($profile->status)['id']
  199.             && ($profile->status)['id'] >= Status::STATUS_APPLICATION_RECEIVED
  200.             && !$profile->isAgent
  201.         ) {
  202.             $this->userService->sendNotificationEmailUpdateStatus($profile);
  203.         }
  204.     }
  205.     public function updateProfileAdmin($request)
  206.     {
  207.         $profile $this->get($request->get('id'));
  208.         if (!$profile) throw new NotFoundHttpException($this->translator->trans('profile_not_found'));
  209.         $statusOld $profile->getStatus()->getId();
  210.         $input = [];
  211.         if ($request->get('jury')) {
  212.             $input['juryDate'] = new \DateTime('now');
  213.         }
  214.         if ($request->get('oraux')) {
  215.             $input['orauxDate'] = new \DateTime('now');
  216.         }
  217.         if($request->get('status') == Status::STATUS_JURY_ACCEPTED){
  218.             if($profile->getSelectedProgram()->getSpecialityId() && !$profile->getQcmToken()){
  219.                 $user $profile->getUser();
  220.                 $now = new \DateTime('now');
  221.                 $data = [
  222.                     'civility' => $user->getGender() == 'mrs' 'mr' ,
  223.                     'firstName' => $user->getFirstName(),
  224.                     'lastName' => $user->getLastName(),
  225.                     'email' => $user->getEmail(),
  226.                     'birthDate' => $user->getBirthDay() ? $user->getBirthDay()->format('Y-m-d') : $now->format('Y-m-d'),
  227.                     'phone' => $user->getPhone(),
  228.                     'speciality' => $profile->getSelectedProgram()->getSpecialityId()
  229.                 ];
  230.                 $responseQcm $this->callQcmApi($data'/auth/external/register''POST');
  231.                 if($responseQcm['success'] == true && $responseQcm['data']){
  232.                     $profile->setQcmToken($responseQcm['data']['password']);
  233.                     $dataQcmResults = [
  234.                         'isDoneTest' => $responseQcm['data']['isDoneTest'],
  235.                         'questions' => $responseQcm['data']['questions']
  236.                     ];
  237.                     $profile->setQcmResults($dataQcmResults);
  238.                 }
  239.             }elseif ($profile->getSelectedProgram()->getSpecialityId() && $profile->getQcmToken()){
  240.                 $data = [
  241.                     'email' => $profile->getUser()->getEmail(),
  242.                     'password' => $profile->getQcmToken(),
  243.                     'speciality' => $profile->getSelectedProgram()->getSpecialityId()
  244.                 ];
  245.                 $responseQcm $this->callQcmApi($data'/auth/external/user/update-speciality''PATCH');  
  246.                 $dataQcmResults = [
  247.                     'isDoneTest' => $responseQcm['data']['isDoneTest'],
  248.                     'questions' => $responseQcm['data']['questions']
  249.                 ];
  250.                 $profile->setQcmResults($dataQcmResults);
  251.             }
  252.         }
  253.         if($request->get('status') == Status::STATUS_INTERVIEW_INVITED && $profile->getQcmMethod() == Profile::QCM_LOCAL){
  254.             if($profile->getOraux()){
  255.                 $dateStartQCM $profile->getOraux()->getDate()->format('Y-m-d');
  256.                 $timeStartQCM $profile->getOraux()->getHour() ? $profile->getOraux()->getHour()->format(' H:i:s') : '';
  257.             }
  258.             if(!isset($timeStartQCM)){
  259.                 $orauxSelected $this->orauxService->get($request->get('oraux'));
  260.                 $dateStartQCM $orauxSelected->getDate()->format('Y-m-d');
  261.                 $timeStartQCM $orauxSelected->getHour() ? $orauxSelected->getHour()->format(' H:i:s') : '';
  262.             }
  263.             $data = [
  264.                 'email' => $profile->getUser()->getEmail(),
  265.                 'password' => $profile->getQcmToken(),
  266.                 'startTestAt' => (new \DateTime($dateStartQCM.$timeStartQCM, new \DateTimeZone($this->container->getParameter('fallback_timezone'))))->format(DATE_ATOM)
  267.             ];
  268.             $this->callQcmApi($data'/auth/external/user/update-start-test''PATCH');
  269.         }
  270.         if( $request->get('status') == Status::STATUS_STUDENT_ENROLLED ) {
  271.             $profile->setEnrolledDate(new \DateTime('now'));
  272.         }
  273.         // Check campus selected in list campus of commercial
  274.         // if ($inputCampus = $request->get('campus')) {
  275.         //     if ($commercial = $profile->getCommercial()) {
  276.         //         $campuses = [];
  277.         //         foreach ($commercial->getCampuses() as $campus) {
  278.         //             $campuses[] = $campus->getId();
  279.         //         }
  280.         //         if (!in_array($inputCampus, $campuses)) {
  281.         //             $input['commercial'] = 'isNull';
  282.         //         }
  283.         //     }
  284.         // }
  285.         $profile $this->update(
  286.             $profile,
  287.             $request,
  288.             $input,
  289.             'App\DTO\Profile\AdminUpdateProfileInput',
  290.             'App\DTO\Profile\ProfileOutput',
  291.             false,
  292.             true
  293.         );
  294.         $this->handleSendMail($statusOld$profile);
  295.         if($request->get('campus') && $request->get('campus') != $profile->campus1['id']){
  296.             if(isset(Common::listEmailAdmission()[$request->get('campus')])){
  297.                 $this->userService->sendCampusEmail($profileCommon::listEmailAdmission()[$request->get('campus')]);
  298.             }
  299.         }
  300.         return $profile;
  301.     }
  302.     public function updateProgramsAdmin($request)
  303.     {
  304.         $profile $this->get($request->get('id'));
  305.         if (!$profile) throw new NotFoundHttpException($this->translator->trans('profile_not_found'));
  306.         $statusOld $profile->getStatus()->getId();
  307.         $profile $this->update(
  308.             $profile,
  309.             $request,
  310.             null,
  311.             'App\DTO\Profile\AdminUpdateProgramsProfileInput',
  312.             'App\DTO\Profile\ProfileOutput',
  313.             false,
  314.             true
  315.         );
  316.         $this->handleSendMail($statusOld$profile);
  317.         return $profile;
  318.     }
  319.     public function duplicateProfile($request){
  320.         $profile $this->repository->find($request->get('id'));
  321.         $programSelected $this->programRepo->find($request->get('programId'));
  322.         $campusSelected $this->campusRepo->find($request->get('campusId'));
  323.         $cloneCV                    $profile->getFileCv() ? clone $profile->getFileCv() : null;
  324.         $cloneFileContract          $profile->getFileContract() ? clone $profile->getFileContract() : null;
  325.         $cloneLetter                $profile->getFileLetter() ? clone $profile->getFileLetter() : null;
  326.         $cloneFileReportCard1       $profile->getFileReportCard1() ? clone $profile->getFileReportCard1() : null;
  327.         $cloneFileReportCard2       $profile->getFileReportCard2() ? clone $profile->getFileReportCard2() : null;
  328.         $cloneFileReportCard3       $profile->getFileReportCard3() ? clone $profile->getFileReportCard3() : null;
  329.         $cloneFileIdentity          $profile->getFileIdentity() ? clone $profile->getFileIdentity() : null;
  330.         $cloneFileResidencePermit   $profile->getFileResidencePermit() ? clone $profile->getFileResidencePermit() : null;
  331.         $cloneFilePhoto             $profile->getFilePhoto() ? clone $profile->getFilePhoto() : null;
  332.         $cloneFileHandicap          $profile->getFileHandicap() ? clone $profile->getFileHandicap() : null;
  333.         $profileDuplicate = clone $profile;
  334.         $profileDuplicate->setFileCv($cloneCV);
  335.         $profileDuplicate->setFileContract($cloneFileContract);
  336.         $profileDuplicate->setFileLetter($cloneLetter);
  337.         $profileDuplicate->setFileReportCard1($cloneFileReportCard1);
  338.         $profileDuplicate->setFileReportCard2($cloneFileReportCard2);
  339.         $profileDuplicate->setFileReportCard3($cloneFileReportCard3);
  340.         $profileDuplicate->setFileIdentity($cloneFileIdentity);
  341.         $profileDuplicate->setFileResidencePermit($cloneFileResidencePermit);
  342.         $profileDuplicate->setFilePhoto($cloneFilePhoto);
  343.         $profileDuplicate->setFileHandicap($cloneFileHandicap);
  344.         $profileDuplicate->setSelectedProgram($programSelected);
  345.         $profileDuplicate->addProgram($programSelected);
  346.         $profileDuplicate->setCampus($campusSelected);
  347.         $profileDuplicate->setCampus1($campusSelected);
  348.         $profileDuplicate->setCampus2(null);
  349.         $profileDuplicate->setCampus3(null);
  350.         $year date("Y");
  351.         if(date("Y-m-d") > date("Y").'-10-01'){
  352.             $session date('Y'strtotime('+1 year')).'-'date('Y'strtotime('+2 year'));
  353.         }else{
  354.             $session $year.'-'date('Y'strtotime('+1 year'));
  355.         }
  356.         $profileDuplicate->setYear($session);
  357.         if($profile->getProfileNotes()){
  358.             foreach($profile->getProfileNotes() as $note){
  359.                 $profileDuplicate->addProfileNote(clone $note);
  360.             }
  361.         }
  362.         if($profile->getProfileFiles()){
  363.             foreach($profile->getProfileFiles() as $file){
  364.                 $profileDuplicate->addProfileFile(clone $file);
  365.             }
  366.         }
  367.         $profileDuplicate->setIsDuplicate(1);
  368.         $this->repository->save($profileDuplicate);
  369.         return $this->autoMapper->map($profileDuplicate'App\DTO\Profile\ProfileOutput');
  370.     }
  371.     public function updateProfileNotesAdmin($request)
  372.     {
  373.         $profile $this->get($request->get('id'));
  374.         if (!$profile) throw new NotFoundHttpException($this->translator->trans('profile_not_found'));
  375.         $statusOld $profile->getStatus()->getId();
  376.         $profile $this->update(
  377.             $profile,
  378.             $request,
  379.             null,
  380.             'App\DTO\Profile\AdminUpdateProfileNotesProfileInput',
  381.             'App\DTO\Profile\ProfileOutput',
  382.             false,
  383.             true
  384.         );
  385.         $this->handleSendMail($statusOld$profile);
  386.         return $profile;
  387.     }
  388.     public function checkProfileExpired(){
  389.         $profiles $this->repository->findAll();
  390.         foreach($profiles as $profile){
  391.             if(!$profile->getExpireIdentity() && !$profile->getExpireResidencePermit()) continue;
  392.             if($profile->getExpireIdentity()){
  393.                 $expireIdentity null;
  394.                 if($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+60 days'))){
  395.                     $expireIdentity Notification::EXPRIRE_TYPE_TWO_MONTH;
  396.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+30 days'))){
  397.                     $expireIdentity Notification::EXPRIRE_TYPE_ONE_MONTH;
  398.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+21 days'))){
  399.                     $expireIdentity Notification::EXPRIRE_TYPE_THREE_WEEK;
  400.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+14 days'))){
  401.                     $expireIdentity Notification::EXPRIRE_TYPE_TWO_WEEK;
  402.                 } elseif($profile->getExpireIdentity()->format('Y-m-d') == date('Y-m-d',strtotime('+7 days'))){
  403.                     $expireIdentity Notification::EXPRIRE_TYPE_ONE_WEEK;
  404.                 }
  405.                 if($expireIdentity){
  406.                     $notification $this->notificationRepo->findOneBy(['profile' => $profile'type' => Notification::TYPE_IDENTITY]);
  407.                     if(!$notification){
  408.                         $notification = new Notification;
  409.                         $notification->setProfile($profile);
  410.                     }
  411.                     
  412.                     $notification->setType(Notification::TYPE_IDENTITY);
  413.                     $notification->setExpireType($expireIdentity);
  414.                     $notification->setIsSeen(null);
  415.                     $this->notificationService->repository->save($notification);
  416.                 }
  417.             }
  418.             if($profile->getExpireResidencePermit()){
  419.                 $expireResidencePermit null;
  420.                 if($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+60 days'))){
  421.                     $expireResidencePermit Notification::EXPRIRE_TYPE_TWO_MONTH;
  422.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+30 days'))){
  423.                     $expireResidencePermit Notification::EXPRIRE_TYPE_ONE_MONTH;
  424.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+21 days'))){
  425.                     $expireResidencePermit Notification::EXPRIRE_TYPE_THREE_WEEK;
  426.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+14 days'))){
  427.                     $expireResidencePermit Notification::EXPRIRE_TYPE_TWO_WEEK;
  428.                 } elseif($profile->getExpireResidencePermit()->format('Y-m-d') == date('Y-m-d',strtotime('+7 days'))){
  429.                     $expireResidencePermit Notification::EXPRIRE_TYPE_ONE_WEEK;
  430.                 }
  431.                 if($expireResidencePermit){
  432.                     $notification $this->notificationRepo->findOneBy(['profile' => $profile'type' => Notification::TYPE_RESIDENCE_PERMIT]);
  433.                     if(!$notification){
  434.                         $notification = new Notification;
  435.                         $notification->setProfile($profile);
  436.                     }
  437.                     
  438.                     $notification->setType(Notification::TYPE_RESIDENCE_PERMIT);
  439.                     $notification->setExpireType($expireResidencePermit);
  440.                     $notification->setIsSeen(null);
  441.                     $this->notificationService->repository->save($notification);
  442.                 }
  443.             }
  444.         }
  445.     }
  446.     public function checkRegister(){
  447.         $profiles $this->repository->findAll();
  448.         foreach($profiles as $profile){
  449.             if($profile->getPercent() > 25 ) continue;
  450.             $day null;
  451.             if($profile->getCreatedDate()->format('Y-m-d') == date('Y-m-d',strtotime('-1 days'))){
  452.                 $day 1;
  453.             } elseif($profile->getCreatedDate()->format('Y-m-d') == date('Y-m-d',strtotime('-3 days'))){
  454.                 $day 3;
  455.             } elseif($profile->getCreatedDate()->format('Y-m-d') == date('Y-m-d',strtotime('-7 days'))){
  456.                 $day 7;
  457.             }
  458.             if($day){
  459.                 $this->userService->sendNotificationRegisterEmail($profile$day);
  460.             }
  461.         }
  462.     }
  463.     private function callQcmApi($data$url$method){
  464.         $requestJson json_encode($dataJSON_THROW_ON_ERROR);
  465.         $response $this->httpClient->request($method$this->container->getParameter('qcm_api_url').$url, [
  466.             'headers' => [
  467.                 'Content-Type: application/json',
  468.                 'Accept: application/json',
  469.             ],
  470.             'body' => $requestJson,
  471.         ]);
  472.         $responseJson $response->getContent();
  473.         $responseData json_decode($responseJsontrue);
  474.         return $responseData;
  475.     }
  476.     public function getQcmUrl($profile){
  477.         $data = [
  478.                 'email' => $profile['user']['email'],
  479.                 'password' => $profile['qcmToken']
  480.             ];
  481.         $requestJson json_encode($dataJSON_THROW_ON_ERROR);
  482.         $response $this->httpClient->request('POST'$this->container->getParameter('qcm_api_url').'/auth/one-time-token', [
  483.             'headers' => [
  484.                 'Content-Type: application/json',
  485.                 'Accept: application/json',
  486.             ],
  487.             'body' => $requestJson,
  488.         ]);
  489.         $responseJson $response->getContent();
  490.         $responseData json_decode($responseJsontrue);
  491.         $redirectUrl null;
  492.         if($responseData['success'] == true){
  493.             $redirectUrl $responseData['redirectUrl'];
  494.         }
  495.         return $redirectUrl;
  496.     }
  497.     public function getRandomComercialOfcampus($campusId)
  498.     {
  499.         $commercials $this->campusService->getListUsersActive($campusId);
  500.         if (empty($commercials) || count($commercials->toArray()) == 0) {
  501.             return null;
  502.         }
  503.         $randomKey array_rand($commercials->toArray());
  504.         $randomCommercial $commercials[$randomKey];
  505.         return $randomCommercial->getId() ?? null;
  506.     }
  507. }