src/Controller/HomePageController.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\RequestPayload;
  4. use App\Entity\PromozioniPortale;
  5. use App\Entity\SegnalazioniPortale;
  6. use App\Entity\SegnalazioniPortaleList;
  7. use App\Security\Users;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security as SecurityGranted;
  14. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  15. use Symfony\Component\Security\Core\Security;
  16. /**
  17.  *  Richiediamo il ROLE_USER per ogni metodo presente in questo controller.
  18.  *
  19.  * @SecurityGranted("is_granted('ROLE_USER')")
  20.  ***/
  21. class HomePageController extends AbstractController
  22. {
  23.     private $webservice;
  24.     private $id_contatto;
  25.     private Users $user;
  26.     private $urlGenerator;
  27.     private $feeds = [];
  28.     private $feedsPA = [];
  29.     /*
  30.      * @string stringa che contiene la lista degli ambiti utente concatenati per recuperare le segnalazioni
  31.      */
  32.     private string $strAmbitiUtente;
  33.     public function __construct(string $kpm_ws_endpointstring $kpm_ws_endpoint_userstring $kpm_ws_endpoint_password,UrlGeneratorInterface $urlGenerator)
  34.     {
  35.         $this->webservice = new WebServiceController($kpm_ws_endpoint$kpm_ws_endpoint_user$kpm_ws_endpoint_password);
  36.         $this->urlGenerator $urlGenerator;
  37.     }
  38.     /**
  39.      * @Route("/", name="home_page")
  40.      */
  41.     public function index(Security $securityRequest $request): Response
  42.     {
  43.         /**
  44.          * @var $this- >user Users
  45.          */
  46.         $this->user $security->getUser();
  47.         $error $request->get('error');
  48.         if ($error == '') {
  49.             $session $request->getSession();
  50.             $error $session->get('error');
  51.             if ($error != '')
  52.                 $session->set('error''');
  53.         }
  54.         $recordfound false;
  55.         //print_r($this->user->getId());
  56.         $tickets = [];
  57.         $servizi = [];
  58.         if ($this->user) {
  59.             /*
  60.         * gestione cards Formazione e Promozioni
  61.         */
  62.             $contactid $this->user->getId();
  63.             $rec_formazione = [];
  64.             $rec_promozione = [];
  65.             $rec_news = [];
  66.             $rec_eventi = [];
  67.           #  $rec_formazione = $this->getRecords('Formazione', 4);
  68.             $rec_formazione $this->getRecordsProfiled('Formazione',$contactid);
  69.             $this->shuffle_with_keys($rec_formazione);
  70.             //ADD PROFILAZIONE
  71.             $rec_formazione array_slice($rec_formazione06);
  72.           #  $rec_promozione = $this->getRecords('Promozione', 12);
  73.             $rec_promozione $this->getRecordsProfiled('Promozione',$contactid);
  74.             $this->shuffle_with_keys($rec_promozione);
  75.             $rec_promozione array_slice($rec_promozione06);
  76.             $str_feeds $session->get('feeds');
  77.             $this->feeds = new \SimpleXMLElement($str_feeds);
  78.             $rec_news $this->getNewsFromFeed(); //$this->getRecords('News',3);
  79.             $str_feedsPA $session->get('feedsPA');
  80.             $this->feedsPA = new \SimpleXMLElement($str_feedsPA);
  81.             $rec_newslinkpa $this->getNewsLinkPA();
  82.             $rec_webinar $this->getNewsFromFeed(true);
  83.             $recordfound true;
  84.             $account $this->user->getAccount();
  85.             #TODO gestire $csrfToken
  86.             #$csrfToken = $request->request->get('_csrf_token');
  87.             #RECUPERIAMO I TICKET
  88.             $body_params = new \stdClass;
  89.             $body_params->mine 'true';
  90.             $body_params->macrotipo 'SW';
  91.             $body_params->contactid $this->user->getId();
  92.             $body_params->accountid $account->getId();
  93.             $body_params->countstatus true;
  94.             $payload = new RequestPayload();
  95.             $payload->setClass("HelpDesk");
  96.             $payload->setMethod("getTickets");
  97.             $payload->setParameters($body_params);
  98.             $ws_response $this->webservice->call($payload);
  99.             $return_gettickets $ws_response->getData();
  100.             if ($ws_response->isSuccess()) {
  101.                 $tickets $return_gettickets;
  102.             }
  103.             $segnalazioni = [];
  104.             $segnalazioniPortlaleList $this->getSegnalazioniWS();
  105.             foreach ($segnalazioniPortlaleList->getAll() as $segnalazione) {
  106.                 $segnalazioni[] = $segnalazione;
  107.             }
  108.             #RECUPERIAMO I SERVIZI
  109.             $body_params->macrotipo 'servizi';
  110.             $payload = new RequestPayload();
  111.             $payload->setClass("HelpDesk");
  112.             $payload->setMethod("getTickets");
  113.             $payload->setParameters($body_params);
  114.             $ws_response $this->webservice->call($payload);
  115.             $return_gettickets $ws_response->getData();
  116.             if ($ws_response->isSuccess()) {
  117.                 $servizi $return_gettickets;
  118.             }
  119.         }
  120.         return $this->render('home_page/home.html.twig', [
  121.             'controller_name' => 'HomePageController''recordfound' => $recordfound'tickets' => $tickets,
  122.             'servizi' => $servizi'segnalazioni' => $segnalazioni,
  123.             'rec_formazione' => $rec_formazione,
  124.             'rec_promozione' => $rec_promozione,
  125.             'rec_news' => $rec_news,
  126.             'rec_eventi' => $rec_webinar,
  127.             'rec_newslinkpa' => $rec_newslinkpa,
  128.             'error' => $error,
  129.         ]);
  130.     }
  131.     /*
  132.      * funzione che prende i record di formazione da WS
  133.      */
  134.     private function getRecords($tipo$limit): array
  135.     {
  136.         $body_params = new \stdClass;
  137.         $body_params->tipo_promozione $tipo;
  138.         $body_params->limit $limit;
  139.         $payload = new RequestPayload();
  140.         $payload->setClass("Promozioni");
  141.         $payload->setMethod("getPromozioniList");
  142.         $payload->setParameters($body_params);
  143.         $ws_response $this->webservice->call($payload);
  144.         $promozioni = [];
  145.         $email "";
  146.         //dobbiamo recuperare la email del contatto utilizzato e completare l'url ,altrimenti rimane vuota
  147.         $email $this->user->getEmail();
  148.         if ($ws_response->isSuccess() == 1) {
  149.             foreach ($ws_response->getData() as $promorec) {
  150.                 $promo = new PromozioniPortale();
  151.                 $promo->promozionecreatedtime $promorec['promozionecreatedtime'];
  152.                 $promo->promozionemodifiedtime $promorec['promozionemodifiedtime'];
  153.                 $promo->promozione_no $promorec['promozione_no'];
  154.                 $promo->bu_mc $promorec['bu_mc'];
  155.                 $promo->nome_promozione $promorec['nome_promozione'];
  156.                 $promo->descrizione $promorec['descrizione'];
  157.                 $promo->tag $promorec['tag'];
  158.                 $promo->datafine $promorec['datafine'];
  159.                 $promo->datainizio $promorec['datainizio'];
  160.                 $promo->modalita $promorec['modalita'];
  161.                 $promo->promozioniportaleid $promorec['promozioniportaleid'];
  162.                 $promo->tipo_promozione $promorec['tipo_promozione'];
  163.                 ($promo->modalita == 'Webinar') ? $promo->url_riferimento $promorec['url_riferimento'] . $email $promo->url_riferimento $promorec['url_riferimento'];
  164.                 $promo->area $promorec['area'];
  165.                 $promozioni[] = $promo;
  166.             }
  167.         }
  168.         return $promozioni;
  169.     }
  170.     /*
  171.  * funzione che prende i record di formazione da WS
  172.  */
  173.     private function getRecordsProfiled($tipo,$contactid): array
  174.     {
  175.         $body_params = new \stdClass;
  176.         $body_params->tipo_promozione $tipo;
  177.         $body_params->contactid $contactid;
  178.         $payload = new RequestPayload();
  179.         $payload->setClass("Promozioni");
  180.         $payload->setMethod("getPromozioniListProfiled");
  181.         $payload->setParameters($body_params);
  182.         #die(var_dump($payload));
  183.         $ws_response $this->webservice->call($payload);
  184.         $promozioni = [];
  185.         $email "";
  186.         //dobbiamo recuperare la email del contatto utilizzato e completare l'url ,altrimenti rimane vuota
  187.         $email $this->user->getEmail();
  188.         if ($ws_response->isSuccess() == 1) {
  189.             foreach ($ws_response->getData() as $promorec) {
  190.                 $promo = new PromozioniPortale();
  191.                 $promo->promozionecreatedtime $promorec['promozionecreatedtime'];
  192.                 $promo->promozionemodifiedtime $promorec['promozionemodifiedtime'];
  193.                 $promo->promozione_no $promorec['promozione_no'];
  194.                 $promo->bu_mc $promorec['bu_mc'];
  195.                 $promo->nome_promozione $promorec['nome_promozione'];
  196.                 $promo->descrizione $promorec['descrizione'];
  197.                 $promo->tag $promorec['tag'];
  198.                 $promo->datafine $promorec['datafine'];
  199.                 $promo->datainizio $promorec['datainizio'];
  200.                 $promo->modalita $promorec['modalita'];
  201.                 $promo->promozioniportaleid $promorec['promozioniportaleid'];
  202.                 $promo->tipo_promozione $promorec['tipo_promozione'];
  203.                 ($promo->modalita == 'Webinar') ? $promo->url_riferimento $promorec['url_riferimento'] . $email $promo->url_riferimento $promorec['url_riferimento'];
  204.                 $promo->area $promorec['area'];
  205.                 $promo->algoritmo $promorec['algoritmo'];
  206.                 $promozioni[] = $promo;
  207.             }
  208.         }
  209.         return $promozioni;
  210.     }
  211.     private function getNewsFromFeed($onlyWebinar false): array
  212.     {
  213.         $news = [];
  214.         $url "https://www.gruppokib.it/feed/";
  215.         $conta 0;
  216.         if (count($this->feeds) == 0) {
  217.             if (@simplexml_load_file($url)) {
  218.                 $this->feeds simplexml_load_file($url);
  219.             }
  220.         }
  221.         foreach ($this->feeds->channel->item as $feed) {
  222.             if ($conta >= 3)
  223.                 continue;
  224.             $strCategorie "";
  225.             foreach ($feed->category as $category) {
  226.                 $strCategorie .= "," $category;
  227.             }
  228.             if ($onlyWebinar) {
  229.                 if (strpos(strtolower($strCategorie), "webinar") === false)
  230.                     continue;
  231.             } else {
  232.                 if (strpos(strtolower($strCategorie), "webinar"))
  233.                     continue;
  234.             }
  235.             $promo = new PromozioniPortale();
  236.             $data date('d-m-Y'strtotime($feed->pubDate));
  237.             $promo->promozionecreatedtime $data;
  238.             $promo->promozionemodifiedtime $feed->pubDate;
  239.             $promo->nome_promozione = (string)($feed->title);
  240.             $promo->datafine $data;
  241.             $promo->datainizio $data;
  242.             $promo->url_riferimento $feed->guid;
  243.             $news[] = $promo;
  244.             $conta++;
  245.         }
  246.         return $news;
  247.     }
  248.     private function getNewsLinkPA(): array
  249.     {
  250.         $news = [];
  251.         $url "https://linkpa.it/feed/";
  252.         $conta 0;
  253.         if (count($this->feedsPA) == 0) {
  254.             if (@simplexml_load_file($url)) {
  255.                 $this->feeds simplexml_load_file($url);
  256.             }
  257.         }
  258.         foreach ($this->feedsPA->channel->item as $feed) {
  259.             //print_r($feed);
  260.             if ($conta >= 4)
  261.                 continue;
  262.             $strCategorie "";
  263.             foreach ($feed->category as $category) {
  264.                 $strCategorie .= "," $category;
  265.             }
  266.             /*if ($onlyWebinar) {
  267.                 if (strpos(strtolower($strCategorie), "webinar") === false)
  268.                     continue;
  269.             } else {
  270.                 if (strpos(strtolower($strCategorie), "webinar"))
  271.                     continue;
  272.             }*/
  273.             $promo = new PromozioniPortale();
  274.             $data date('d-m-Y'strtotime($feed->pubDate));
  275.             $promo->promozionecreatedtime $data;
  276.             $promo->promozionemodifiedtime $feed->pubDate;
  277.             $promo->nome_promozione = (string)($feed->title);
  278.             $promo->datafine $data;
  279.             $promo->datainizio $data;
  280.             $promo->url_riferimento $feed->guid;
  281.             $news[] = $promo;
  282.             $conta++;
  283.         }
  284.         return $news;
  285.     }
  286.     private function getSegnalazioniWS(): SegnalazioniPortaleList
  287.     {
  288.         //dobbiamo recuperare gli ambiti dell'utente per passarli al WS che ritornerà solo le segnalazioni che riguardano l'utente
  289.         $ambiti $this->user->getAmbitiSw();
  290.         $ambiti1 $this->user->getAmbitiServizi();
  291.         $ambiti $ambiti ' |##| ' $ambiti1;
  292.         $segnalazioni = new SegnalazioniPortaleList();
  293.         $body_params = new \stdClass;
  294.         $body_params->ambiti $ambiti;
  295.         $payload = new RequestPayload();
  296.         $payload->setClass("Segnalazioni");
  297.         $payload->setMethod("getSegnalazioniList");
  298.         $payload->setParameters($body_params);
  299.         $ws_response $this->webservice->call($payload);
  300.         if ($ws_response->isSuccess() == 1) {
  301.             foreach ($ws_response->getData() as $segnalaz) {
  302.                 $segnalazione = new SegnalazioniPortale();
  303.                 $segnalazione->setSegnalazioneNo($segnalaz['segnalazione_no']);
  304.                 $segnalazione->setId($segnalaz['segnalazioniportaleid']);
  305.                 $segnalazione->setNomeSegnalazione($segnalaz['nome_segnalazione']);
  306.                 $segnalazione->setDescrizione($segnalaz['descrizione']);
  307.                 $segnalazione->setDataInizio($segnalaz['data_inizio']);
  308.                 $segnalazione->setOraInizio($segnalaz['ora_inizio']);
  309.                 $segnalazione->setDataFine($segnalaz['data_fine']);
  310.                 $segnalazione->setOraFine($segnalaz['ora_fine']);
  311.                 $segnalazione->setStatoUrgenza($segnalaz['stato_urgenza']);
  312.                 $segnalazione->setAmbiti($segnalaz['category']);
  313.                 $segnalazioni->add($segnalazione);
  314.             }
  315.         }
  316.         return $segnalazioni;
  317.     }
  318.     /**
  319.      * @Route("/consenso-privacy", name="app_set_consenso")
  320.      */
  321.     public function setConsensoPrivacy(Request $request,Security $security): response
  322.     {
  323.         $consenso $request->get('consenso');
  324.         $user $security->getUser();
  325.         $userid $security->getUser()->getId();
  326.         $body_params = new \stdClass;
  327.         $body_params->contactid $userid;
  328.         $body_params->consenso_utilizzo_dati $consenso;
  329.         $payload = new RequestPayload();
  330.         $payload->setClass("Authenticate");
  331.         $payload->setMethod("setConsensoPrivacy");
  332.         $payload->setParameters($body_params);
  333.         $ws_response $this->webservice->call($payload);
  334.         if ($ws_response->isSuccess() == 1) {
  335.         } else {
  336.         }
  337.         $user->setConsenso_utilizzo_dati($consenso);
  338.         $referal 'home_page';
  339.         $referal_url $this->urlGenerator->generate($referal);
  340.         return new RedirectResponse($referal_url);
  341.     }
  342.     /**
  343.      * @Route("/nascondi-Wizard", name="app_nascondiWizard")
  344.      */
  345.     public function nascondiWizard(Request $requestSecurity $security): response
  346.     {
  347.         $user $security->getUser();
  348.         $userid $security->getUser()->getId();
  349.         $body_params = new \stdClass;
  350.         $body_params->contactid $userid;
  351.         $payload = new RequestPayload();
  352.         $payload->setClass("Authenticate");
  353.         $payload->setMethod("nascondiWizard");
  354.         $payload->setParameters($body_params);
  355.         $ws_response $this->webservice->call($payload);
  356.         if ($ws_response->isSuccess() == 1) {
  357.         } else {
  358.         }
  359.         $user->setNascondiWizard(true);
  360.         $referal 'home_page';
  361.         $referal_url $this->urlGenerator->generate($referal);
  362.         return new RedirectResponse($referal_url);
  363.     }
  364.     /**
  365.      * @Route("/register-click/{id_enc}/{posizione}/{setype}/{algoritmo}/{referer}/", name="app_registerClick" )
  366.      */
  367.     public function registerClick(Request $request,Security $security$id_enc$posizione$setype$algoritmo,$referer) :response
  368.     {
  369.         $user $security->getUser();
  370.         //MM 13-07-2023 dobbiamo gestire le chiamate pre-login quindi se non abbiamo l'user
  371.         //loggato dobbiamo valorizzare $userid a 0
  372.         if(!$user == null) {
  373.             $userid $security->getUser()->getId();
  374.         }
  375.         else
  376.         {
  377.             $userid 0;
  378.         }
  379.         $caller_ip $request->getClientIp();
  380.         $promozione = new PromozioniPortale();
  381.         $id $promozione->fromFollowLink($id_enc);
  382.         $focus $this->getEntityWS($id,$setype);
  383.         foreach ($focus as $mod_field => $val){
  384.             $promozione->$mod_field $val;
  385.         }
  386.         $ambiti_sw_arr = array();
  387.         $ambiti_servizi_arr = array();
  388.         //MM 13-07-2023 facciamo solo se siamo loggati
  389.         $ambiti_str "";
  390.         if(!$user == null) {
  391.             if (!empty($user->getAmbitiSw())) {
  392.                 $ambiti_sw_arr explode(' |##| '$user->getAmbitiSw());
  393.             }
  394.             if (!empty($user->getAmbitiServizi())) {
  395.                 $ambiti_servizi_arr explode(' |##| '$user->getAmbitiServizi());
  396.             }
  397.             $ambiti_arr array_merge($ambiti_servizi_arr,$ambiti_sw_arr);
  398.             $ambiti_str implode(' |##| ',$ambiti_arr);
  399.         }
  400.         $body_params = new \stdClass;
  401.         $body_params->contactid $userid;
  402.         $body_params->crmid $id;
  403.         $body_params->posizione $posizione;
  404.         $body_params->url $promozione->url_riferimento;
  405.         $body_params->setype $setype;
  406.         $body_params->portaltype $promozione->tipo_promozione;
  407.         $body_params->tags $promozione->tag;
  408.         $body_params->algoritmo $algoritmo;
  409.         $body_params->ambiti $ambiti_str;
  410.         $body_params->referer $referer;
  411.         $body_params->caller_ip $caller_ip;
  412.         $payload = new RequestPayload();
  413.         $payload->setClass("Utils");
  414.         $payload->setMethod("setClick");
  415.         $payload->setParameters($body_params);
  416.         if($user->getConsenso_utilizzo_dati()=='Sì') {
  417.             $ws_response $this->webservice->call($payload);
  418.             if ($ws_response->isSuccess() == 1) {
  419.             } else {
  420.             }
  421.         }
  422.         return new RedirectResponse($promozione->url_riferimento);
  423.     }
  424.     /**
  425.      * @Route("/home_redirect-Generic/{url}/{setype}/{algoritmo}/{referer}/", name="app_home_registerClickGeneric" )
  426.      */
  427.     public function registerClickGeneric(Request $request,Security $securitystring $urlstring $setypestring $algoritmostring $referer) :response
  428.     {
  429.         $user $security->getUser();
  430.         //MM 13-07-2023 dobbiamo gestire le chiamate pre-login quindi se non abbiamo l'user
  431.         //loggato dobbiamo valorizzare $userid a 0
  432.         if(!$user == null) {
  433.             $userid $security->getUser()->getId();
  434.         }
  435.         else
  436.         {
  437.             $userid 0;
  438.         }
  439.         $url strtr($url'_''/');
  440.         //MM 13-07-2023 facciamo solo se siamo loggati
  441.         $ambiti_str "";
  442.         if(!$user == null) {
  443.             if (!empty($user->getAmbitiSw())) {
  444.                 $ambiti_sw_arr explode(' |##| '$user->getAmbitiSw());
  445.             }
  446.             if (!empty($user->getAmbitiServizi())) {
  447.                 $ambiti_servizi_arr explode(' |##| '$user->getAmbitiServizi());
  448.             }
  449.             $ambiti_arr array_merge($ambiti_servizi_arr,$ambiti_sw_arr);
  450.             $ambiti_str implode(' |##| ',$ambiti_arr);
  451.         }
  452.         $caller_ip $request->getClientIp();
  453.         $body_params = new \stdClass;
  454.         $body_params->contactid $userid;
  455.         $body_params->crmid 0;
  456.         $body_params->posizione 0;
  457.         $body_params->url $url;
  458.         $body_params->setype $setype;
  459.         $body_params->portaltype '';
  460.         $body_params->tags "";
  461.         $body_params->algoritmo $algoritmo;
  462.         $body_params->ambiti $ambiti_str;
  463.         $body_params->referer $referer;
  464.         $body_params->caller_ip $caller_ip;
  465.         $payload = new RequestPayload();
  466.         $payload->setClass("Utils");
  467.         $payload->setMethod("setClick");
  468.         $payload->setParameters($body_params);
  469.         if($userid == 0)
  470.         {
  471.             $ws_response $this->webservice->call($payload);
  472.             if ($ws_response->isSuccess() == 1) {
  473.             } else {
  474.             }
  475.         }else
  476.         {
  477.             if($user->getConsenso_utilizzo_dati()=='Sì') {
  478.                 $ws_response $this->webservice->call($payload);
  479.                 if ($ws_response->isSuccess() == 1) {
  480.                 } else {
  481.                 }
  482.             }
  483.         }
  484.         return new RedirectResponse($url);
  485.     }
  486.     function shuffle_with_keys(&$array)
  487.     {
  488.         /* Auxiliary array to hold the new order */
  489.         $aux = array();
  490.         /* We work with an array of the keys */
  491.         $keys array_keys($array);
  492.         /* We shuffle the keys */
  493.         shuffle($keys);
  494.         /* We iterate thru' the new order of the keys */
  495.         foreach ($keys as $key) {
  496.             /* We insert the key, value pair in its new order */
  497.             $aux[$key] = $array[$key];
  498.             /* We remove the element from the old array to save memory */
  499.             unset($array[$key]);
  500.         }
  501.         $array $aux;
  502.     }
  503.     private function getEntityWS($id,$module){
  504.         $body_params = new \stdClass;
  505.         $body_params->id $id;
  506.         $body_params->module $module;
  507.         $payload = new RequestPayload();
  508.         $payload->setClass("Utils");
  509.         $payload->setMethod("retrieveEntityModelWS");
  510.         $payload->setParameters($body_params);
  511.         $ws_response $this->webservice->call($payload);
  512.         if ($ws_response->isSuccess() == 1) {
  513.             $focus $ws_response->getData();
  514.         }
  515.         return $focus;
  516.     }
  517. }