src/Controller/USSDFunctionController.php line 192

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\SysService;
  4. use App\Entity\SysSessionTmp;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Doctrine\Persistence\ObjectManager;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use App\Entity\UssdCurrentSession;
  11. use App\Entity\MenuData;
  12. use App\Entity\SysOperatorGSM;
  13. use App\Entity\SysUssdMenu;
  14. use App\Controller\BusTicketController;
  15. use App\Entity\SysMtnEntryParam;
  16. use App\Entity\SysSessionBackup;
  17. use App\Entity\SysUssdHistory;
  18. use App\Message\ServicePayment;
  19. use DateTime;
  20. use Psr\Log\LoggerInterface;
  21. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  22. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  23. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  24. use Symfony\Component\Serializer\Serializer;
  25. ////
  26. class USSDFunctionController extends AbstractController
  27. {
  28.     private $connDB;
  29.     private $shortCode "";
  30.     private $msisdn "";
  31.     private $userInput "";
  32.     private $lang "";
  33.     private $sessionId "";
  34.     private $reqNo "";
  35.     private $screenId "";
  36.     private $serverSession "";
  37.     private $operatorCode "";
  38.     private $newRequest false;
  39.     private $currentSession
  40.     private $sysUssdHistory;
  41.     private $logger;
  42.     public function __construct(LoggerInterface $logger)
  43.     {
  44.         $this->logger $logger;
  45.     }
  46.     
  47.     /**
  48.      * @Route("/u/s/s/d/function", name="u_s_s_d_function")
  49.      */
  50.     public function index(): Response
  51.     {
  52.         return $this->render('ussd_function/index.html.twig', [
  53.             'controller_name' => 'USSDFunctionController',
  54.         ]);
  55.     }
  56.     /**
  57.      * @Route("/serviceussd233", name="ussdEntry")
  58.      */
  59.     public function index2(): Response
  60.     {
  61.         $xmlResponse = new Response();
  62.         $xmlResponse->setContent("TEST MESSAGE OK");
  63.         $xmlResponse->headers->set('Content-Type''text/xml');
  64.         $this->logger->info("Response =>" $xmlResponse);
  65.         return $xmlResponse;
  66.     }
  67.     /**
  68.      * @Route("/serviceussd", name="ussdEntry_Moov")
  69.      */
  70.     public function ussdEntry_Moov(Request $request): Response
  71.     {
  72.         //
  73.         $operatorCode 'MOOVBJ';
  74.         $currentSession = new UssdCurrentSession(); 
  75.         $currentSession->setOperatorCode($operatorCode);
  76.         $getRequest $_SERVER["REQUEST_URI"];
  77.         
  78.         //Log entry request
  79.         $this->logger->info($operatorCode ",Request Entry =>" $this->getUssdGatewayIpAddr() . "=>" $getRequest);
  80.         $this->sysUssdHistory = new SysUssdHistory();
  81.         $this->sysUssdHistory->setEntryTime(new \DateTime('now'))
  82.                             ->setOperatorCode($operatorCode)
  83.                             ->setSourceIpAddress($this->getUssdGatewayIpAddr());
  84.                             
  85.         //Check and get value from $_GET or $_POST in the request
  86.         if(isset($_GET["msisdn"])){
  87.             $ARG $_GET;
  88.         }elseif(isset($_POST["msisdn"])) {
  89.             $ARG $_GET;
  90.         }
  91.         
  92.         /***** initalise session variable *******/
  93.         $currentSession->setMsisdn($ARG["msisdn"]); 
  94.         if(isset($ARG["sc"])){
  95.             $currentSession->setShortCode($ARG["sc"]);
  96.         }
  97.         if(isset($ARG["user_input"])){
  98.             $currentSession->setUserInput($ARG["user_input"]);
  99.             if(strlen($ARG["user_input"]) <=){   //TODO:Check that user imput is not null during continue session
  100.                 $currentSession->setNewRequest(true);
  101.             }else{
  102.                 $currentSession->setNewRequest(false);
  103.             }
  104.         }
  105.         if(isset($ARG["lang"])){
  106.             $currentSession->setLanguage($ARG["lang"]);
  107.         }
  108.         if(isset($ARG["session_id"])){
  109.             $currentSession->setSessionId($ARG["session_id"]);
  110.         }
  111.         if(isset($ARG["screen_id"])){
  112.             if(strlen($ARG["screen_id"])>0)
  113.                 $currentSession->setScreenId($ARG["screen_id"]);
  114.             else
  115.                 $currentSession->setScreenId(0);
  116.         }
  117.         if(isset($ARG["req_no"])){
  118.             if(strlen($ARG["req_no"])>0)
  119.                 $currentSession->setRequestNumber($ARG["req_no"]);
  120.             else
  121.                 $currentSession->setRequestNumber(0);
  122.         }
  123.         $this->currentSession $currentSession//Difine the new incoming request to the global varible
  124.         
  125.         /*********Fin initialisation ******/
  126.         
  127.    
  128.         //Start processing of the request and get the menu to be sent
  129.         $menuData $this->processIncomingRequest();
  130.         //LogSession in dataBase
  131.         /*********** Creation du menu, reponse au serveur de moov benin */
  132.         $ussdResponse '<?xml version="1.0" encoding="UTF-8"?>';
  133.         $ussdResponse $ussdResponse '<response>';
  134.         if($menuData->getIsMemuOption()){
  135.             $ussdResponse $ussdResponse '<screen_type>menu</screen_type>';
  136.             $ussdResponse $ussdResponse '<text>' $menuData->getMenuTitle() . '</text>';
  137.             $ussdResponse $ussdResponse '<options>';
  138.             foreach($menuData->getOptions() as $itemVal)
  139.             {
  140.                 $ussdResponse $ussdResponse '<option choice="'.  $itemVal[0] . '.">' $itemVal[1] . '</option>';
  141.             }
  142.             $ussdResponse $ussdResponse '</options>';
  143.         }else{
  144.             $ussdResponse $ussdResponse '<screen_type>form</screen_type>';
  145.             $ussdResponse $ussdResponse '<text>' $menuData->getMenuTitle() . '</text>';
  146.         }
  147.                 
  148.         if($menuData->getIsShowBack()){
  149.             $ussdResponse $ussdResponse '<back_link>1</back_link>';
  150.         }else{
  151.             $ussdResponse $ussdResponse '<back_link>0</back_link>';
  152.         }
  153.         $ussdResponse $ussdResponse '<home_link>0</home_link>';
  154.         if($menuData->getIsSessionContinue()){
  155.             $ussdResponse $ussdResponse '<session_op>continue</session_op>';
  156.         }else{
  157.             $ussdResponse $ussdResponse '<session_op>end</session_op>';
  158.         }
  159.         $ussdResponse $ussdResponse '<screen_id>' . (string) $menuData->getScreenId() . '</screen_id>';
  160.         $ussdResponse $ussdResponse '</response>';
  161.         /********************************** */
  162.         //$response["error"] = FALSE;
  163.         //$response["error_code"] = 0; //No Error
  164.         //$response["error_msg"] = "No Message";
  165.         //$response["Sesssion"] = $currentSession;
  166.         $xmlResponse = new Response();
  167.         $xmlResponse->setContent($ussdResponse);
  168.         $xmlResponse->headers->set('Content-Type''text/xml');
  169.         $this->logger->info("Response =>" $xmlResponse);
  170.         return $xmlResponse;
  171.     }
  172.     /**
  173.      * @Route("/ussd_mtnbenin", name="ussdEntry_MTN")
  174.      */
  175.     public function ussdEntry_MTN(Request $request): Response
  176.     {
  177.         $encoders = [new XmlEncoder(), new JsonEncoder()];
  178.         $normalizers = [new ObjectNormalizer()];
  179.         $serializer = new Serializer($normalizers$encoders);
  180.         
  181.         $contentBody $request->getContent();
  182.         $entryParam $serializer->deserialize($contentBodySysMtnEntryParam::class, 'xml');
  183.         //var_dump($contentBody);
  184.         //var_dump("<===============>");
  185.         //var_dump($entryParam);
  186.         $operatorCode 'MTNBJ';
  187.         $currentSession = new UssdCurrentSession(); 
  188.         $currentSession->setOperatorCode($operatorCode);
  189.         $getRequest $_SERVER["REQUEST_URI"];
  190.         
  191.         //Log entry request
  192.         $this->logger->info($operatorCode ",Request Entry =>" $this->getUssdGatewayIpAddr() . "=>" $getRequest "=>" $contentBody);
  193.         $this->sysUssdHistory = new SysUssdHistory();
  194.         $this->sysUssdHistory->setEntryTime(new \DateTime('now'))
  195.                             ->setOperatorCode($operatorCode)
  196.                             ->setSourceIpAddress($this->getUssdGatewayIpAddr());
  197.                             
  198.         /***** initalise session variable *******/
  199.         $currentSession->setMsisdn($entryParam->getMsisdn()); 
  200.         $currentSession->setShortCode("450");
  201.         if ($entryParam->getStatusCode() == 0){
  202.             $currentSession->setUserInput($entryParam->getSubscriberInput());
  203.             if($entryParam->getNewRequest() == "1" ){
  204.                 $currentSession->setNewRequest(true);
  205.             }else{
  206.                 $currentSession->setNewRequest(false);
  207.             }
  208.             $currentSession->setLanguage($entryParam->getLanguage());
  209.             $currentSession->setSessionId($entryParam->getSessionId());
  210.             $currentSession->setScreenId(0);
  211.             $currentSession->setRequestNumber(0);
  212.             $this->currentSession $currentSession//Difine the new incoming request to the global varible
  213.             
  214.             /*********Fin initialisation ******/
  215.             
  216.     
  217.         
  218.         
  219.             //Start processing of the request and get the menu to be sent
  220.             $menuData $this->processIncomingRequest();
  221.             /*********** Creation du menu, reponse au serveur de moov benin */
  222.             $ussdResponse '<?xml version="1.0" encoding="UTF-8"?>';
  223.             $ussdResponse $ussdResponse '<response>';
  224.             $ussdResponse $ussdResponse '<msisdn>' $currentSession->getMsisdn() . '</msisdn>';
  225.             $ussdResponse $ussdResponse '<applicationResponse>';
  226.             $ussdResponse $ussdResponse $menuData->getMenuTitle();
  227.             if($menuData->getIsMemuOption()){
  228.                 foreach($menuData->getOptions() as $itemVal)
  229.                     {
  230.                         $ussdResponse $ussdResponse "\n" $itemVal[0] . '.' $itemVal[1];
  231.                     }
  232.             }
  233.             $ussdResponse $ussdResponse '</applicationResponse>';
  234.             $ussdResponse $ussdResponse '<freeflow>';
  235.             if($menuData->getIsSessionContinue()){
  236.                 $ussdResponse $ussdResponse '<freeflowState>FC</freeflowState>';
  237.             }else{
  238.                 $ussdResponse $ussdResponse '<freeflowState>FB</freeflowState>';
  239.             }
  240.             $ussdResponse $ussdResponse '<freeflowCharging>N</freeflowCharging><freeflowChargingAmount>0</freeflowChargingAmount>';
  241.             $ussdResponse $ussdResponse '</freeflow>';
  242.             $ussdResponse $ussdResponse '</response>';
  243.         }else{
  244.             //Send Clean Acknowledge Response
  245.             $ussdResponse '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
  246.             $ussdResponse $ussdResponse '<response>';
  247.             $ussdResponse $ussdResponse '<msisdn>' $currentSession->getMsisdn() . '</msisdn>';
  248.             $ussdResponse $ussdResponse '<statusCode>'.$entryParam->getStatusCode().'</statusCode>';
  249.             $ussdResponse $ussdResponse '</response>';
  250.         }
  251.         $xmlResponse = new Response();
  252.         $xmlResponse->setContent($ussdResponse);
  253.         $xmlResponse->headers->set('Content-Type''text/xml');
  254.         $this->logger->info("Response =>" $xmlResponse);
  255.         return $xmlResponse;
  256.         //return $this->render('ussd_function/index.html.twig', [
  257.         //    'controller_name' => 'USSDFunctionController',
  258.         //]);
  259.     }
  260.     function getUssdGatewayIpAddr(){
  261.         if(!empty($_SERVER['HTTP_CLIENT_IP'])){
  262.             //ip from share internet
  263.             $ip $_SERVER['HTTP_CLIENT_IP'];
  264.         }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  265.             //ip pass from proxy
  266.             $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
  267.         }else{
  268.             $ip $_SERVER['REMOTE_ADDR'];
  269.         }
  270.         return $ip;
  271.     }
  272.     function processIncomingRequest(){
  273.         //Check short request like *450*1# or *450*3#
  274.         $inputTable explode("*"$this->currentSession->getUserInput());
  275.         if(count($inputTable) > && strcmp($inputTable[0], "450") == 0){
  276.             
  277.             for ($i 0$i 2$i++) {
  278.                 if(strcmp($inputTable[$i], "450") == 0){
  279.                     $this->currentSession->setNewRequest(true);
  280.                     $this->currentSession->setUserInput($inputTable[$i]);
  281.                     $this->processIncomingRequest();
  282.                 }else{
  283.                     $this->currentSession->setNewRequest(false);
  284.                     $this->currentSession->setUserInput($inputTable[$i]);
  285.                     return $this->processIncomingRequest();
  286.                 }
  287.                 //var_dump($inputTable);
  288.                 
  289.             }
  290.         }
  291.         //Check temp instance of the session
  292.         $entityManager $this->getDoctrine()->getManager();
  293.         $repoSession =$this->getDoctrine()->getRepository(SysSessionTmp::class);
  294.         $tempSession $repoSession->findOneBy([
  295.             'msisdn' => $this->currentSession->getMsisdn(),
  296.             'sessionId' => $this->currentSession->getSessionId()
  297.         ]);
  298.          //Check if user request previouse menu is the main menu
  299.          if(strcmp($this->currentSession->getUserInput(),"88") == ){ //request previous menu
  300.             if($tempSession != null){
  301.                 $repoUssdMenu $this->getDoctrine()->getRepository(SysUssdMenu::class);
  302.                 $menuRequest $repoUssdMenu->findOneBy(['menuCode'=>$tempSession->getMenuCode()]);
  303.                 if(strcmp($menuRequest->getPreviousMenuCode(), 'MAIN') ==0){
  304.                     $this->currentSession->setNewRequest(true);
  305.                 }
  306.             }
  307.         }
  308.         //Check if it is new request
  309.         if($tempSession == null)
  310.             $this->currentSession->setNewRequest(true);
  311.         
  312.         //Process the request
  313.         $menuData = new MenuData();  //Data to return for creation the next menu
  314.         if($this->currentSession->getNewRequest()){ //if yes it is new session
  315.             //it is a new first request for this msisdn with this sessionId
  316.             //Fo new request we send the main menu
  317.             $menuData $this->getMainMenu();
  318.             if($tempSession == null){ // to not create new temp entry if it is a user previous request
  319.                 $sysTemp = new SysSessionTmp();
  320.                 $sysTemp->setCreateTime(new \DateTime('now'));
  321.             }else{
  322.                 $sysTemp $tempSession;
  323.             }
  324.             
  325.             $sysTemp->setSessionId($this->currentSession->getSessionId());
  326.             $sysTemp->setMsisdn($this->currentSession->getMsisdn());
  327.             $sysTemp->setUpdateTime(new \DateTime('now'));
  328.             $repoOperator =$this->getDoctrine()->getRepository(SysOperatorGSM::class);
  329.             $operator = new SysOperatorGSM();
  330.             $operator $repoOperator->findOneBy(['codeOperator'=>$this->currentSession->getOperatorCode()]);
  331.             $sysTemp->setOperator($operator);
  332.             $service = new SysService();
  333.             $repoService =$this->getDoctrine()->getRepository(SysService::class);
  334.             $service $repoService->findOneBy(['codeService'=>'MAIN']);
  335.             $sysTemp->setService($service);
  336.             $sysTemp->setMenuCode($menuData->getMenuCode());
  337.             $sysTemp->setPreviousMenuCode($menuData->getPreviousMenuCode());
  338.             $sysTemp->setNextMenuCode($menuData->getNextMenuCode());
  339.             $sysTemp->setIsInputRequest(false);
  340.             $sysTemp->setMenuOptionsString($menuData->getMenuOptionString());
  341.             $sysTemp->setMenuTitle($menuData->getMenuTitle());
  342.             $entityManager->persist($sysTemp);
  343.             $entityManager->flush();
  344.             //$this->currentSession->getMsisdn()
  345.         }else{
  346.             //session exit it is a continus request, check the service and connect to the correct service controller
  347.             $isCorrectChose false;
  348.             $optionsMenu = [];
  349.             if(!$tempSession->getIsInputRequest()){
  350.                 $options explode('+'$tempSession->getMenuOptionsString());
  351.                 foreach($options as $val){
  352.                     $item explode(',',$val);
  353.                     if($item[0] === $this->currentSession->getUserInput()){
  354.                         $this->currentSession->setInputItem($item);
  355.                         $isCorrectChose true;
  356.                         break;
  357.                     }
  358.                     if($item[0]!='-1')
  359.                         $optionsMenu[] = $item;
  360.                 }
  361.             }else{
  362.                 if(strlen($this->currentSession->getUserInput())>0){
  363.                     $this->currentSession->setInputItem([-2,$this->currentSession->getUserInput(),-2]);
  364.                     $isCorrectChose true;
  365.                 }
  366.             }
  367.             if($isCorrectChose){
  368.                 //$ussdMenu = new SysUssdMenu();
  369.                 if(strcmp($tempSession->getMenuCode(), 'MAIN') ==){
  370.                     //it is the first menu of the service
  371.                     $repoServices =$this->getDoctrine()->getRepository(SysService::class);
  372.                     $service $repoServices->find($this->currentSession->getInputItem()[2]);
  373.                     $repoUssdMenu =$this->getDoctrine()->getRepository(SysUssdMenu::class);
  374.                     $ussdMenu $repoUssdMenu->findOneBy(['service'=>$service'levelOrder'=>1]);
  375.                     $this->currentSession->setService($service);
  376.                     $this->currentSession->setNewSession(true);
  377.                     $menuData $this->processService($service->getCodeService(), 'MAIN'$ussdMenu->getMenuCode());
  378.                 }else{
  379.                     $this->currentSession->setService($tempSession->getService());
  380.                     $this->currentSession->setNewSession(false);
  381.                     $menuData $this->processService($tempSession->getService()->getCodeService(), $tempSession->getMenuCode(), $tempSession->getNextMenuCode());
  382.                 }
  383.                 
  384.                 if($menuData->getIsSessionContinue()){ //Check if session continue
  385.                     $tempSession->setUpdateTime(new \DateTime('now'));
  386.                     $tempSession->setService($menuData->getService());
  387.                     $tempSession->setMenuCode($menuData->getMenuCode());
  388.                     $tempSession->setIsInputRequest($menuData->getIsInputRequest());
  389.                     $tempSession->setMenuOptionsString($menuData->getMenuOptionString());
  390.                     $tempSession->setPreviousMenuCode($menuData->getPreviousMenuCode());
  391.                     $tempSession->setNextMenuCode($menuData->getNextMenuCode());
  392.                     $tempSession->setMenuTitle($menuData->getMenuTitle());
  393.                     $tempSession->setScreenId($menuData->getScreenId());
  394.                     $entityManager->persist($tempSession);
  395.                     $entityManager->flush();
  396.                 }else{
  397.                     //Delete SysSessionTemp
  398.                     $entityManager->remove($tempSession); 
  399.                 }
  400.             }else{
  401.                 //TODO: handle incorrect imput
  402.                 $menuData->setMenuTitle("Choix incorrect, Reessayez:\n" $tempSession->getMenuTitle());
  403.                 $menuData->setService($tempSession->getService());
  404.                 $menuData->setMenuCode($tempSession->getMenuCode());
  405.                 $menuData->setIsInputRequest($tempSession->getIsInputRequest());
  406.                 $menuData->setMenuOptionString($tempSession->getMenuOptionsString());
  407.                 $menuData->setPreviousMenuCode($tempSession->getPreviousMenuCode());
  408.                 $menuData->setNextMenuCode($tempSession->getNextMenuCode());
  409.                 if(!$tempSession->getIsInputRequest()){
  410.                     $menuData->setIsMemuOption(true);
  411.                     $menuData->setOptions($optionsMenu);
  412.                 }else{
  413.                     $menuData->setIsMemuOption(false);
  414.                 }
  415.                 //$menuData->setMenuOptionString("");
  416.                 $menuData->setIsShowBack(false);
  417.                 $menuData->setIsSessionContinue(true);
  418.                 //$menuData->setIsInputRequest(false);
  419.                 //$menuData->setMenuCode('MAIN');
  420.                 //$menuData->setPreviousMenuCode('MAIN');
  421.                 //$menuData->setNextMenuCode('MAIN');
  422.             }
  423.             
  424.         }
  425.         //******  Log Ussd Session history *******************/
  426.         $this->sysUssdHistory->setSessionId($this->currentSession->getSessionId())
  427.                             ->setMsisdn($this->currentSession->getMsisdn())
  428.                             ->setIncomingUserInput($this->currentSession->getUserInput())
  429.                             ->setSysResponseTitle($menuData->getMenuTitle())
  430.                             ->setSysResponseOption($menuData->getMenuOptionString())
  431.                             ->setMenuCode($menuData->getMenuCode())
  432.                             ->setMenuCode($menuData->getMenuCode());
  433.         
  434.         if($tempSession == null){
  435.             $this->sysUssdHistory->setServiceCode('0');
  436.         }else{
  437.             $this->sysUssdHistory->setServiceCode($tempSession->getService()->getCodeService());
  438.         }
  439.         if($this->currentSession->getNewRequest()){
  440.             $this->sysUssdHistory->setSessionFlag("INTIAL");
  441.         }else{
  442.             if($menuData->getIsSessionContinue()){
  443.                 $this->sysUssdHistory->setSessionFlag("INTERMEDIATE");
  444.             }else{
  445.                 $this->sysUssdHistory->setSessionFlag("FINAL");
  446.             }
  447.         }
  448.         $this->sysUssdHistory->setOutputTime(new \DateTime("now"));
  449.         $entityManager->persist($this->sysUssdHistory);
  450.         //*********************************************** */
  451.         
  452.         //Commit databsse                    
  453.         $entityManager->flush(); 
  454.         //Return data
  455.         return $menuData;
  456.     }
  457.     function processService($codeService$menuCode$nextMenuCode){
  458.         
  459.         switch ($codeService) {
  460.             case "TTBUS":
  461.                 $busFunction = new BusTicketController($this->getDoctrine());
  462.                 $dataM $busFunction->busUserInputProsess($menuCode$nextMenuCode$this->currentSession);
  463.             break;
  464.             case "TTCINE":
  465.                 $cineFunction = new CineTicketController($this->getDoctrine());
  466.                 $dataM $cineFunction->busUserInputProsess($menuCode$nextMenuCode$this->currentSession);
  467.             break;
  468.             case "RCHGAZ":
  469.                 $rechGazFunction = new RechGazController($this->getDoctrine()); //GazServiceController($this->getDoctrine()); // 
  470.                 $dataM $rechGazFunction->userInputProsess($menuCode$nextMenuCode$this->currentSession);
  471.                 
  472.             break;
  473.             case "ESANTE":
  474.                 $infoSanteFunction = new InfoSanteController($this->getDoctrine());
  475.                 $dataM $infoSanteFunction->userInputProsess($menuCode$nextMenuCode$this->currentSession);
  476.                 break;
  477.             case "ELOYER":
  478.             break;
  479.             case "QOSIC":
  480.                 $mobileBip = new MobileBipController($this->getDoctrine());
  481.                 $dataM $mobileBip->userInputProsess($menuCode$nextMenuCode$this->currentSession);
  482.                 break;
  483.             case "LABBAIK":
  484.                 $labbaik = new LabbaikController($this->getDoctrine());
  485.                 
  486.                 $dataM $labbaik->userInputProsess($menuCode$nextMenuCode$this->currentSession);
  487.                 break;
  488.             case "AUTRES":
  489.                 $autresFunction = new AutresController($this->getDoctrine());
  490.                 $dataM $autresFunction->userInputProsess($menuCode$nextMenuCode$this->currentSession);
  491.             break;
  492.         }
  493.         if($dataM->getIsToPayed()){
  494.             $this->dispatchMessage(new ServicePayment($dataM->getTransactionIdToPayed()));
  495.         }
  496.         return $dataM;
  497.     }
  498.     function getMainMenu(){
  499.     
  500.         //initialise data to sent 
  501.         $dataM = new MenuData();
  502.         $dataM->setMenuTitle("Bienvenu sur ReservLine");
  503.         $dataM->setIsMemuOption(true);
  504.         $dataM->setOptions([]);
  505.         $dataM->setMenuOptionString("");
  506.         $dataM->setIsShowBack(false);
  507.         $dataM->setIsSessionContinue(true);
  508.         $dataM->setIsInputRequest(false);
  509.         $dataM->setMenuCode('MAIN');
  510.         $dataM->setPreviousMenuCode('MAIN');
  511.         $dataM->setNextMenuCode('MAIN');
  512.         //$data = [
  513.             //'menuTitle' => ,
  514.             //'isMemuOption' => true,
  515.             //'options' => ,
  516.             //'isShowBack' => false,
  517.             //'isSessionContinue' => true,
  518.             //'menuOptionString' => "",
  519.             //'is_input_request' => 0,
  520.         //];
  521.         //create option list 
  522.         $repoServices =$this->getDoctrine()->getRepository(SysService::class);
  523.         $serviceList $repoServices->findBy(['enable'=>true], ['orderNumber' => 'ASC']);
  524.         if($serviceList == null){
  525.             //TODO: Error - no service available retreived from the data base
  526.             //print("Error - no service available retreived from the data base");
  527.         }else{
  528.             $options = [];
  529.             $menuOptionString="-1,libelle,-1";
  530.             $i=0;
  531.             foreach($serviceList as $serviceVal)
  532.             {
  533.                 //Check service is in production or in test
  534.                 if(!$serviceVal->getInProduction()){
  535.                     if(!$serviceVal->getVisibleToAll()){
  536.                         if($serviceVal->getTestNumberList() == null){
  537.                             continue;
  538.                         }else{
  539.                             if(!str_contains($serviceVal->getTestNumberList(),$this->currentSession->getMsisdn())){
  540.                                 continue;
  541.                             }
  542.                         }
  543.                     }
  544.                 }
  545.                 //Add service in the main menu to be display
  546.                 $options[$i] = array($serviceVal->getOrderNumber(), $serviceVal->getLibelle(),  $serviceVal->getId());
  547.                 $menuOptionString .= '+'$serviceVal->getOrderNumber()  . ',' $serviceVal->getLibelle() . ',' $serviceVal->getId();
  548.                 $i++;
  549.             }
  550.             $dataM->setOptions($options);
  551.             $dataM->setMenuOptionString($menuOptionString);
  552.             //$data["options"] = $options;
  553.             //$data['is_input_request'] = true;
  554.         }
  555.         return $dataM;
  556.     }
  557.    static function createReservationCode(SysService $serivceint $tempSessionId ) : string
  558.     {
  559.         $codeString '';
  560.         $codeString $codeString strVal(rand(1,9));  //premier chiffre aleatoire
  561.         //$codeString = $codeString . sprintf("%02d",$serivce->id); // Id du serivice sur 2 chiffre
  562.         //$codeString = $codeString . sprintf("%02d",date_format(new \Datetime("now"), 'm'));  // add current second sur 2 chiffre
  563.         $codeString $codeString sprintf("%02d",date_format(new \Datetime("now"), 's'));  // add current second sur 2 chiffre
  564.         $codeString $codeString substr(sprintf("%04d",$tempSessionId), -3); // liste 3 digit of tempSessionId
  565.         
  566.         switch ($serivce->getCodeService()) {
  567.             case "TTBUS":
  568.                 $codeString 'b' $codeString;
  569.             break;
  570.             case "TTCINE":
  571.                 $codeString 'c' $codeString;
  572.             break;
  573.             case "RCHGAZ":
  574.                 $codeString 'g' $codeString;
  575.             break;
  576.             case "ELOYER":
  577.                 $codeString 'l' $codeString;
  578.             break;
  579.             case "ESANTE":
  580.                 $codeString 's' $codeString;
  581.             break;
  582.         }
  583.         return $codeString;
  584.     }
  585.     static function createTransactionReference(SysService $serivceint $transactionId ) : string
  586.     {
  587.         $codeString '' strVal(rand(111,999));  //3 premier chiffre aleatoire
  588.         $codeString $codeString sprintf("%02d",$serivce->getId()); // Id du serivice sur 2 chiffre
  589.         $codeString $codeString sprintf("%02d",date_format(new \Datetime("now"), 'i')); //Minute actuel sur  2 chiffre
  590.         $codeString $codeString sprintf("%02d",date_format(new \Datetime("now"), 's'));  // add second sur 2 chiffre
  591.         $codeString $codeString substr(sprintf("%06d",$transactionId), -5); // liste 5 digit of tempSessionId
  592.         return $codeString;
  593.     }
  594. /*
  595.     // Create ussd menu
  596.     function createMenu($operatorCode, $menuText, $isMemuOption, $menuItems, $isShowBack, $isSessionContinue, $screenId) {
  597.         //if( strcmp(,'moovbenin') == 0 )
  598.         $response = "";
  599.         switch ($operatorCode) {
  600.             case "MOOVBJ":
  601.                 $response = $response . '<?xml version="1.0" encoding="UTF-8"?>';
  602.                 $response = $response . '<response>';
  603.                 
  604.                 if(!$isMemuOption){
  605.                     $response = $response . "\n". '<screen_type>form</screen_type>';
  606.                     $response = $response . "\n". '<text>' . $menuText . '</text>';
  607.                 }else if($isMemuOption){
  608.                     $response = $response . "\n". '<screen_type>menu</screen_type>';
  609.                     $response = $response . "\n". '<text>' . $menuText . '</text>';
  610.                     $response = $response . "\n". '<options>';
  611.                     foreach($menuItems as $itemVal)
  612.                     {
  613.                         $response = $response . '<option choice="'.  $itemVal[0] . '">' . $itemVal[1] . '</option>';
  614.                     }
  615.                     $response = $response . '</options>';
  616.                 }
  617.                 
  618.                 if($isShowBack){
  619.                     $response = $response . '<back_link>1</back_link>';
  620.                 }else{
  621.                     $response = $response . '<back_link>0</back_link>';
  622.                 }
  623.                 $response = $response . '<home_link>0</home_link>';
  624.                 if($isSessionContinue){
  625.                     $response = $response . '<session_op>continue</session_op>';
  626.                 }else{
  627.                     $response = $response . '<session_op>end</session_op>';
  628.                 }
  629.                 $response = $response . '<screen_id>' . (string) $screenId . '</screen_id>';
  630.                 $response = $response . '</response>';
  631.                 break;
  632.             case "MTNBJ":
  633.                 $response = $response . '<?xml version="1.0" encoding="UTF-8"?>';
  634.                 $response = $response . '<response>';
  635.                 $response = $response . '<text>' . $menuText . '</text>';
  636.                 $response = $response . '</response>';
  637.                 break;
  638.             default:
  639.                 $response = $response . '<?xml version="1.0" encoding="UTF-8"?>';
  640.                 $response = $response . '<response>';
  641.                 $response = $response . '<text>Erreur d\'application</text>';
  642.                 $response = $response . '</response>';
  643.         }
  644.         return $response;
  645.     }
  646. */
  647. }