src/Controller/CoreController.php line 68

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use DateTime;
  4. use App\Entity\User;
  5. use App\Entity\Alert;
  6. use App\Entity\Actor;
  7. use App\Entity\Pcode;
  8. use App\Entity\Person;
  9. use App\Entity\Cluster;
  10. use App\Entity\Project;
  11. use App\Entity\ProjectDetail;
  12. use App\Entity\AlertDetail;
  13. use App\Entity\MovementDetail;
  14. use SimpleXMLElement;
  15. use GuzzleHttp\Client;
  16. use App\Event\AppEvents;
  17. use Lcobucci\JWT\Parser;
  18. use Lcobucci\JWT\Builder;
  19. use App\AppTools\AppUtils;
  20. use App\Entity\Idps;
  21. use App\Entity\VodacomCToB;
  22. use App\Mercure\JwtProvider;
  23. use Lcobucci\JWT\Signer\Key;
  24. use App\Event\PlatformEvents;
  25. use App\Event\MessagePostEvent;
  26. //Conversion JSON
  27. use Lcobucci\JWT\ValidationData;
  28. use Lcobucci\JWT\Parsing\Decoder;
  29. use Lcobucci\JWT\Signer\Hmac\Sha256;
  30. use Symfony\Component\Mercure\Update;
  31. use App\Service\MercureCookieGenerator;
  32. use Doctrine\ORM\EntityManagerInterface;
  33. use GuzzleHttp\Exception\GuzzleException;
  34. use Symfony\Component\Serializer\Serializer;
  35. use Symfony\Component\HttpFoundation\Request;
  36. use Symfony\Component\HttpFoundation\Response;
  37. use Symfony\Component\Mercure\PublisherInterface;
  38. use Symfony\Component\Validator\Constraints\Json;
  39. use Symfony\Component\HttpFoundation\JsonResponse;
  40. use Symfony\Component\EventDispatcher\GenericEvent;
  41. use Symfony\Component\Messenger\MessageBusInterface;
  42. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  43. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  44. use Symfony\Component\Serializer\SerializerInterface;
  45. use Symfony\Component\Routing\Annotation\Route;
  46. //use Lcobucci\JWT\Signer\Rsa\Sha256;
  47. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  48. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  49. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  50. use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcherEvent;
  51. class CoreController extends AbstractController
  52. {
  53.     private $serializer;
  54.     private $appUtils;
  55.     private $em;
  56.     public function __construct(SerializerInterface $serializerEntityManagerInterface $emAppUtils $appUtils)
  57.     {
  58.         $this->serialize $serializer;
  59.         $this->appUtils $appUtils;
  60.         $this->em $em;
  61.     }
  62.     public function index(Request $request)
  63.     {
  64.         //$em = $this->em->getManager();
  65.         //#[Route('/cd', name: 'app_drc', methods: ['GET', 'POST'])]
  66.         
  67.         //$numberAlerts = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1'))));
  68.         $numberAlerts $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('cd')[0]["alertSignalE"]);
  69.         $numberAlertEvaluE $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('cd')[0]["alertEvaluE"]);
  70.         //$numberAlertEvaluE = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1', 'isDeleted' => '0'))));
  71.         $numberActor $this->_convertUnit(count($this->em->getRepository(Actor::class)->findAllOperationnel()));
  72.         $numberPersMoved $this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(1));  // 1 = population déplacé
  73.         $numberPersReturn $this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(2));  // 2 = population Retourné
  74.         $numberPersMovedAr $this->em->getRepository(Idps::class)->findDeplaced()[0];  // 1 = population déplacé
  75.         $numberPersReturnAr $this->em->getRepository(Idps::class)->findReturn()[0];  // 2 = population Retourné
  76.     
  77.         $numberPersMovedFx =  $numberPersMovedAr->getPerson();
  78.         $numberPersReturnFx =  $numberPersReturnAr->getPerson();
  79.         // dump($numberPersMovedFx);
  80.         // dump($numberPersReturnFx);
  81.         $allProvinces $this->em->getRepository(Pcode::class)->getAllProvinces([]);
  82.         
  83.         $allByProvinces $this->em->getRepository(Pcode::class)->getAllByProvinces([]);
  84.         
  85.         return $this->render('core/home.html.twig', [
  86.             'controller_name' => 'CoreController''adminID' => 'CD''numberAlerts' => $numberAlerts'numberAlertEvaluE' => $numberAlertEvaluE'numberPersMoved' => $numberPersMoved'numberPersReturn' => $numberPersReturn'numberActor' => $numberActor'allProvinces' => $allProvinces'allByProvinces' => $allByProvinces,
  87.             'numberPersReturnFx' => $numberPersReturnFx'numberPersMovedFx'=>$numberPersMovedFx'numberPersMovedAr' => $numberPersMovedAr'numberPersReturnAr' =>$numberPersReturnAr
  88.         ]);
  89.     }
  90.     public function index2(Request $request)
  91.     {
  92.         //$em = $this->em->getManager();
  93.         
  94.         //$numberAlerts = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1'))));
  95.         $numberAlerts $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('africa')[0]["alertSignalE"]);
  96.         $numberAlertEvaluE $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('africa')[0]["alertEvaluE"]);
  97.         $numberNonAlertEvaluE $this->_convertUnit(($this->em->getRepository(Pcode::class)->alertStatut('africa')[0]["alertSignalE"])-($this->em->getRepository(Pcode::class)->alertStatut('africa')[0]["alertEvaluE"]));
  98.         //$numberActor = $this->_convertUnit(count($this->em->getRepository(Actor::class)->findAllOperationnel()));
  99.         //$numberPersMoved = $this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(1));  // 1 = population déplacé
  100.         //$numberPersReturn = $this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(2));  // 2 = population Retourné
  101.         //$numberPersMovedAr = $this->em->getRepository(Idps::class)->findDeplaced()[0];  // 1 = population déplacé
  102.         //$numberPersReturnAr = $this->em->getRepository(Idps::class)->findReturn()[0];  // 2 = population Retourné
  103.         $allPays $this->em->getRepository(Pcode::class)->getAllPays();
  104.         
  105.         $allByPays $this->em->getRepository(Pcode::class)->getAllByPays();
  106.         
  107.         return $this->render('core/homepage.html.twig', [
  108.             'controller_name' => 'CoreController''numberAlerts' => $numberAlerts'numberAlertEvaluE' => $numberAlertEvaluE'numberNonAlertEvaluE' => $numberNonAlertEvaluE,'allProvinces' => $allPays'allByProvinces' => $allByPays
  109.         ]);
  110.     }
  111.     
  112.     /**
  113.      * @Route("/cd", name="app_drc", methods={"GET","POST"})
  114.      */
  115.     public function accDRC(Request $request)
  116.     {
  117.         //$em = $this->em->getManager();
  118.         //#[Route('/cd', name: 'app_drc', methods: ['GET', 'POST'])]
  119.         
  120.         //$numberAlerts = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1'))));
  121.         $numberAlerts $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('cd')[0]["alertSignalE"]);
  122.         $numberAlertEvaluE $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('cd')[0]["alertEvaluE"]);
  123.         //$numberAlertEvaluE = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1', 'isDeleted' => '0'))));
  124.         $numberActor $this->_convertUnit(count($this->em->getRepository(Actor::class)->findAllOperationnel()));
  125.         $numberPersMoved $this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(1));  // 1 = population déplacé
  126.         $numberPersReturn $this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(2));  // 2 = population Retourné
  127.         $numberPersMovedAr $this->em->getRepository(Idps::class)->findDeplaced()[0];  // 1 = population déplacé
  128.         $numberPersReturnAr $this->em->getRepository(Idps::class)->findReturn()[0];  // 2 = population Retourné
  129.     
  130.         $numberPersMovedFx =  $numberPersMovedAr->getPerson();
  131.         $numberPersReturnFx =  $numberPersReturnAr->getPerson();
  132.         // dump($numberPersMovedFx);
  133.         // dump($numberPersReturnFx);
  134.         $allProvinces $this->em->getRepository(Pcode::class)->getAllProvinces([]);
  135.         
  136.         $allByProvinces $this->em->getRepository(Pcode::class)->getAllByProvinces([]);
  137.         
  138.         return $this->render('core/home.html.twig', [
  139.             'controller_name' => 'CoreController''adminID' => 'CD''numberAlerts' => $numberAlerts'numberAlertEvaluE' => $numberAlertEvaluE'numberPersMoved' => $numberPersMoved'numberPersReturn' => $numberPersReturn'numberActor' => $numberActor'allProvinces' => $allProvinces'allByProvinces' => $allByProvinces,
  140.             'numberPersReturnFx' => $numberPersReturnFx'numberPersMovedFx'=>$numberPersMovedFx'numberPersMovedAr' => $numberPersMovedAr'numberPersReturnAr' =>$numberPersReturnAr
  141.         ]);
  142.     }
  143.     
  144.     /**
  145.      * @Route("/cf", name="app_cf", methods={"GET","POST"})
  146.      */
  147.     public function accCAR(Request $request)
  148.     {
  149.         //$em = $this->em->getManager();
  150.         //#[Route('/cf', name: 'app_car', methods: ['GET', 'POST'])]
  151.         
  152.         //$numberAlerts = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1'))));
  153.         $numberAlerts $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('cf')[0]["alertSignalE"]);
  154.         $numberAlertEvaluE $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('cf')[0]["alertEvaluE"]);
  155.         //$numberAlertEvaluE = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1'))));
  156.         $numberActor $this->_convertUnit(count($this->em->getRepository(Actor::class)->findAllOperationnel()));
  157.         $numberPersMoved 0;//$this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(1));  // 1 = population déplacé
  158.         $numberPersReturn 0;//$this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(2));  // 2 = population Retourné
  159.         $numberPersMovedAr $this->em->getRepository(Idps::class)->findDeplaced()[0];  // 1 = population déplacé
  160.         $numberPersReturnAr $this->em->getRepository(Idps::class)->findReturn()[0];  // 2 = population Retourné
  161.     
  162.         $numberPersMovedFx =  0;//$numberPersMovedAr->getPerson();
  163.         $numberPersReturnFx 0;//$numberPersReturnAr->getPerson();
  164.         // dump($numberPersMovedFx);
  165.         // dump($numberPersReturnFx);
  166.         $allProvinces $this->em->getRepository(Pcode::class)->getAllProvinces([]);
  167.         
  168.         $allByProvinces $this->em->getRepository(Pcode::class)->getAllByProvinces([]);
  169.         
  170.         return $this->render('core/home.html.twig', [
  171.             'controller_name' => 'CoreController''adminID' => 'CF''numberAlerts' => $numberAlerts'numberAlertEvaluE' => $numberAlertEvaluE'numberPersMoved' => $numberPersMoved'numberPersReturn' => $numberPersReturn'numberActor' => $numberActor'allProvinces' => $allProvinces'allByProvinces' => $allByProvinces,
  172.             'numberPersReturnFx' => $numberPersReturnFx'numberPersMovedFx'=>$numberPersMovedFx'numberPersMovedAr' => $numberPersMovedAr'numberPersReturnAr' =>$numberPersReturnAr
  173.         ]);
  174.     }
  175.      /**
  176.      * @Route("/bf", name="app_bur", methods={"GET","POST"})
  177.      */
  178.     public function accBNF(Request $request)
  179.     {
  180.         //$em = $this->em->getManager();
  181.         
  182.         //$numberAlerts = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1'))));
  183.         $numberAlerts $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('bf')[0]["alertSignalE"]);
  184.         $numberAlertEvaluE $this->_convertUnit($this->em->getRepository(Pcode::class)->alertStatut('bf')[0]["alertEvaluE"]);
  185.         //$numberAlertEvaluE = $this->_convertUnit(count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1'))));
  186.         $numberActor $this->_convertUnit(count($this->em->getRepository(Actor::class)->findAllOperationnel()));
  187.         $numberPersMoved 0;//$this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(1));  // 1 = population déplacé
  188.         $numberPersReturn 0;//$this->_convertUnit($this->em->getRepository(MovementDetail::class)->findAllPersons(2));  // 2 = population Retourné
  189.         $numberPersMovedAr 0;//$this->em->getRepository(Idps::class)->findDeplaced()[0];  // 1 = population déplacé
  190.         $numberPersReturnAr 0;//$this->em->getRepository(Idps::class)->findReturn()[0];  // 2 = population Retourné
  191.     
  192.         $numberPersMovedFx =  $numberPersMovedAr->getPerson();
  193.         $numberPersReturnFx =  $numberPersReturnAr->getPerson();
  194.         // dump($numberPersMovedFx);
  195.         // dump($numberPersReturnFx);
  196.         $allProvinces $this->em->getRepository(Pcode::class)->getAllProvinces([]);
  197.         
  198.         $allByProvinces $this->em->getRepository(Pcode::class)->getAllByProvinces([]);
  199.         
  200.         return $this->render('core/home.html.twig', [
  201.             'controller_name' => 'CoreController''adminID' => 'BF''numberAlerts' => $numberAlerts'numberAlertEvaluE' => $numberAlertEvaluE'numberPersMoved' => $numberPersMoved'numberPersReturn' => $numberPersReturn'numberActor' => $numberActor'allProvinces' => $allProvinces'allByProvinces' => $allByProvinces,
  202.             'numberPersReturnFx' => $numberPersReturnFx'numberPersMovedFx'=>$numberPersMovedFx'numberPersMovedAr' => $numberPersMovedAr'numberPersReturnAr' =>$numberPersReturnAr
  203.         ]);
  204.     }
  205.     public function dashboardAction(Request $request){
  206.         
  207.        // $em = $this->em->getManager();
  208.         
  209.         if ($request->isXmlHttpRequest()) {
  210.             
  211.             $data $request->attributes->get('data');
  212.             $admin0 $request->attributes->get('admin_id');
  213.             if ($data == 'data') {
  214.                 
  215.                     $type="dps";
  216.                     $allByArea $this->em->getRepository(Pcode::class)->getAllByProvinces($admin0);
  217.                     $numberAlerts count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1''isDeleted' => '0')));
  218.                     $numberActors count($this->em->getRepository(Actor::class)->findAllOperationnel());
  219.                     $numberPersMoved $this->em->getRepository(MovementDetail::class)->findAllPersons(1);  // 1 = population déplacé
  220.                     $numberPersReturn $this->em->getRepository(MovementDetail::class)->findAllPersons(2);  // 2 = population Retourné
  221.                     $numberPersCible $this->em->getRepository(ProjectDetail::class)->allpersCibles();
  222.      
  223.                 $list = [];
  224.                 if ($allByArea) {
  225.                     foreach($allByArea as $data) {
  226.                        
  227.                         $list [] = [
  228.                             'area'  => 
  229.                                         '<div class="media align-items-center position-relative">' .
  230.                                         '<div class="media-body ml-0">' .
  231.                                         '<h6 class="mb-1 font-weight-semi-bold"><a class="text-dark stretched-link" href="#!">' .  $data['label'] . '</a></h6>' .
  232.                                         '</div>' .
  233.                                         '</div>'
  234.                             ,
  235.                             'alertes'  =>  $data['nbrAlert']. //$this->_convertUnit((is_numeric($data['nbrAlert'])) ? $data['nbrAlert'] : 0)
  236.                                             '<div class="d-flex align-items-center">' .
  237.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  238.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrAlert'], $numberAlerts). '%;" aria-valuenow="' $this->_pourcent($data['nbrAlert'], $numberAlerts). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  239.                                             '</div>' .
  240.                                             '<div class="font-weight-semi-bold ml-2">'$this->_pourcent($data['nbrAlert'], $numberAlerts) . '%</div>' .
  241.                                             '</div>'
  242.                                             ,
  243.                             'pDeplacee'  =>  $this->_convertUnit((is_numeric($data['nbrPersMoved'])) ? $data['nbrPersMoved'] : 0) .
  244.                                             '<div class="d-flex align-items-center">' .
  245.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  246.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrPersMoved'], $numberPersMoved). '%;" aria-valuenow="' $this->_pourcent($data['nbrPersMoved'], $numberPersMoved). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  247.                                             '</div>' .
  248.                                             '<div class="font-weight-semi-bold ml-2">'$this->_pourcent($data['nbrPersMoved'], $numberPersMoved) . '%</div>' .
  249.                                             '</div>'
  250.                                             ,
  251.                             'pRetournee'  =>  $this->_convertUnit((is_numeric($data['nbrPersReturn'])) ? $data['nbrPersReturn'] : 0).
  252.                                             '<div class="d-flex align-items-center">' .
  253.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  254.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrPersReturn'], $numberPersReturn). '%;" aria-valuenow="' $this->_pourcent($data['nbrPersReturn'], $numberPersReturn). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  255.                                             '</div>' .
  256.                                             '<div class="font-weight-semi-bold ml-2">'$this->_pourcent($data['nbrPersReturn'], $numberPersReturn) . '%</div>' .
  257.                                             '</div>'
  258.                                             ,
  259.                             'pCible'  =>  $this->_convertUnit((is_numeric($data['nbrPersCibles'])) ? $data['nbrPersCibles'] : 0).
  260.                                             '<div class="d-flex align-items-center">' .
  261.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  262.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrPersCibles'], $numberPersCible). '%;" aria-valuenow="' $this->_pourcent($data['nbrPersCibles'], $numberPersCible). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  263.                                             '</div>' .
  264.                                             '<div class="font-weight-semi-bold ml-2">'$this->_pourcent($data['nbrPersCibles'], $numberPersCible) . '%</div>' .
  265.                                             '</div>'
  266.                                             ,
  267.                             'acteur'  =>  $this->_convertUnit((is_numeric($data['nbrActor']) ? $data['nbrActor'] : )).
  268.                                             '<div class="d-flex align-items-center">' .
  269.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  270.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrActor'], $numberActors). '%;" aria-valuenow="' $this->_pourcent($data['nbrActor'], $numberActors). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  271.                                             '</div>' .
  272.                                             '<div class="font-weight-semi-bold ml-2">'.$this->_pourcent($data['nbrActor'], $numberActors) . '%</div>' .
  273.                                             '</div>'
  274.                                             ,
  275.                             'id'            =>  $data['id'],
  276.                             'nbrAlert'      =>  $data['nbrAlert'],
  277.                             'aLabel'        =>  $data['label'],
  278.                             'nbrPersMoved'  =>  $data['nbrPersMoved'],
  279.                             'nbrPersReturn' =>  $data['nbrPersReturn'],
  280.                             'nbrPersCibles' =>  $data['nbrPersCibles'],
  281.                             'nbrActor'      =>  $data['nbrActor'],
  282.                             'area_type'     =>  $type,
  283.                         ];
  284.                     }
  285.                 }
  286.                 $rep=new JsonResponse();
  287.                 return $rep->setData($list);
  288.             }
  289.             else if ($data == 'data2') {
  290.                 
  291.                 $type="dps";
  292.                 $allByArea $this->em->getRepository(Pcode::class)->getAllByPays();
  293.                 $numberAlerts count($this->em->getRepository(Alert::class)->findBy(array('isValid' => '1''isDeleted' => '0')));
  294.                 
  295.                 $list = [];
  296.                 if ($allByArea) {
  297.                     foreach($allByArea as $data) {
  298.                     
  299.                         $list [] = [
  300.                             'area'  => 
  301.                                         '<div class="media align-items-center position-relative">' .
  302.                                         '<div class="media-body ml-0">' .
  303.                                         '<h6 class="mb-1 font-weight-semi-bold"><a class="text-dark stretched-link" href="#!">' .  $data['label'] . '</a></h6>' .
  304.                                         '</div>' .
  305.                                         '</div>'
  306.                             ,
  307.                             'alertes'  =>  $data['nbrAlert']. //$this->_convertUnit((is_numeric($data['nbrAlert'])) ? $data['nbrAlert'] : 0)
  308.                                             '<div class="d-flex align-items-center">' .
  309.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  310.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrAlert'], $numberAlerts). '%;" aria-valuenow="' $this->_pourcent($data['nbrAlert'], $numberAlerts). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  311.                                             '</div>' .
  312.                                             '<div class="font-weight-semi-bold ml-2">'$this->_pourcent($data['nbrAlert'], $numberAlerts) . '%</div>' .
  313.                                             '</div>'
  314.                                             ,
  315.                             'alertEvaluE'  =>  $data['nbrAlertEvaluE']. //$this->_convertUnit((is_numeric($data['nbrAlert'])) ? $data['nbrAlert'] : 0)
  316.                                             '<div class="d-flex align-items-center">' .
  317.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  318.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrAlertEvaluE'], $data['totalAlertEvaluE']). '%;" aria-valuenow="' $this->_pourcent($data['nbrAlertEvaluE'], $data['totalAlertEvaluE']). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  319.                                             '</div>' .
  320.                                             '<div class="font-weight-semi-bold ml-2">'$this->_pourcent($data['nbrAlertEvaluE'], $data['totalAlertEvaluE']) . '%</div>' .
  321.                                             '</div>'
  322.                                             ,
  323.                             'alertNonEvaluE'  =>  $data['nbrAlertNonEvaluE']. //$this->_convertUnit((is_numeric($data['nbrAlert'])) ? $data['nbrAlert'] : 0)
  324.                                             '<div class="d-flex align-items-center">' .
  325.                                             '<div class="progress w-100 mr-2 rounded-soft bg-200" style="height: 5px;">' .
  326.                                             '<div class="progress-bar rounded-capsule" role="progressbar" style="width: '  .$this->_pourcent($data['nbrAlertNonEvaluE'], $data['totalAlertNonEvaluE']). '%;" aria-valuenow="' $this->_pourcent($data['nbrAlertNonEvaluE'], $data['totalAlertNonEvaluE']). '" aria-valuemin="0" aria-valuemax="100"></div>' .
  327.                                             '</div>' .
  328.                                             '<div class="font-weight-semi-bold ml-2">'$this->_pourcent($data['nbrAlertNonEvaluE'], $data['totalAlertNonEvaluE']) . '%</div>' .
  329.                                             '</div>'
  330.                                             ,
  331.                             
  332.                             'id'            =>  $data['id'],
  333.                             'nbrAlert'      =>  $data['nbrAlert'],
  334.                             'aLabel'        =>  $data['label'],
  335.                             'area_type'     =>  $type,
  336.                         ];
  337.                     }
  338.                 }
  339.                 $rep=new JsonResponse();
  340.                 return $rep->setData($list);
  341.             }
  342.             else if ($data == 'SeverityZSColor') {
  343.                 
  344.                 $severityZS $this->em->getRepository(Pcode::class)->pcodeSeverityColor($admin0);
  345.                 $alert7Day $this->em->getRepository(Pcode::class)->alert7LastDay($admin0);
  346.                 
  347.                 $rep=new JsonResponse();
  348.                 return $rep->setData(['zsSeverity' => $severityZS'alert7Day' => $alert7Day]);
  349.             }
  350.             else if ($data == 'SeverityZS') {
  351.                 
  352.                 $severityZS $this->em->getRepository(Pcode::class)->pcodeSeverity($admin0);
  353.                 
  354.                 $rep=new JsonResponse();
  355.                 return $rep->setData(['zsSeverity' => $severityZS]);
  356.             }
  357.             else if ($data == 'StatutAlert') {
  358.                 
  359.                 $alertStatut $this->em->getRepository(Pcode::class)->alertStatut($admin0);
  360.                 $alertByArea $this->em->getRepository(Pcode::class)->alertStatutByTerritoire($admin0);
  361.                 $mvt24Month $this->em->getRepository(Pcode::class)->mvt24LastMonth($admin0);
  362.                 
  363.                 $rep=new JsonResponse();
  364.                 return $rep->setData(['alertStatut' => $alertStatut'alertByArea' => $alertByArea'mvt24Month' => $mvt24Month]);
  365.             }
  366.             else if ($data == 'PersonneCibles') {
  367.                 
  368.                
  369.                 $pers_ByCluster $this->em->getRepository(Cluster::class)->byCluster_persCible();
  370.                 $projetActor_ByCluster $this->em->getRepository(Cluster::class)->byCluster_projectActor("");
  371.                 
  372.                 $rep=new JsonResponse();
  373.                 return $rep->setData(array(
  374.                                         'allByCluster' => $pers_ByCluster,
  375.                                         'projetActor' => $projetActor_ByCluster,
  376.                                          )
  377.                                     );
  378.             }
  379.             else if ($data == 'Acteurs') {
  380.                
  381.                 $actorByCat $this->em->getRepository(Actor::class)->actor_byCategorie('CD');
  382.                 $acteur_ByCluster $this->em->getRepository(Cluster::class)->byCluster_actor();
  383.                 
  384.                 
  385.                 /*$temp="";
  386.                 foreach($lists as $list) {  
  387.                     $temp .= '<a href="#">'.$list->getAcronymFr().'</a> | ';  
  388.                 }*/
  389.                 $rep=new JsonResponse();
  390.                 return $rep->setData(array(
  391.                                         'allByCluster' => $acteur_ByCluster,
  392.                                         'actorByCat' => $actorByCat,
  393.                                         //'list' => $temp,
  394.                                          )
  395.                                     );
  396.             }
  397.             
  398.             else return null
  399.             
  400.         } else { 
  401.             return null
  402.         }
  403.     }
  404.     //** Convertir Nombre avec Unité k, M, b
  405.     private function _convertUnit($nombre) {
  406.         if($nombre==0) return 0;
  407.         else if($nombre<0) return 0;
  408.         $nombre $nombre*;
  409.         $def = [
  410.             [1''],
  411.             [1000'k'],
  412.             [1000 1000'M'],
  413.             [1000 1000 1000'b'],
  414.             [1000 1000 1000 1000'T']
  415.         ];
  416.         for ($i 0$i 5$i++) {
  417.             if ($nombre $def[$i][0]) return round(($nombre $def[$i 1][0]),2) . '' $def[$i 1][1];
  418.         }
  419.     }
  420.     //** Convertir Nombre avec Unité k, M, b
  421.     private function _pourcent($nbre$total) {
  422.         if ($total==0) return 0;
  423.         else 
  424.         return round(( (is_numeric($nbre) ? $nbre 0) == 0) ? $nbre $total 100);
  425.     }
  426.     public function getRandomCode($size)
  427.     {
  428.         $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@-';
  429.         $charactersLength strlen($characters);
  430.         $randomString '';
  431.         for ($i 0$i $size$i++) {
  432.             $randomString .= $characters[rand(0$charactersLength 1)];
  433.         }
  434.         return $randomString;
  435.     }
  436.     public function getTimeExpiration()
  437.     {
  438.         $now = new \DateTime();
  439.         return $now->add(new \DateInterval('PT5M'));
  440.     }
  441.     public function getProfilProgression()
  442.     {
  443.         return new JsonResponse(50);
  444.     }
  445.     public function jsonTest(Request $requestUserPasswordEncoderInterface $passwordEncoder)
  446.     {
  447.         $encoders = [new XmlEncoder(), new JsonEncoder()];
  448.         $normalizers = [new ObjectNormalizer()];
  449.         $serializer = new Serializer($normalizers$encoders);
  450.         $jsonContent $serializer->serialize($this->getUser(), 'json');
  451.         return new JsonResponse(json_decode($jsonContenttrue));
  452.     }
  453.     public function receiveMercureEventView(Request $requestMercureCookieGenerator $cookieGenerator)
  454.     {
  455.         //dump($this->getParameter('mercure.default_hub'));
  456.         //dump($this->getParameter('app.server_host'));
  457.         $response $this->render('core/mercure_test.html.twig');
  458.         //dump($cookieGenerator->generate($this->getUser()));
  459.         //$response->headers->set('set-cookie', $cookieGenerator->generate($this->getUser()));
  460.         //dump($cookieGenerator->generate($this->getUser()));
  461.         $token = (new Builder())
  462.             ->set("mercure""ppoo")
  463.             ->sign(new Sha256(), 'LOUP BEAU')
  464.             ->getToken();
  465.         // dump($this->jwt());
  466.         return $response;
  467.     }
  468.     //public function ping(PublisherInterface $publisher)
  469.     public function ping(MessageBusInterface $busUser $user)
  470.     {
  471.         //$target = [$this->getParameter('app.server_host') . 'user/{' . $user->getId() . '}'];
  472. //        $update = new Update(
  473. //            $this->getParameter('app.server_host') . 'ft/notification/' . $user->getId(),
  474. //            json_encode(['status' => 'LOUP: ' . $user->getId()])
  475. //            //$target
  476. //        );
  477.         $notification = [
  478.             'code' => Response::HTTP_GATEWAY_TIMEOUT,
  479.             'message' => 'LA TRANSACTION A ÉTÉ ANNULÉE',
  480.             'contents' => [
  481.                 'user' => $user->getId(),
  482.                 'financialTransaction' => 1,
  483.             ],
  484.         ];
  485.         // Envoyer l'événement au serveur Mercure
  486.         $update = new Update(
  487.             $this->getParameter('app.server_host') . 'ft/notification/' $user->getId(),
  488.             json_encode($notification)
  489.         //$target
  490.         );
  491.         // $publisher($update); SYNCH
  492.         $bus->dispatch($update); // ASYNCH
  493.         //return new Response('published!');
  494.         return $this->redirectToRoute('makuta_mercure_api_receive_event');
  495.     }
  496.     public function c2bTest(Request $request)
  497.     {
  498.         // $loginXml = $this->render('vodacom/login.xml.twig', [
  499.         //     'username' => 'thirdpartyc2bw',
  500.         //     'password' => 'thirdpartyc2bw',
  501.         // ]);
  502.         // //return $loginXml;
  503.         // // dump($loginXml->getContent());
  504.         // // return $this->render('core/index.html.twig', [
  505.         // //     'controller_name' => 'CoreController',
  506.         // // ]);
  507.         // $vodacom = new VodacomController();
  508.         // $result = $vodacom->getTokenArray($this->getParameter("app.mpesa_server"), $loginXml->getContent());
  509.         // // $encoders = [new XmlEncoder(), new JsonEncoder()];
  510.         // // $normalizers = [new ObjectNormalizer()];
  511.         // // $serializer = new Serializer($normalizers, $encoders);
  512.         // // $jsonContent = $serializer->serialize($result, 'json');
  513.         // //return new JsonResponse(json_decode($jsonContent, true));
  514.         // //return new JsonResponse($result);
  515.         // $token = $result['data']['contents']['SessionID'];
  516.         // //return new JsonResponse($result);
  517.         // $vodacomCToB = new VodacomCToB();
  518.         // $vodacomCToB->setToken($token);
  519.         // $vodacomCToB->setCustomerMSISDN('243810666161');
  520.         // $vodacomCToB->setCurrency('USD');
  521.         // $vodacomCToB->setThirdPartyReference(date_format($vodacomCToB->getTransactionDateTime(), 'YmdHis'));
  522.         // $vodacomCToB->setAmount('2');
  523.         // $vodacomCToB->setSurname('via Makuta');
  524.         // $vodacomCToB->setInitials('Rickain');
  525.         // $vodacomCToBXml = $this->render('vodacom/c_to_b.xml.twig', [
  526.         //     'vodacomCToB' => $vodacomCToB,
  527.         // ]);
  528.         // $cToBResponse = $vodacom->cToB($this->getParameter('app.mpesa_server'), $vodacomCToBXml->getContent());
  529.         return new JsonResponse("RAS");
  530.     }
  531.     public function declencheEvent()
  532.     {
  533.         return parent::render('core/test.html.twig');
  534.     }
  535.     public function testJwt()
  536.     {
  537.         $response = [
  538.             'code' => Response::HTTP_OK,
  539.             'message' => 'OK',
  540.             'contents' => 'Ceci est un exmple du contenu',
  541.         ];
  542.         // $token = (new Builder())
  543.         //     ->set("makuta", ["data" => json_encode($response)])
  544.         //     ->sign(new Sha256(), "OOOOOO")
  545.         //     ->getToken();
  546.         ////$bingo = $token->verify(new Sha256(), 'testing 1');
  547.         //return new JsonResponse((string) $token);
  548.         // $signer = new Sha256();
  549.         // $key = new Key('0000');
  550.         // //$key = new Key('private_file', 'public');
  551.         // $token = (new Builder())
  552.         //     ->withClaim('makuta', ['data' => $response])
  553.         //     ->getToken($signer, $key);
  554.         // $token = (new Parser())->parse((string) $token); // Parses from a string
  555.         // $token->getHeaders(); // Retrieves the token header
  556.         // $token->getClaims(); // Retrieves the token claims
  557.         // return new JsonResponse((string) $token);
  558.         $signer = new Sha256();
  559.         $publicKey = new Key('0000');
  560.         //$privateKey = new Key('0000');
  561.         $now = new \DateTime();
  562.         $token = (new Builder())
  563.             ->issuedBy($this->getParameter('app.server_host'))
  564.             ->issuedAt($now->getTimestamp())
  565.             ->expiresAt($this->appUtils->getTimeExpiration(2)->getTimestamp())
  566.             ->withClaim('makuta', ['data' => $response])
  567.             ->getToken($signer$publicKey);
  568.         // ->getToken($signer, $publicKey, $privateKey);
  569.         //$token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2RlIjoiZmFicmljZSIsImV4cCI6MTk5MX0=.BDcOI1t8H3HPe5Yd5Hohabe2hsnXeZu2hP_soLIswPs=";
  570.         $tt = (new Parser())->parse((string) $token); // Parses from a string
  571.         $tt->getHeaders(); // Retrieves the token header
  572.         $tt->getClaims(); // Retrieves the token claims
  573.         //$tt->getClaims()['exp']; //Heure d'expiration
  574.         $bingo $tt->verify(new Sha256(), '0000');
  575.         //$timestampNow = $now->getTimestamp();
  576.         //$ooo = $timestampNow < $exp ? 'now sup' : 'now inf';
  577.         $validationData = new ValidationData();
  578.         $validationData->setIssuer($this->getParameter('app.server_host'));
  579.         //$validationData->setCurrentTime(time() - 1);
  580.         //$validationData->set
  581.         $validation $tt->validate($validationData);
  582.         //return new JsonResponse($tt->getClaim('makuta')->data);
  583.         //return new JsonResponse((string) $token);
  584.         return new JsonResponse($tt->getClaims());
  585.     }
  586.     public function test()
  587.     {
  588.         return $this->render('core/test.html.twig');
  589.     }
  590. }