src/Controller/GestionController.php line 81

Open in your IDE?
  1. <?php
  2. // src/Controller/EntrepriseController.php
  3. namespace App\Controller;
  4. use App\Entity\SujetFAQ;
  5. use App\Entity\Article;
  6. use App\Entity\AppUser;
  7. use App\Entity\Product;
  8. use App\Entity\Review;
  9. use App\Entity\Devis;
  10. use App\Entity\Category;
  11. use App\Entity\Commande;
  12. use App\Entity\Conversation;
  13. use App\Entity\Service;
  14. use App\Entity\ProductOrder;
  15. use App\Entity\Entreprise;
  16. use App\Entity\Notification;
  17. use App\Entity\ProductMisDeCote;
  18. use App\Entity\SubCategory;
  19. use App\Entity\AvisUtilisateur;
  20. use App\Form\SujetFAQType;
  21. use App\Form\AvisUtilisateurType;
  22. use App\Form\AvisUtilisateurEditType;
  23. use App\Form\ProductType;
  24. use App\Entity\ShippingMethod;
  25. use App\Entity\RoleBoutique;
  26. use App\Entity\Boutique;
  27. use App\Form\BoutiqueType;
  28. use App\Entity\Plan;
  29. use App\Entity\ValiditeService;
  30. use App\Entity\UserBoutique;
  31. use App\Entity\RequeteAjoutBoutique;
  32. use App\Entity\TVA;
  33. use Spipu\Html2Pdf\Html2Pdf;
  34. use App\Entity\CategorieEntreprise;
  35. use App\Entity\Produit;
  36. use App\Entity\ProductPhoto;
  37. use App\Entity\OffreDevis;
  38. use App\Form\ProduitType;
  39. use App\Form\ProduitEditType;
  40. use App\Entity\Ticket;
  41. use App\Entity\Message;
  42. use App\Services\CinetPay;
  43. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  44. use App\Form\TicketType;
  45. use App\Entity\CommentaireTicket;
  46. use App\Form\CommentaireTicketType;
  47. use App\Entity\PaiementService;
  48. use App\Form\SettingBoutiqueOngletEntrepriseType;
  49. use App\Form\SettingBoutiqueOngletBanqueType;
  50. use App\Form\SettingBoutiqueOngletInfoLegaleType;
  51. use App\Form\SettingBoutiqueOngletDocumentType;
  52. use App\Form\SettingBoutiqueOngletEmailType;
  53. use Symfony\Component\HttpFoundation\Response;
  54. use Symfony\Component\HttpFoundation\JsonResponse;
  55. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  56. use Symfony\Component\HttpFoundation\Request;
  57. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  58. use Symfony\Component\Routing\Annotation\Route;
  59. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  60. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security as Security;
  61. /**
  62.  * @Route("/{_locale}/gestion")
  63.  */
  64. class GestionController extends AbstractController
  65. {    
  66.     private $session;
  67.     
  68.     public function __construct(SessionInterface $session)
  69.     {
  70.         $this->session $session;
  71.     }
  72.     
  73.     /**
  74.      * @Route("/mes-entreprises/", name="gestion_mes_entreprises")
  75.      * @return \Symfony\Component\HttpFoundation\Response
  76.      */
  77.     public function mesEntrepriseAction(Request $request)
  78.     {
  79.         $em $this->getDoctrine()
  80.                     ->getManager();
  81.     
  82.         $user $this->getUser();
  83.         $userBoutiques $em->getRepository(UserBoutique::class)
  84.                         ->findByUser($user);
  85.         return $this->render('gestion/mes_entreprise.html.twig', [
  86.             'userBoutiques' => $userBoutiques
  87.         ]);
  88.     }
  89.     
  90.     
  91.     /**
  92.      * @Route("/shop/{slug}", name="gestion.show_shop")
  93.      * @return \Symfony\Component\HttpFoundation\Response
  94.      */
  95.     public function afficherBoutiqueAction(Request $requestBoutique $boutique)
  96.     {
  97.         $em $this->getDoctrine()
  98.                     ->getManager();
  99.         $user $this->getUser();
  100.         $userBoutique $em->getRepository(UserBoutique::class)
  101.                         ->findOneBy(
  102.                             array(
  103.                             'user' => $user->getId(),
  104.                             'boutique' => $boutique->getId()
  105.                             )
  106.                         );
  107.         
  108.         if(null == $userBoutique){
  109.             return $this->redirectToRoute('security_login');
  110.         }
  111.         $abonnement $em->getRepository(Commande::class)
  112.                         ->findBy(
  113.                             array(
  114.                                 'boutique' => $boutique 
  115.                             ),
  116.                             array(
  117.                                 'laDate' => 'DESC'
  118.                             ),
  119.                             1
  120.                         );    
  121.         if(!empty($abonnement)){
  122.             $abonnement $abonnement[0];
  123.         }
  124.             
  125.         return $this->render('gestion/afficher_boutique.html.twig', [
  126.             'boutique' => $boutique,
  127.             'userBoutique' => $userBoutique,
  128.             'abonnement' => $abonnement
  129.             
  130.         ]);
  131.     }
  132.     
  133.     /**
  134.      * @Route("/devenir-premium/", name="gestion.devenir_premium")
  135.      * @return \Symfony\Component\HttpFoundation\Response
  136.      */
  137.     public function devenirPremiumAction(Request $requestBoutique $boutique)
  138.     {
  139.         $em $this->getDoctrine()
  140.                     ->getManager();
  141.                     
  142.         $user $this->getUser();
  143.         $userBoutique $em->getRepository(UserBoutique::class)
  144.                         ->findOneBy(
  145.                             array(
  146.                             'user' => $user->getId(),
  147.                             'boutique' => $boutique->getId()
  148.                             )
  149.                         );
  150.         $transId rand(4560100000);
  151.         $transDate = new \DateTime();
  152.         $amount 15000;
  153.         if('POST' == $request->getMethod()){
  154.             var_dump($_POST);
  155.         }
  156.         
  157.         
  158.     $commande = new Commande;
  159.     //transaction id
  160.     $id_transaction rand(); //CinetPay::generateTransId();
  161.     // Payment description
  162.     $description_du_paiement "Devenir premium";
  163.     // Payment Date must be on date format
  164.     $date_transaction date("Y-m-d H:i:s");
  165.     // Amount
  166.     $montant_a_payer 15000;
  167.     // put a value that you can use to identify the buyer in your system
  168.     $identifiant_du_payeur $user->getId().'@@@'.$boutique->getId();
  169.     //Veuillez entrer votre apiKey
  170.     $apiKey "1182873575626ba8e6c712e9.05305545";
  171.     //Secret Key: 127127447062796bafS
  172.     //Veuillez entrer votre siteId
  173.     $site_id "792421";
  174.     //platform ,  utiliser PROD si vous avez créé votre compte sur www.cinetpay.com  ou TEST si vous avez créé votre compte sur www.sandbox.cinetpay.com
  175.     $plateform "PROD";
  176.     //la version ,  utilisé V1 si vous voulez utiliser la version 1 de l'api
  177.     $version "V2";
  178.     // nom du formulaire CinetPay
  179.     $formName "goCinetPay";
  180.     // notify url
  181.     $notify_url $this->generateUrl('gestion.cinetpay_notify', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  182.     // return url
  183.     $return_url =  $this->generateUrl('gestion.cinetpay_return', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  184.     // cancel url
  185.     $cancel_url =  $this->generateUrl('gestion.cinetpay_cancel', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  186.     // cinetpay button type, must be 1, 2, 3, 4 or 5
  187.     $btnType 4;
  188.     // button size, can be 'small' , 'large' or 'larger'
  189.     $btnSize 'large';
  190.     // fill command class
  191.     $commande->setCpmTransId($id_transaction);
  192.     $commande->setCpmAmount($montant_a_payer);
  193.     $commande->setUser($user);
  194.     $commande->setBoutique($boutique);
  195.     $em->persist($commande);
  196.     $em->flush();
  197.    
  198.         return $this->render('gestion/devenir_premium.html.twig', [
  199.             'user' => $user,
  200.             'transId' => $transId,
  201.             'transDate' => $transDate,
  202.             'amount' => $amount,
  203.             'plan' => $plan,
  204.             'transaction' => $id_transaction,
  205.             'formName' => $formName,
  206.             'btnType' => $btnType,
  207.             'btnSize' => $btnSize,
  208.             'boutique' => $boutique,
  209.             'userBoutique' => $userBoutique,
  210.         ]);
  211.         
  212.         return $this->redirectToRoute('gestion.show_shop', array('slug' => $boutique->getSlug()));
  213.             
  214.     }
  215.     /**
  216.      * @Route("/table-formule-pour-paiement/{slug}", name="gestion_table_formule_pour_paiement")
  217.      * @return \Symfony\Component\HttpFoundation\Response
  218.      */
  219.     public function tableFormulePourPaiementAction(Request $requestBoutique $boutique)
  220.     {
  221.         $em $this->getDoctrine()
  222.                     ->getManager();
  223.                     
  224.         $plans $em->getRepository(Plan::class)
  225.                     ->paidPlan();
  226.         return $this->render('gestion/table_formule_pour_paiement.html.twig', [
  227.             'boutique' => $boutique,
  228.             'plans' => $plans
  229.         ]);
  230.     }
  231.     /**
  232.      * @Route("/paiement-abonnement/{idEntreprise}/{idPlan}/{idUser}/{plateforme}", name="gestion_paiement_abonnement")
  233.      * @return \Symfony\Component\HttpFoundation\Response
  234.      */
  235.     public function paiementAbonnementAction(Request $request,  $idEntreprise$idPlan$idUser$plateforme)
  236.     {
  237.         $em $this->getDoctrine()
  238.                     ->getManager();
  239.         $user $this->getUser();
  240.         $boutique =  $em->getRepository(Boutique::class)
  241.                         ->findOneById($idEntreprise);
  242.         if($plateforme == 'mobile'){
  243.             $user =  $em->getRepository(AppUser::class)
  244.                         ->findOneById($idUser);
  245.         }
  246.         
  247.         $userBoutique $em->getRepository(UserBoutique::class)
  248.                         ->findOneBy(
  249.                             array(
  250.                             'user' => $user->getId(),
  251.                             'boutique' => $boutique->getId()
  252.                             )
  253.                         );
  254.         if(null == $userBoutique){
  255.             return $this->createNotFoundException();
  256.         }
  257.         $plan $em->getRepository(Plan::class)
  258.                     ->findOneById($idPlan);
  259.         $transId rand(4560100000);
  260.         $transDate = new \DateTime();
  261.         $amount 15000;
  262.         $message '';
  263.         $error '';
  264.         $qrUrl '';
  265.         $authenticationUrl 'https://billpayment.api.prod.run.billmap.net/api/authentication/token';
  266.         $id_transaction '';
  267.         $apiKeyAndSecret = array(
  268.             'orangekey' => '2CSLsG7IDYHmR8Wp',
  269.             'orangesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  270.             'mtnkey' => '3AXHb9Q0ctzSJqbV',
  271.             'mtnsecret' => 'oDXwYw4XwervcUHof7u7M0tRfRuAYf9aGmgOWYF9y1aMjkWX3lZx312X5ge8L8I9',
  272.             'moovekey' => 'GX7fNUtKpzbaZbrM',
  273.             'moovesecret' => '2OZpbuvcRCDNapJrsVkHTE6gqocNdeN1DxIQIlEpBZjbR6GuQaBYkbim05fDbK1i',
  274.             'wavekey' => '2CSLsG7IDYHmR8Wp',
  275.             'wavesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF'
  276.         );
  277.         
  278.         //variable mise pour la compatibilité mobile
  279.         $keyOperateur = array(
  280.             'orangekey' => '2CSLsG7IDYHmR8Wp',
  281.             'orangesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  282.             'orangedebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/Bill/orange/webpayment',
  283.             'orangecode' => 'MYHELPPLACE_ORANGE',
  284.             'mtnkey' => '2CSLsG7IDYHmR8Wp',
  285.             'mtnsecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  286.             'mtndebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/Bill/debit/openapi',
  287.             'mtncode' => 'MYHELPPLACE_MTNCI',
  288.             'moovkey' => 'GX7fNUtKpzbaZbrM',
  289.             'moovsecret' => '2OZpbuvcRCDNapJrsVkHTE6gqocNdeN1DxIQIlEpBZjbR6GuQaBYkbim05fDbK1i',
  290.             'moovdebiturl' =>'https://billpayment.api.prod.run.billmap.net/api/Bill/debit/moov',
  291.             'moovcode' => 'MYHELPPLACE_MOOVCI',
  292.             'wavekey' => '2CSLsG7IDYHmR8Wp',
  293.             'wavesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  294.             'wavedebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/bill/wave/checkout',
  295.             'wavecode' => 'MYHELPPLACE_WAVE'
  296.         );
  297.         
  298.         if('POST' == $request->getMethod()){
  299.             $formData json_decode($request->getContent());
  300.             if($plateforme == 'web'){
  301.                 $operateurPaiement $request->request->get('operateur_paiement');
  302.                 $numeroDeTelephone $request->request->get('numero_de_telephone');
  303.                 $indicatifPays $request->request->get('indicatif_pays');
  304.                 $mois = (float)$request->request->get('mois');
  305.                 //$montantTransaction = (float)$request->request->get('montant_transaction');
  306.                 $montantTransaction $plan->getTarif() * $mois;
  307.                 $key $request->request->get($operateurPaiement.'key');
  308.                 $secret =  $request->request->get($operateurPaiement.'secret');
  309.                 $debitURL =  $request->request->get($operateurPaiement.'debiturl');
  310.                 $code =  $request->request->get($operateurPaiement.'code');
  311.                 $otp $request->request->get('otp');
  312.             }else{
  313.                 // mobile
  314.             
  315.                 $operateurPaiement $formData->operateur_paiement;
  316.                 $numeroDeTelephone $formData->numero_de_telephone;
  317.                 $indicatifPays $formData->indicatif_pays;
  318.                 $mois = (float)$formData->mois;
  319.                 //$montantTransaction = (float)$formData->montant_transaction;
  320.                 $montantTransaction $plan->getTarif() * $mois;
  321.                 $key $keyOperateur[$operateurPaiement.'key'];
  322.                 $secret =  $keyOperateur[$operateurPaiement.'secret'];
  323.                 $debitURL =  $keyOperateur[$operateurPaiement.'debiturl'];
  324.                 $code =  $keyOperateur[$operateurPaiement.'code'];
  325.                 $otp $formData->otp;
  326.             }
  327.             $content = array(
  328.                 'key' => $apiKeyAndSecret[$operateurPaiement.'key'],
  329.                 'secret' => $apiKeyAndSecret[$operateurPaiement.'secret']
  330.             );
  331.             
  332.             $content json_encode($content);
  333.             $ch curl_init($authenticationUrl);
  334.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  335.             curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  336.             curl_setopt($chCURLOPT_POSTFIELDS$content);
  337.             $serverOutput curl_exec($ch);
  338.             curl_close($ch);
  339.             
  340.             $serverOutput json_decode($serverOutputtrue);
  341.             $id_transaction '';
  342.             if($serverOutput['success']){
  343.                 $commande = new Commande;
  344.                 $commande->setPlan($plan);
  345.                 //transaction id
  346.                 
  347.                 // Payment description
  348.                 $description_du_paiement "Devenir premium";
  349.                 // Payment Date must be on date format
  350.                 $date_transaction date("Y-m-d H:i:s");
  351.                 // Amount
  352.                 $montant_a_payer $montantTransaction;
  353.                 // put a value that you can use to identify the buyer in your system
  354.                 $identifiant_du_payeur $user->getId().'@@@'.$boutique->getId();
  355.                 $commande->setCpmTransId($id_transaction);
  356.                 $commande->setCpmAmount($montant_a_payer);
  357.                 $commande->setUser($user);
  358.                 $commande->setBoutique($boutique);
  359.                 $em->persist($commande);
  360.                 $em->flush();
  361.                 if($operateurPaiement == 'wave'){
  362.                     $content = array(
  363.                     'code' =>  $code,
  364.                     'transactionChannel' => "WEB",
  365.                     'msisdn' => $indicatifPays.$numeroDeTelephone,
  366.                     'reference' => ''.$commande->getId().'',
  367.                     'metaData' => ''.$mois.'@ABONNEMENT',
  368.                     'amount' => $montantTransaction
  369.                     );
  370.                 } else{
  371.                     $content = array(
  372.                     'code' => $code,
  373.                     'msisdn' => $indicatifPays.$numeroDeTelephone,
  374.                     'reference' =>''.$commande->getId().'',
  375.                     'amount' => $montantTransaction,
  376.                     'metaData' =>  ''.$mois.'',
  377.                     'otp' => $otp
  378.                     );
  379.                 }
  380.                                 
  381.                 $content json_encode($content);
  382.                 $ch curl_init($debitURL);
  383.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  384.                 curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type: application/json''Authorization: Bearer '.$serverOutput['token']]);
  385.                 
  386.                 curl_setopt($chCURLOPT_POSTFIELDS$content);
  387.                 $serverOutput curl_exec($ch);
  388.                 curl_close($ch);
  389.                 $serverOutput json_decode($serverOutputtrue);
  390.                 
  391.                 $id_transaction $serverOutput['billMapTransactionId']; 
  392.             
  393.                 // notify url
  394.                 $notify_url $this->generateUrl('gestion_payment_notify', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  395.                 // return url
  396.                 $return_url =  $this->generateUrl('gestion_payment_return', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  397.                 // cancel url
  398.                 $cancel_url =  $this->generateUrl('gestion_payment_cancel', array('transaction' => $id_transaction), UrlGeneratorInterface::ABSOLUTE_URL);
  399.                 $commande->setCpmTransId($id_transaction);
  400.                 $commande->setCpmAmount($montant_a_payer);
  401.                 
  402.                 $em->flush();
  403.                 if($operateurPaiement == 'wave'){
  404.                     
  405.                     if($plateforme == 'web'){
  406.                         //["qr_Url"]=> string(87) "https://pay.wave.com/c/cos-24zr78rx02t1g?a=100.00&c=XOF&m=MYHELPPLACE_WAVE%20%2A%20Eves" }
  407.                         return $this->redirect($serverOutput['qr_Url']);
  408.                     }else{
  409.                         
  410.                         $data = array(
  411.                             'error' => $error,
  412.                             'qrUrl' => $serverOutput['qr_Url'],
  413.                             'message' => $message
  414.                         );
  415.                                 
  416.                         $response = new JsonResponse;
  417.                                 
  418.                         $response $this->allowRemoteRequest($response);
  419.                                 
  420.                         $response->setContent(json_encode($data));
  421.                         return $response;
  422.                     }
  423.                 }
  424.                 return $this->redirectToRoute('gestion_finaliser_abonnement', array('slug' => $boutique->getSlug(), 'plan' => $plan->getSlug()));
  425.             }
  426.         }
  427.         
  428.         if($plateforme == 'mobile'){
  429.             return $this->render('api/paiement_abonnement.html.twig', [
  430.                 'user' => $user,
  431.                 'transId' => $transId,
  432.                 'transDate' => $transDate,
  433.                 'amount' => $amount,
  434.                 'plan' => $plan,
  435.                 'boutique' => $boutique,
  436.                 'userBoutique' => $userBoutique,
  437.                 'transaction' => $id_transaction,
  438.                 'keyOperateur' => $keyOperateur
  439.                 ]);
  440.         }
  441.         return $this->render('gestion/paiement_abonnement.html.twig', [
  442.             'user' => $user,
  443.             'transId' => $transId,
  444.             'transDate' => $transDate,
  445.             'amount' => $amount,
  446.             //'CinetPay' => $CinetPay,
  447.             'plan' => $plan,
  448.             'boutique' => $boutique,
  449.             'userBoutique' => $userBoutique,
  450.             'transaction' => $id_transaction
  451.         ]);    
  452.     }
  453.     /**
  454.      * @Route("/paiement-frais-de-service/{idUser}/{typeService}/{plateforme}", name="gestion_paiement_frais_de_service")
  455.      * @return \Symfony\Component\HttpFoundation\Response
  456.     */
  457.     public function paiementFraisDeServiceAction(Request $request,  $idUser$typeService$plateforme)
  458.     {
  459.         $em $this->getDoctrine()
  460.                     ->getManager();
  461.         $user $em->getRepository(AppUser::class)
  462.                     ->findOneById($idUser);
  463.         
  464.         if(null == $user){
  465.             return $this->createNotFoundException();
  466.         }
  467.         
  468.         $transId rand(4560100000);
  469.         $transDate = new \DateTime();
  470.         $amount 15000;
  471.         $message '';
  472.         $error '';
  473.         $qrUrl '';
  474.         $authenticationUrl 'https://billpayment.api.prod.run.billmap.net/api/authentication/token';
  475.         $id_transaction '';
  476.         $apiKeyAndSecret = array(
  477.             'orangekey' => '2CSLsG7IDYHmR8Wp',
  478.             'orangesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  479.             'mtnkey' => '3AXHb9Q0ctzSJqbV',
  480.             'mtnsecret' => 'oDXwYw4XwervcUHof7u7M0tRfRuAYf9aGmgOWYF9y1aMjkWX3lZx312X5ge8L8I9',
  481.             'moovekey' => 'GX7fNUtKpzbaZbrM',
  482.             'moovesecret' => '2OZpbuvcRCDNapJrsVkHTE6gqocNdeN1DxIQIlEpBZjbR6GuQaBYkbim05fDbK1i',
  483.             'wavekey' => '2CSLsG7IDYHmR8Wp',
  484.             'wavesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF'
  485.         );
  486.         //variable mise pour la compatibilité mobile
  487.         $keyOperateur = array(
  488.             'orangekey' => '2CSLsG7IDYHmR8Wp',
  489.             'orangesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  490.             'orangedebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/Bill/orange/webpayment',
  491.             'orangecode' => 'MYHELPPLACE_ORANGE',
  492.             'mtnkey' => '2CSLsG7IDYHmR8Wp',
  493.             'mtnsecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  494.             'mtndebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/Bill/debit/openapi',
  495.             'mtncode' => 'MYHELPPLACE_MTNCI',
  496.             'moovkey' => 'GX7fNUtKpzbaZbrM',
  497.             'moovsecret' => '2OZpbuvcRCDNapJrsVkHTE6gqocNdeN1DxIQIlEpBZjbR6GuQaBYkbim05fDbK1i',
  498.             'moovdebiturl' =>'https://billpayment.api.prod.run.billmap.net/api/Bill/debit/moov',
  499.             'moovcode' => 'MYHELPPLACE_MOOVCI',
  500.             
  501.             'wavekey' => '2CSLsG7IDYHmR8Wp',
  502.             'wavesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  503.             'wavedebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/bill/wave/checkout',
  504.             'wavecode' => 'MYHELPPLACE_WAVE'
  505.         );
  506.         if('POST' == $request->getMethod()){
  507.             $formData json_decode($request->getContent());
  508.             if($plateforme == 'web'){
  509.                 $operateurPaiement $request->request->get('operateurPaiement');
  510.                 $numeroDeTelephone $request->request->get('numeroDeTelephone');
  511.                 $indicatifPays $request->request->get('indicatifPays');
  512.                 $montantTransaction = (float)$request->request->get('montant');
  513.                 $key $request->request->get($operateurPaiement.'key');
  514.                 $secret =  $request->request->get($operateurPaiement.'secret');
  515.                 $debitURL =  $request->request->get($operateurPaiement.'debiturl');
  516.                 $code =  $request->request->get($operateurPaiement.'code');
  517.                 $otp $request->request->get('otp');
  518.             }else{
  519.                 // mobile
  520.             
  521.                 $operateurPaiement $formData->operateurPaiement;
  522.                 $numeroDeTelephone $formData->numeroDeTelephone;
  523.                 $indicatifPays $formData->indicatifPays;
  524.                 $montantTransaction = (float)$formData->montant;
  525.                 $key $keyOperateur[$operateurPaiement.'key'];
  526.                 $secret =  $keyOperateur[$operateurPaiement.'secret'];
  527.                 $debitURL =  $keyOperateur[$operateurPaiement.'debiturl'];
  528.                 $code =  $keyOperateur[$operateurPaiement.'code'];
  529.                 $otp $formData->otp;
  530.             }
  531.             $content = array(
  532.                 'key' => $apiKeyAndSecret[$operateurPaiement.'key'],
  533.                 'secret' => $apiKeyAndSecret[$operateurPaiement.'secret']
  534.             );
  535.             
  536.             $content json_encode($content);
  537.             $ch curl_init($authenticationUrl);
  538.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  539.             curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  540.             curl_setopt($chCURLOPT_POSTFIELDS$content);
  541.             $serverOutput curl_exec($ch);
  542.             curl_close($ch);
  543.             
  544.             $serverOutput json_decode($serverOutputtrue);
  545.             $id_transaction '';
  546.             if($serverOutput['success']){
  547.                 $paiementService = new PaiementService;
  548.                 $paiementService->setMontant($montantTransaction);
  549.                 $paiementService->setUser($user);
  550.                 //transaction id
  551.                 
  552.                 // Payment description
  553.                 $description_du_paiement "Devenir premium";
  554.                 // Payment Date must be on date format
  555.                 $date_transaction date("Y-m-d H:i:s");
  556.                 // Amount
  557.                 $montant_a_payer $montantTransaction;
  558.                 //$commande->setCpmTransId($id_transaction);
  559.                 //$commande->setCpmAmount($montant_a_payer);
  560.                 //$commande->setUser($user);
  561.                 $em->persist($paiementService);
  562.                 $em->flush();
  563.                 if($operateurPaiement == 'wave'){
  564.                     $content = array(
  565.                     'code' =>  $code,
  566.                     'transactionChannel' => "WEB",
  567.                     'msisdn' => $indicatifPays.$numeroDeTelephone,
  568.                     'reference' => ''.$paiementService->getId().'',
  569.                     'metaData' => ''.$paiementService->getId().'@SERVICE',
  570.                     'amount' => $montantTransaction
  571.                     );
  572.                 } else{
  573.                     $content = array(
  574.                     'code' => $code,
  575.                     'msisdn' => $indicatifPays.$numeroDeTelephone,
  576.                     'reference' =>''.$paiementService->getId().'',
  577.                     'amount' => $montantTransaction,
  578.                     'metaData' => ''.$paiementService->getId().'@SERVICE',
  579.                     'otp' => $otp
  580.                     );
  581.                 }
  582.                                 
  583.                 $content json_encode($content);
  584.                 
  585.                 $ch curl_init($debitURL);
  586.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  587.                 curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type: application/json''Authorization: Bearer '.$serverOutput['token']]);
  588.                 
  589.                 curl_setopt($chCURLOPT_POSTFIELDS$content);
  590.                 $serverOutput curl_exec($ch);
  591.                 var_dump($serverOutput);
  592.                 curl_close($ch);
  593.                 
  594.                 $serverOutput json_decode($serverOutputtrue);
  595.                 
  596.                 $id_transaction $serverOutput['billMapTransactionId']; 
  597.                 $paiementService->setCpmTransId($id_transaction);
  598.                 //$commande->setCpmAmount($montant_a_payer);
  599.                 
  600.                 $em->flush();
  601.                 if($operateurPaiement == 'wave'){
  602.                     
  603.                     if($plateforme == 'web'){
  604.                         //["qr_Url"]=> string(87) "https://pay.wave.com/c/cos-24zr78rx02t1g?a=100.00&c=XOF&m=MYHELPPLACE_WAVE%20%2A%20Eves" }
  605.                         return $this->redirect($serverOutput['qr_Url']);
  606.                     }else{
  607.                         $data = array(
  608.                             'error' => $error,
  609.                             'qrUrl' => $serverOutput['qr_Url'],
  610.                             'message' => $message
  611.                         );
  612.                                 
  613.                         $response = new JsonResponse;
  614.                                 
  615.                         $response $this->allowRemoteRequest($response);
  616.                                 
  617.                         $response->setContent(json_encode($data));
  618.                         return $response;
  619.                     }
  620.                 }
  621.                 //return $this->redirectToRoute('gestion_finaliser_abonnement', array('slug' => $boutique->getSlug(), 'plan' => $plan->getSlug()));
  622.             }
  623.         }
  624.         
  625.         if($plateforme == 'mobile'){
  626.             return $this->render('api/paiement_service.html.twig', [
  627.                 
  628.                 ]);
  629.         }
  630.         return $this->render('gestion/paiement_abonnement.html.twig', [
  631.             'user' => $user,
  632.             'transId' => $transId,
  633.             'transDate' => $transDate,
  634.             'amount' => $amount,
  635.             //'CinetPay' => $CinetPay,
  636.             'plan' => $plan,
  637.             'boutique' => $boutique,
  638.             'userBoutique' => $userBoutique,
  639.             'transaction' => $id_transaction
  640.         ]);    
  641.         if($request->getMethod() == 'POST'){
  642.             
  643.             $formData json_decode($request->getContent());
  644.             
  645.             $dateDebut $formData->dateDebut;
  646.             $dateDebut = new \DateTime($dateDebut);
  647.             $dateDebut->setTime(00);
  648.             
  649.             $dateFin $formData->dateFin;
  650.             //$dateFin = $request->request->get('dateFin');
  651.             
  652.             $dateFin = new \DateTime($dateFin);
  653.             $dateFin->setTime(2359);
  654.             $demandeRetraits $em->getRepository(DemandeRetrait::class)
  655.                                 ->demandeDUnePeriode($boutique->getId(), $dateDebut$dateFintrue);
  656.         }
  657.         $data = array(
  658.                 'error' => '',
  659.                 'message' => '',
  660.                 'demandeRetraits' => $demandeRetraits
  661.                 
  662.         );
  663.         $response = new JsonResponse;
  664.         
  665.         $response $this->allowRemoteRequest($response);
  666.         
  667.         $response->setContent(json_encode($data));
  668.         return $response;
  669.         
  670.         return $this->render('api/envoyer_push_notification.html.twig', [ 
  671.             
  672.         ]);        
  673.     }
  674.     /**
  675.      * @Route("/paiement-prestation/{idUser}/{idOffreDevis}/{plateforme}", name="gestion_paiement_de_prestation")
  676.      * @return \Symfony\Component\HttpFoundation\Response
  677.     */
  678.     public function paiementPrestationAction(Request $request,  $idUser$idOffreDevis$plateforme)
  679.     {
  680.         $em $this->getDoctrine()
  681.                     ->getManager();
  682.         $user $em->getRepository(AppUser::class)
  683.                     ->findOneById($idUser);
  684.         
  685.         if(null == $user){
  686.             return $this->createNotFoundException();
  687.         }
  688.         $offreDevis =  $em->getRepository(OffreDevis::class)
  689.                     ->findOneById($idOffreDevis);
  690.         
  691.         $transId rand(4560100000);
  692.         $transDate = new \DateTime();
  693.         $amount 15000;
  694.         $message '';
  695.         $error '';
  696.         $qrUrl '';
  697.         $authenticationUrl 'https://billpayment.api.prod.run.billmap.net/api/authentication/token';
  698.         $id_transaction '';
  699.         $apiKeyAndSecret = array(
  700.             'orangekey' => '2CSLsG7IDYHmR8Wp',
  701.             'orangesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  702.             'mtnkey' => '3AXHb9Q0ctzSJqbV',
  703.             'mtnsecret' => 'oDXwYw4XwervcUHof7u7M0tRfRuAYf9aGmgOWYF9y1aMjkWX3lZx312X5ge8L8I9',
  704.             'moovekey' => 'GX7fNUtKpzbaZbrM',
  705.             'moovesecret' => '2OZpbuvcRCDNapJrsVkHTE6gqocNdeN1DxIQIlEpBZjbR6GuQaBYkbim05fDbK1i',
  706.             'wavekey' => '2CSLsG7IDYHmR8Wp',
  707.             'wavesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF'
  708.         );
  709.         //variable mise pour la compatibilité mobile
  710.         $keyOperateur = array(
  711.             'orangekey' => '2CSLsG7IDYHmR8Wp',
  712.             'orangesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  713.             'orangedebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/Bill/orange/webpayment',
  714.             'orangecode' => 'MYHELPPLACE_ORANGE',
  715.             'mtnkey' => '2CSLsG7IDYHmR8Wp',
  716.             'mtnsecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  717.             'mtndebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/Bill/debit/openapi',
  718.             'mtncode' => 'MYHELPPLACE_MTNCI',
  719.             'moovkey' => 'GX7fNUtKpzbaZbrM',
  720.             'moovsecret' => '2OZpbuvcRCDNapJrsVkHTE6gqocNdeN1DxIQIlEpBZjbR6GuQaBYkbim05fDbK1i',
  721.             'moovdebiturl' =>'https://billpayment.api.prod.run.billmap.net/api/Bill/debit/moov',
  722.             'moovcode' => 'MYHELPPLACE_MOOVCI',
  723.             
  724.             'wavekey' => '2CSLsG7IDYHmR8Wp',
  725.             'wavesecret' => '3puc5vA7cySjUGoCkAJZ5nzIesMg0uWdLVsNchbvClZz8ZqtBwzz1bdOMSxnWEzF',
  726.             'wavedebiturl' => 'https://billpayment.api.prod.run.billmap.net/api/bill/wave/checkout',
  727.             'wavecode' => 'MYHELPPLACE_WAVE'
  728.         );
  729.         if('POST' == $request->getMethod()){
  730.             $formData json_decode($request->getContent());
  731.             if($plateforme == 'web'){
  732.                 $operateurPaiement $request->request->get('operateurPaiement');
  733.                 $numeroDeTelephone $request->request->get('numeroDeTelephone');
  734.                 $indicatifPays $request->request->get('indicatifPays');
  735.                 $montantTransaction $offreDevis->getValeurFinanciere();
  736.                 $key $request->request->get($operateurPaiement.'key');
  737.                 $secret =  $request->request->get($operateurPaiement.'secret');
  738.                 $debitURL =  $request->request->get($operateurPaiement.'debiturl');
  739.                 $code =  $request->request->get($operateurPaiement.'code');
  740.                 $otp $request->request->get('otp');
  741.             }else{
  742.                 // mobile
  743.             
  744.                 $operateurPaiement $formData->operateurPaiement;
  745.                 $numeroDeTelephone $formData->numeroDeTelephone;
  746.                 $indicatifPays $formData->indicatifPays;
  747.                 $montantTransaction $offreDevis->getValeurFinanciere();
  748.                 $key $keyOperateur[$operateurPaiement.'key'];
  749.                 $secret =  $keyOperateur[$operateurPaiement.'secret'];
  750.                 $debitURL =  $keyOperateur[$operateurPaiement.'debiturl'];
  751.                 $code =  $keyOperateur[$operateurPaiement.'code'];
  752.                 $otp $formData->otp;
  753.             }
  754.             $content = array(
  755.                 'key' => $apiKeyAndSecret[$operateurPaiement.'key'],
  756.                 'secret' => $apiKeyAndSecret[$operateurPaiement.'secret']
  757.             );
  758.             
  759.             $content json_encode($content);
  760.             $ch curl_init($authenticationUrl);
  761.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  762.             curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type: application/json']);
  763.             curl_setopt($chCURLOPT_POSTFIELDS$content);
  764.             $serverOutput curl_exec($ch);
  765.             curl_close($ch);
  766.             
  767.             $serverOutput json_decode($serverOutputtrue);
  768.             $id_transaction '';
  769.             if($serverOutput['success']){
  770.                 $paiementService = new PaiementService;
  771.                 $paiementService->setMontant($montantTransaction);
  772.                 $paiementService->setUser($user);
  773.                 $paiementService->setTypeService('PRESTATION');
  774.                 //transaction id
  775.                 
  776.                 // Payment description
  777.                 $description_du_paiement "Devenir premium";
  778.                 // Payment Date must be on date format
  779.                 $date_transaction date("Y-m-d H:i:s");
  780.                 // Amount
  781.                 $montant_a_payer $montantTransaction;
  782.                 //$commande->setCpmTransId($id_transaction);
  783.                 //$commande->setCpmAmount($montant_a_payer);
  784.                 //$commande->setUser($user);
  785.                 $em->persist($paiementService);
  786.                 $em->flush();
  787.                 if($operateurPaiement == 'wave'){
  788.                     $content = array(
  789.                     'code' =>  $code,
  790.                     'transactionChannel' => "WEB",
  791.                     'msisdn' => $indicatifPays.$numeroDeTelephone,
  792.                     'reference' => ''.$paiementService->getId().'',
  793.                     'metaData' => ''.$offreDevis->getId().'@PRESTATION',
  794.                     'amount' => $montantTransaction
  795.                     );
  796.                 } else{
  797.                     $content = array(
  798.                     'code' => $code,
  799.                     'msisdn' => $indicatifPays.$numeroDeTelephone,
  800.                     'reference' =>''.$paiementService->getId().'',
  801.                     'amount' => $montantTransaction,
  802.                     'metaData' => ''.$offreDevis->getId().'@PRESTATION',
  803.                     'otp' => $otp
  804.                     );
  805.                 }
  806.                                 
  807.                 $content json_encode($content);
  808.                 
  809.                 $ch curl_init($debitURL);
  810.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  811.                 curl_setopt($chCURLOPT_HTTPHEADER, ['Content-Type: application/json''Authorization: Bearer '.$serverOutput['token']]);
  812.                 
  813.                 curl_setopt($chCURLOPT_POSTFIELDS$content);
  814.                 $serverOutput curl_exec($ch);
  815.                 var_dump($serverOutput);
  816.                 curl_close($ch);
  817.                 
  818.                 $serverOutput json_decode($serverOutputtrue);
  819.                 
  820.                 $id_transaction $serverOutput['billMapTransactionId']; 
  821.                 $paiementService->setCpmTransId($id_transaction);
  822.                 //$commande->setCpmAmount($montant_a_payer);
  823.                 
  824.                 $em->flush();
  825.                 if($operateurPaiement == 'wave'){
  826.                     
  827.                     if($plateforme == 'web'){
  828.                         //["qr_Url"]=> string(87) "https://pay.wave.com/c/cos-24zr78rx02t1g?a=100.00&c=XOF&m=MYHELPPLACE_WAVE%20%2A%20Eves" }
  829.                         return $this->redirect($serverOutput['qr_Url']);
  830.                     }else{
  831.                         $data = array(
  832.                             'error' => $error,
  833.                             'qrUrl' => $serverOutput['qr_Url'],
  834.                             'message' => $message
  835.                         );
  836.                                 
  837.                         $response = new JsonResponse;
  838.                                 
  839.                         $response $this->allowRemoteRequest($response);
  840.                                 
  841.                         $response->setContent(json_encode($data));
  842.                         return $response;
  843.                     }
  844.                 }
  845.                 //return $this->redirectToRoute('gestion_finaliser_abonnement', array('slug' => $boutique->getSlug(), 'plan' => $plan->getSlug()));
  846.             }
  847.         }
  848.         
  849.         if($plateforme == 'mobile'){
  850.             return $this->render('api/paiement_prestation.html.twig', [
  851.                 
  852.                 ]);
  853.         }
  854.         return $this->render('gestion/paiement_abonnement.html.twig', [
  855.             'user' => $user,
  856.             'transId' => $transId,
  857.             'transDate' => $transDate,
  858.             'amount' => $amount,
  859.             //'CinetPay' => $CinetPay,
  860.             'plan' => $plan,
  861.             'boutique' => $boutique,
  862.             'userBoutique' => $userBoutique,
  863.             'transaction' => $id_transaction
  864.         ]);    
  865.         if($request->getMethod() == 'POST'){
  866.             
  867.             $formData json_decode($request->getContent());
  868.             
  869.             $dateDebut $formData->dateDebut;
  870.             $dateDebut = new \DateTime($dateDebut);
  871.             $dateDebut->setTime(00);
  872.             
  873.             $dateFin $formData->dateFin;
  874.             //$dateFin = $request->request->get('dateFin');
  875.             
  876.             $dateFin = new \DateTime($dateFin);
  877.             $dateFin->setTime(2359);
  878.             $demandeRetraits $em->getRepository(DemandeRetrait::class)
  879.                                 ->demandeDUnePeriode($boutique->getId(), $dateDebut$dateFintrue);
  880.         }
  881.         $data = array(
  882.                 'error' => '',
  883.                 'message' => '',
  884.                 'demandeRetraits' => $demandeRetraits
  885.                 
  886.         );
  887.         $response = new JsonResponse;
  888.         
  889.         $response $this->allowRemoteRequest($response);
  890.         
  891.         $response->setContent(json_encode($data));
  892.         return $response;
  893.         
  894.         return $this->render('api/envoyer_push_notification.html.twig', [ 
  895.             
  896.         ]);        
  897.     }
  898.     /**
  899.      * @Route("/finaliser-abonnement/{slug}/{plan}", name="gestion_finaliser_abonnement")
  900.      * @return \Symfony\Component\HttpFoundation\Response
  901.      */
  902.     public function finaliserAction(Request $requestBoutique $boutique$plan)
  903.     {
  904.         $em $this->getDoctrine()
  905.                     ->getManager();
  906.                     
  907.         $user $this->getUser();
  908.         $userBoutique $em->getRepository(UserBoutique::class)
  909.                         ->findOneBy(
  910.                             array(
  911.                             'user' => $user->getId(),
  912.                             'boutique' => $boutique->getId()
  913.                             )
  914.                         );
  915.         $plan $em->getRepository(Plan::class)
  916.                         ->findOneBySlug($plan);
  917.         return $this->render('gestion/finaliser_abonnement.html.twig', [
  918.                 'user' => $user,
  919.                 'boutique' => $boutique,
  920.                 'userBoutique' => $userBoutique,
  921.                 'plan' => $plan
  922.             ]);
  923.     }
  924.     /**
  925.     * @Route("/payment/billmap-return", name="gestion_billmap_return")
  926.     */
  927.     public function billmapReturnAction(Request $request)
  928.     {
  929.         $em $this->getDoctrine()
  930.                     ->getManager();
  931.         $user $this->getUser();
  932.         /* 
  933.         https://www.myhelpplace.com/fr/gestion/payment/billmap-return?
  934.         // Reference=66&
  935.         // Amount=100.00&
  936.         // MSISDN=2250574053562&
  937.         // NetworkMSISDN=2250574053562&
  938.         // BillMapTransactionId=T4398121&
  939.         // ExternalTransactionId=16464863303&
  940.         // ResponseCode=01&
  941.         // ResponseMessage=Successfully
  942.         */
  943.         $reference $request->query->get('Reference'); //Ici, c'est bien la valeur qui avait été passé dans "metaData" lors de la requete 
  944.         $montant $request->query->get('Amount');
  945.         $mois $request->query->get('MetaData');
  946.         $numeroDeTelephone $request->query->get('MSISDN');
  947.         $billMapTransactionId $request->query->get('BillMapTransactionId');
  948.         $responseMessage $request->query->get('ResponseMessage');
  949.         $responseCode $request->query->get('ResponseCode');
  950.         
  951.         if($responseCode == '01'){
  952.             $reference explode('@'$reference); //'metaData' => ''.$paiementService->getId().'@SERVICE',
  953.             if($reference[1] == 'ABONNEMENT'){
  954.                 //Si la transaction a marché 
  955.                 $commande $em->getRepository(Commande::class)
  956.                         ->findOneByCpmTransId($billMapTransactionId);
  957.                 $dateFin  =  new \DateTime();
  958.                 //
  959.                 $dateFin->modify('+'.$mois .' month');
  960.                 $commande->setDateFin($dateFin);
  961.                 $em->flush();
  962.             }
  963.             if($reference[1] == 'SERVICE'){
  964.                 //Si la transaction a marché 
  965.                 $paiementService $em->getRepository(PaiementService::class)
  966.                         ->findOneByCpmTransId($billMapTransactionId);
  967.                 $paiementService->setEtat('VALIDE');
  968.                 
  969.                 $em->flush();
  970.             }
  971.             if($reference[1] == 'PRESTATION'){
  972.                 //Si la transaction a marché 
  973.                 $paiementService $em->getRepository(PaiementService::class)
  974.                         ->findOneByCpmTransId($billMapTransactionId);
  975.                 $paiementService->setEtat('VALIDE');
  976.                 $offreDevis $em->getRepository(OffreDevis::class)
  977.                                 ->findOneById($reference[1]);
  978.                 $boutique $offreDevis->getDevis()->getBoutique();
  979.                 $boutique->setSolde($boutique->setSolde() + $paiementService->getMontant()*90/100);
  980.                 $em->flush();
  981.             }
  982.             
  983.         }
  984.         $response = new JsonResponse;
  985.         $data = array(
  986.             'mois' => 'Mois souscrit '$mois,
  987.             'montant' => 'Montant ' $montant,
  988.             'bonjour' => 'Bonjour tout le monde'
  989.         );
  990.         $response $this->allowRemoteRequest($response);
  991.         
  992.         $response->setContent(json_encode($data));
  993.         return $response;
  994.         return $this->render('gestion/billmap_return.html.twig', [
  995.             
  996.             'user' => $user
  997.         ]);
  998.     }
  999.     /**
  1000.     * @Route("/payment/notify/{transaction}", name="gestion_payment_notify")
  1001.     */
  1002.     public function paymentNotifyAction($transaction)
  1003.     {
  1004.         $em $this->getDoctrine()
  1005.                     ->getManager();
  1006.         $user $this->getUser();
  1007.         
  1008.         $requestStack $this->get('request_stack');
  1009.         $request $requestStack->getCurrentRequest();
  1010.         $ok_submission '';
  1011.         $error '';
  1012.         
  1013.         $commande $em->getRePository(Commande::class)
  1014.                             ->findOneByCpmTransId($transaction);
  1015.         $messageRequete '';        
  1016.         $errorMessage '';
  1017.         if('POST' == $request->getMethod()){
  1018.             
  1019.         $id_transaction $_POST['cpm_trans_id'];
  1020.         $apiKey "1182873575626ba8e6c712e9.05305545";
  1021.         //Secret Key: 127127447062796bafS
  1022.         //Veuillez entrer votre siteId
  1023.         $site_id "792421";
  1024.         $plateform "PROD"// Valorisé à PROD si vous êtes en production
  1025.         $version "V2"// Valorisé à V1 si vous voulez utiliser la version 1 de l'api
  1026.         $CinetPay = new CinetPay($site_id$apiKey$plateform$version);
  1027.         // Reprise exacte des bonnes données chez CinetPay
  1028.         $CinetPay->setTransId($id_transaction)->getPayStatus();
  1029.         $cpm_site_id $CinetPay->_cpm_site_id;
  1030.         $signature $CinetPay->_signature;
  1031.         $cpm_amount $CinetPay->_cpm_amount;
  1032.         $cpm_trans_id $CinetPay->_cpm_trans_id;
  1033.         $cpm_custom $CinetPay->_cpm_custom;
  1034.         $cpm_currency $CinetPay->_cpm_currency;
  1035.         $cpm_payid $CinetPay->_cpm_payid;
  1036.         $cpm_payment_date $CinetPay->_cpm_payment_date;
  1037.         $cpm_payment_time $CinetPay->_cpm_payment_time;
  1038.         $cpm_error_message $CinetPay->_cpm_error_message;
  1039.         $payment_method $CinetPay->_payment_method;
  1040.         $cpm_phone_prefixe $CinetPay->_cpm_phone_prefixe;
  1041.         $cel_phone_num $CinetPay->_cel_phone_num;
  1042.         $cpm_ipn_ack $CinetPay->_cpm_ipn_ack;
  1043.         $created_at $CinetPay->_created_at;
  1044.         $updated_at $CinetPay->_updated_at;
  1045.         $cpm_result $CinetPay->_cpm_result;
  1046.         $cpm_trans_status $CinetPay->_cpm_trans_status;
  1047.         $cpm_designation $CinetPay->_cpm_designation;
  1048.         $buyer_name $CinetPay->_buyer_name;
  1049.         
  1050.         $commande $em->getRePository(Commande::class)
  1051.                             ->findOneByCpmTransId($cpm_trans_id);
  1052.         if($commande->getCpmTransStatus() == '00'){
  1053.             //Paiement déjà validé
  1054.         } else{
  1055.             $commande->setPaymentMethod($payment_method);
  1056.             $commande->setCpmPayid($cpm_payid);
  1057.             $commande->setBuyerName($buyer_name);
  1058.             $commande->setSignature($signature);
  1059.             $commande->setCelPhoneNum($cel_phone_num);
  1060.             //$commande->setCpmPaymentDate($cpm_payment_date . ' ' . $cpm_payment_time);
  1061.             if ($commande->getCpmAmount() == $cpm_amount) {
  1062.                 // C'est OK : On continue le remplissage des nouvelles données
  1063.                 $commande->setCpmErrorMessage($cpm_error_message);
  1064.                 $commande->setCpmTransStatus($cpm_result);
  1065.                 //$commande->setCpmTransStatus($cpm_trans_status);
  1066.                 if($cpm_result == '00'){
  1067.                     //Le paiement est bon
  1068.                     // Traitez et delivrez le service au client
  1069.                     $em->flush();
  1070.                     $customArray explode('@@@'$cpm_custom);
  1071.                     $boutique $em->getRepository(Boutique::class)
  1072.                                     ->findOneById($customArray[1]);
  1073.                     $boutique->setEstPro(true);
  1074.                     $boutique->getDatePremium($commande->getLaDate());
  1075.                     $em->flush();
  1076.                     return $this->redirect($this->generateUrl('gestion.show_shop', array('slug' =>$boutique->getSlug())));
  1077.                     $errorMessage 'Paiement effectué avec succès';
  1078.                 }else{
  1079.                     //Le paiement a échoué
  1080.                 }
  1081.         } else {
  1082.             //Fraude : montant payé ' . $cpm_amount . ' ne correspond pas au montant de la commande
  1083.             $commande->setCpmTransStatus('-1');
  1084.             //$commande->setTransStatus('REFUSED');
  1085.         }
  1086.         // On met à jour notre ligne
  1087.         //$commande->update();
  1088.         
  1089.         }
  1090.         
  1091.         }
  1092.         return $this->render('gestion/payment_notify.html.twig', [
  1093.             'pageTitle' => $pageTitle,
  1094.             'user' => $user,
  1095.             'errorMessage' => $errorMessage
  1096.         ]);
  1097.     }
  1098.     
  1099.     /**
  1100.     * @Route("/payment/return/{transaction}", name="gestion_payment_return")
  1101.      */
  1102.     public function paymentReturnAction($transaction)
  1103.     {
  1104.         $em $this->getDoctrine()
  1105.                     ->getManager();
  1106.         $user $this->getUser();
  1107.         
  1108.         $requestStack $this->get('request_stack');
  1109.         $request $requestStack->getCurrentRequest();
  1110.         $ok_submission '';
  1111.         $error '';
  1112.         
  1113.         $messageRequete '';
  1114.         $errorMessage '';
  1115.         $pageTitle 'Devenir premium';
  1116.         $commande $em->getRePository(Commande::class)
  1117.                             ->findOneByCpmTransId($transaction);
  1118.         
  1119.         if('POST' == $request->getMethod()){
  1120.             $errorMessage 'Paiement effectué avec succès'
  1121.             $id_transaction $_POST['cpm_trans_id'];
  1122.         $apiKey "1182873575626ba8e6c712e9.05305545";
  1123.         //Secret Key: 127127447062796bafS
  1124.         //Veuillez entrer votre siteId
  1125.         $site_id "792421";
  1126.         $plateform "PROD"// Valorisé à PROD si vous êtes en production
  1127.         $version "V2"// Valorisé à V1 si vous voulez utiliser la version 1 de l'api
  1128.         $CinetPay = new CinetPay($site_id$apiKey$plateform$version);
  1129.         // Reprise exacte des bonnes données chez CinetPay
  1130.         $CinetPay->setTransId($id_transaction)->getPayStatus();
  1131.         $cpm_site_id $CinetPay->_cpm_site_id;
  1132.         $signature $CinetPay->_signature;
  1133.         $cpm_amount $CinetPay->_cpm_amount;
  1134.         $cpm_trans_id $CinetPay->_cpm_trans_id;
  1135.         $cpm_custom $CinetPay->_cpm_custom;
  1136.         $cpm_currency $CinetPay->_cpm_currency;
  1137.         $cpm_payid $CinetPay->_cpm_payid;
  1138.         $cpm_payment_date $CinetPay->_cpm_payment_date;
  1139.         $cpm_payment_time $CinetPay->_cpm_payment_time;
  1140.         $cpm_error_message $CinetPay->_cpm_error_message;
  1141.         $payment_method $CinetPay->_payment_method;
  1142.         $cpm_phone_prefixe $CinetPay->_cpm_phone_prefixe;
  1143.         $cel_phone_num $CinetPay->_cel_phone_num;
  1144.         $cpm_ipn_ack $CinetPay->_cpm_ipn_ack;
  1145.         $created_at $CinetPay->_created_at;
  1146.         $updated_at $CinetPay->_updated_at;
  1147.         $cpm_result $CinetPay->_cpm_result;
  1148.         $cpm_trans_status $CinetPay->_cpm_trans_status;
  1149.         $cpm_designation $CinetPay->_cpm_designation;
  1150.         $buyer_name $CinetPay->_buyer_name;
  1151.         
  1152.         $customArray explode('@@@'$cpm_custom);
  1153.         $boutique $em->getRepository(Boutique::class)
  1154.                                     ->findOneById($customArray[1]);
  1155.         
  1156.         return $this->redirect($this->generateUrl('gestion.show_shop', array('slug' =>$boutique->getSlug())));
  1157.                     
  1158.         }
  1159.         return $this->render('gestion/cinetpay_return.html.twig', [
  1160.             'pageTitle' => $pageTitle,
  1161.             'user' => $user,
  1162.             'errorMessage' => $errorMessage
  1163.         ]);
  1164.     }
  1165.     
  1166.     /**
  1167.     * @Route("/payment/cancel/{transaction}", name="gestion_payment_cancel")
  1168.      */
  1169.     public function paymentCancelction($transaction)
  1170.     {
  1171.         $em $this->getDoctrine()
  1172.                     ->getManager();
  1173.         $user $this->getUser();
  1174.         
  1175.         $requestStack $this->get('request_stack');
  1176.         $request $requestStack->getCurrentRequest();
  1177.         $ok_submission '';
  1178.         $error '';
  1179.         
  1180.         $commande $em->getRePository(Commande::class)
  1181.                             ->findOneByCpmTransId($transaction);
  1182.                             
  1183.         $messageRequete '';        
  1184.         
  1185.         
  1186.         if('POST' == $request->getMethod()){
  1187.             var_dump($_POST);
  1188.         }
  1189.         return $this->render('gestion/cinetpay_cancel.html.twig', [
  1190.             
  1191.             'user' => $user
  1192.         ]);
  1193.     }
  1194.     
  1195.         /**
  1196.      * @Route("/shop/{slug}/mini-statistic", name="gestion.mini_statistic")
  1197.      * @return \Symfony\Component\HttpFoundation\Response
  1198.      */
  1199.     public function miniStatisticAction(Request $requestBoutique $boutique)
  1200.     {
  1201.         $em $this->getDoctrine()
  1202.                     ->getManager();
  1203.         
  1204.         $user $this->getUser();
  1205.               
  1206.         
  1207.         $mois date('mY');
  1208.         $annee date('Y');
  1209.         
  1210.         $nombreOffreDevis $em->getRepository(OffreDevis::class)
  1211.                         ->nombreOffreDevis($boutique->getId());
  1212.         
  1213.         $conversations $em->getRepository(Conversation::class)
  1214.                         ->nombreMessageDUneBoutique($boutique->getId());    
  1215.             
  1216.         $nombreTiers 0;
  1217.         
  1218.         $userBoutique $em->getRepository(UserBoutique::class)
  1219.                         ->findOneBy(
  1220.                             array(
  1221.                             'user' => $user->getId(),
  1222.                             'boutique' => $boutique->getId()
  1223.                             )
  1224.                         );
  1225.                         
  1226.         return $this->render('gestion/mini_statistic.html.twig', [
  1227.            'boutique' => $boutique,
  1228.            'userBoutique' => $userBoutique,
  1229.            'nombreOffreDevis' => $nombreOffreDevis,
  1230.            'conversations' => $conversations
  1231.         ]);
  1232.     }
  1233.     
  1234.     
  1235.         
  1236.     /**
  1237.      * @Route("/{slug}/settings", name="gestion.settings")
  1238.      * @return \Symfony\Component\HttpFoundation\Response
  1239.      */
  1240.     public function settingsAction(Request $requestBoutique $boutique)
  1241.     {
  1242.         $em $this->getDoctrine()
  1243.                     ->getManager();
  1244.         $user $this->getUser();        
  1245.         $userBoutique $em->getRepository(UserBoutique::class)
  1246.                         ->findOneBy(
  1247.                             array(
  1248.                             'user' => $user->getId(),
  1249.                             'boutique' => $boutique->getId()
  1250.                             )
  1251.                         );
  1252.         $form $this->createForm(SettingBoutiqueOngletEntrepriseType::class, $boutique);
  1253.         $aUnAbonnementPayant false;
  1254.         $commande $em->getRepository(Commande::class)
  1255.                     ->findOneBy(
  1256.                         array(
  1257.                             'boutique' => $boutique
  1258.                         ),
  1259.                         array(
  1260.                             'dateFin' => 'DESC'
  1261.                         )
  1262.                     );
  1263.         if($commande != null){
  1264.             $aujourdhui = new \DateTime();
  1265.             if($commande->getDateFin() > $aujourdhui){
  1266.                 $aUnAbonnementPayant true;
  1267.             }
  1268.         }
  1269.         if($request->getMethod() == 'POST'){
  1270.                $form->handleRequest($request);
  1271.                if($form->isValid()){
  1272.                    $em->flush();
  1273.                 } else {
  1274.                     $error =" Veillez corrigez vos erreurs";
  1275.                 }
  1276.         }
  1277.         return $this->render('gestion/settings.html.twig', [
  1278.            'boutique' => $boutique,
  1279.             'form' => $form->createView(),
  1280.             'userBoutique' => $userBoutique,
  1281.             'aUnAbonnementPayant' => $aUnAbonnementPayant
  1282.         ]);
  1283.     }
  1284.     
  1285.     
  1286.     /**
  1287.      * @Route("/{slug}/edit-entreprise", name="gestion.edit_entreprise")
  1288.      * @return \Symfony\Component\HttpFoundation\Response
  1289.      */
  1290.     public function editEntrepriseAction(Request $requestBoutique $boutique)
  1291.     {
  1292.         $em $this->getDoctrine()
  1293.                     ->getManager();
  1294.         $user $this->getUser();        
  1295.         $userBoutique $em->getRepository(UserBoutique::class)
  1296.                         ->findOneBy(
  1297.                             array(
  1298.                             'user' => $user->getId(),
  1299.                             'boutique' => $boutique->getId()
  1300.                             )
  1301.                         );    
  1302.         $form $this->createForm(SettingBoutiqueOngletEntrepriseType::class, $boutique);
  1303.         $aUnAbonnementPayant false;
  1304.         $commande $em->getRepository(Commande::class)
  1305.                     ->findOneBy(
  1306.                         array(
  1307.                             'boutique' => $boutique
  1308.                         ),
  1309.                         array(
  1310.                             'dateFin' => 'DESC'
  1311.                         )
  1312.                     );
  1313.         if($commande != null){
  1314.             $aujourdhui = new \DateTime();
  1315.             if($commande->getDateFin() >= $aujourdhui){
  1316.                 $aUnAbonnementPayant true;
  1317.             }
  1318.         }
  1319.         if($request->getMethod() == 'POST'){
  1320.                $form->handleRequest($request);
  1321.                if($form->isValid()){
  1322.                   
  1323.                    if(isset($_FILES['logo']) && $_FILES['logo']['error'] == ){
  1324.                        $this->gererFichierMultipleLogo($boutique$_FILES['logo']);
  1325.                       
  1326.                    }
  1327.                    $em->flush();
  1328.                 } else {
  1329.                     $error =" Veillez corrigez vos erreurs";
  1330.                 }
  1331.         }
  1332.         return $this->render('gestion/edit_entreprise.html.twig', [
  1333.            'boutique' => $boutique,
  1334.             'form' => $form->createView(),
  1335.             'userBoutique' => $userBoutique,
  1336.             'aUnAbonnementPayant' => $aUnAbonnementPayant
  1337.         ]);
  1338.     }
  1339.     
  1340.     /**
  1341.     * @Route("/{slug}/products", name="gestion.products")
  1342.      */
  1343.     public function productsAction(Boutique $boutique)
  1344.     {
  1345.         $em $this->getDoctrine()
  1346.                     ->getManager();
  1347.                     
  1348.         $products $em->getRePository(Produit::class)
  1349.                             ->findByBoutique($boutique);
  1350.          
  1351.          return $this->render('gestion/products.html.twig', [
  1352.             'products' => $products,
  1353.             'boutique' => $boutique
  1354.         ]);
  1355.     }
  1356.     
  1357.     /**
  1358.      * @Route("/{slug}/new-product", name="gestion.new_product")
  1359.      */
  1360.     public function newProductAction(Boutique $boutique)
  1361.     {
  1362.         $requestStack $this->get('request_stack');
  1363.         $request $requestStack->getCurrentRequest();
  1364.     
  1365.         $em $this->getDoctrine()
  1366.                     ->getManager();
  1367.         $ok_submission '';
  1368.         $error '';        
  1369.         $produit = new Produit;
  1370.         $form $this->createForm(ProduitType::class, $produit);
  1371.         $user $this->getUser();
  1372.         
  1373.                             
  1374.         if('POST' == $request->getMethod() )
  1375.         {
  1376.             $form->handleRequest($request);
  1377.             if( $form->isValid()){
  1378.                 $produit->setBoutique($boutique);
  1379.                 if(isset($_FILES['imagePrincipale']) && $_FILES['imagePrincipale']['error'] == 0){
  1380.                     //var_dump($_FILES['fichier']);
  1381.                     
  1382.                     $em->persist($produit);
  1383.                     $em->flush();
  1384.                     
  1385.                     $this->gererFichierMultiple($produit$_FILES['imagePrincipale'], true);
  1386.                     
  1387.                     $ok_submission 'Enregistrement effectué';
  1388.     
  1389.                 } else{
  1390.                     $error 'Veuillez indiquer l\'image principale';
  1391.                 }
  1392.                 
  1393.                 
  1394.                 if(isset($_FILES['photos']) && $_FILES['photos']['name'][0] != ''){
  1395.                         
  1396.                         $this->gererFichierMultiple($produit$_FILES['photos']);
  1397.                 }
  1398.                 $produit = new Produit;
  1399.                 $form $this->createForm(ProduitType::class, $produit);
  1400.                 
  1401.                 
  1402.             } else {
  1403.                 $form->getErrors(truefalse); 
  1404.                 $error 'Une erreur s\'est produite';
  1405.             }
  1406.         }
  1407.         return $this->render('gestion/new_product.html.twig', [
  1408.             'form' => $form->createView(),
  1409.             'error' => $error,
  1410.             'ok_submission' => $ok_submission,
  1411.             'boutique' => $boutique
  1412.         ]);
  1413.     }
  1414.     
  1415.     /**
  1416.      * @Route("/edit-main-image/{id}", name="gestion.edit_main_image")
  1417.      */
  1418.     public function editMainImageAction(Produit $produit)
  1419.     {
  1420.         $requestStack $this->get('request_stack');
  1421.         $request $requestStack->getCurrentRequest();
  1422.     
  1423.         $em $this->getDoctrine()
  1424.                     ->getManager();
  1425.         $ok_submission '';
  1426.         $error '';        
  1427.         $user $this->getUser();
  1428.         if('POST' == $request->getMethod()){
  1429.             $image $produit->getImagePrincipale();
  1430.             if(isset($_FILES['imagePrincipale']) && $_FILES['imagePrincipale']['error'] == 0){
  1431.                 $data $_FILES['imagePrincipale'];
  1432.                 $ex pathinfo($data['name'])['extension'];
  1433.                 $exA = array('jpg''jpeg''png''gif');
  1434.                 
  1435.                 if (in_array(strtolower($ex), $exA)){
  1436.                 
  1437.                     $image->setExtension($ex);
  1438.                 } else {
  1439.                     throw new \RuntimeException('Désolé, vous n\'avez pas le droit de télécharger ce type de fichier: '.$ex);
  1440.                 }
  1441.                 
  1442.                 $name $produit->getId().time().'.'.$ex;
  1443.                 //Delete old image
  1444.                 
  1445.                     unlink($image->getUploadRootDir().'/original/'.$image->getUrl());
  1446.                     if(!is_dir($image->getUploadRootDir().'/original/') && !mkdir($image->getUploadRootDir().'/original'0777true))
  1447.                     {
  1448.                         throw new \RuntimeException('Impossible de créer le dossier de destination');
  1449.                     }
  1450.                     
  1451.                     if (!move_uploaded_file($data['tmp_name'], $image->getUploadRootDir().'/original/'.$name))
  1452.                     {
  1453.                         throw new \RuntimeException('Désolé, une erreur s\'est produite.');
  1454.                     }
  1455.                     $image->setUrl($name);
  1456.                 } else{
  1457.                     $error 'Veuillez indiquer l\'image principale';
  1458.                 }
  1459.             
  1460.             $ok_submission 'Enregistrement effectué';
  1461.             $em->flush();
  1462.         }
  1463.         
  1464.         return $this->render('gestion/edit_main_image.html.twig', [
  1465.             'produit' => $produit,
  1466.             'error' => $error,
  1467.             'ok_submission' => $ok_submission
  1468.         ]);
  1469.     }
  1470.     
  1471.     
  1472.     
  1473.     /**
  1474.      * @Route("/delete-prodcut-image/{id}/{photo}", name="gestion.delete_product_image")
  1475.      */
  1476.     public function deleteProductImageAction(Produit $produit$photo)
  1477.     {
  1478.         
  1479.         $em $this->getDoctrine()
  1480.                     ->getManager();
  1481.         $photo $em->getRePository(ProductPhoto::class)
  1482.                     ->findOneById($photo);
  1483.         $em->remove($photo);    
  1484.         $link substr($photo->getUrl(), 32); //taille de https://www.lika.ci/uploads/img/
  1485.         
  1486.         unlink($photo->getUploadRootDir().'/'.$link);
  1487.         $em->flush();    
  1488.             
  1489.         return $this->redirectToRoute('gestion.products', array('slug' => $produit->getBoutique()->getSlug()));
  1490.                     
  1491.         
  1492.     }
  1493.     
  1494.     /**
  1495.      * @Route("/{slug}/add-more-image/{id}", name="gestion.add_more_image")
  1496.      */
  1497.     public function addMoreImageAction(Request $request,  $slug,  $id)
  1498.     {
  1499.         
  1500.         $em $this->getDoctrine()
  1501.                     ->getManager();
  1502.         $boutique $em->getRepository(Boutique::class)
  1503.                         ->findOneBySlug($slug);
  1504.         $produit $em->getRepository(Produit::class)
  1505.                         ->findOneById($id);
  1506.         $ok_submission '';
  1507.         $error '';        
  1508.         $user $this->getUser();
  1509.         
  1510.         if('POST' == $request->getMethod() )
  1511.         {
  1512.             if(isset($_FILES['photos'])){
  1513.                 $this->gererFichierMultiple($produit$_FILES['photos']);
  1514.                 $ok_submission 'Enregistrement effectué';
  1515.             }
  1516.             
  1517.         }
  1518.         
  1519.         return $this->render('gestion/add_more_image.html.twig', [
  1520.             'produit' => $produit,
  1521.             'error' => $error,
  1522.             'ok_submission' => $ok_submission,
  1523.             'boutique' => $boutique
  1524.         ]);
  1525.     }
  1526.     
  1527.     
  1528.     /**
  1529.      * @Route("/edit-product/{boutique}/{produit}", name="gestion.edit_product")
  1530.      */
  1531.     public function editProductAction($boutique$produit)
  1532.     {
  1533.         $requestStack $this->get('request_stack');
  1534.         $request $requestStack->getCurrentRequest();
  1535.     
  1536.         $em $this->getDoctrine()
  1537.                     ->getManager();
  1538.         $boutique $em->getRepository(Boutique::class)
  1539.                         ->findOneById($boutique);
  1540.         
  1541.         $produit $em->getRepository(Produit::class)
  1542.                         ->findOneById($produit);
  1543.         $ok_submission '';
  1544.         $error '';        
  1545.         $form $this->createForm(ProduitEditType::class, $produit);
  1546.         $user $this->getUser();
  1547.         if('POST' == $request->getMethod())
  1548.         {
  1549.             $form->handleRequest($request);
  1550.             if( $form->isValid()){
  1551.                 $em->flush();
  1552.                 $ok_submission 'Enregistrement effectué';
  1553.                 if(isset($_FILES['imagePrincipale']) && $_FILES['imagePrincipale']['error'] == 0){
  1554.                     //var_dump($_FILES['fichier']);
  1555.                     
  1556.                     $em->persist($produit);
  1557.                     $em->flush();
  1558.                     
  1559.                     $this->gererFichierMultiple($produit$_FILES['imagePrincipale'], true);
  1560.                     
  1561.                     $ok_submission 'Enregistrement effectué';
  1562.     
  1563.                 } 
  1564.                 
  1565.                 if(isset($_FILES['photos']) && $_FILES['photos']['name'][0] != ''){
  1566.                         
  1567.                         $this->gererFichierMultiple($produit$_FILES['photos']);
  1568.                 }
  1569.             } else {
  1570.                 $error 'Une erreur s\'est produite';
  1571.             }
  1572.         }
  1573.         return $this->render('gestion/edit_product.html.twig', [
  1574.             'form' => $form->createView(),
  1575.             'error' => $error,
  1576.             'ok_submission' => $ok_submission,
  1577.             'boutique' => $boutique
  1578.         ]);
  1579.     }        
  1580.     
  1581.     //Produit/Service
  1582.     /**
  1583.      * @Route("/{slug}/delete-product/{id}", name="gestion.delete_product")
  1584.      * @return \Symfony\Component\HttpFoundation\Response
  1585.      */
  1586.     public function deleteProductAction(Request $request,  $slug$id)
  1587.     { 
  1588.         $em $this->getDoctrine()
  1589.                     ->getManager();
  1590.         $boutique $em->getRepository(Boutique::class)
  1591.                         ->findOneBySlug($slug);
  1592.         
  1593.         $product $em->getRepository(Produit::class)
  1594.                         ->findOneBy(
  1595.                         array(
  1596.                             'boutique' => $boutique->getId(),
  1597.                             'id' => $id
  1598.                         )
  1599.                         );
  1600.         if(null !== $product){
  1601.             //les auttres images
  1602.             foreach($product->getPhotos() as $photo){
  1603.                 $link substr($photo->getUrl(), 32); //taille de https://www.lika.ci/uploads/img/
  1604.                 unlink($photo->getUploadRootDir().'/'.$link);
  1605.                 $em->remove($photo);
  1606.             }
  1607.             $em->flush();
  1608.             $em->remove($product);
  1609.             //Image principale
  1610.             if($product->getImagePrincipale() != null){
  1611.                 $link substr($product->getImagePrincipale()->getUrl(), 32); //taille de https://www.lika.ci/uploads/img/
  1612.                 unlink($product->getImagePrincipale()->getUploadRootDir().'/'.$link);
  1613.                 
  1614.                 $em->remove($product->getImagePrincipale());
  1615.             }
  1616.             
  1617.         
  1618.             $em->flush();
  1619.         }
  1620.         return $this->redirectToRoute('gestion.products', array('slug' => $boutique->getSlug()));
  1621.     
  1622.     }
  1623.     
  1624.     
  1625.     /**
  1626.      * @Route("/{slug}/proposals", name="gestion.proposals")
  1627.      * @return \Symfony\Component\HttpFoundation\Response
  1628.      */
  1629.     public function proposalsAction(Request $requestBoutique $boutique)
  1630.     {
  1631.               
  1632.         $em $this->getDoctrine()
  1633.                     ->getManager();
  1634.         
  1635.         $offreDevis $em->getRepository(OffreDevis::class)
  1636.                         ->findByBoutique($boutique);
  1637.                         
  1638.         $devis $em->getRepository(Devis::class)
  1639.                         ->findByCategorieEntreprise($boutique->getCategorieEntreprise());
  1640.         
  1641.         $user $this->getUser();
  1642.         $notifications $em->getRepository(Notification::class)
  1643.                                         ->findBy(
  1644.                                             array(
  1645.                                             'user' => $user,
  1646.                                             'vu'  => false,
  1647.                                             'typeNotification' => 'devis'
  1648.                                             )
  1649.                                         );
  1650.         foreach($notifications as $notification){
  1651.             $notification->setVu(true);
  1652.         }
  1653.         $em->flush();
  1654.         
  1655.         return $this->render('gestion/proposals.html.twig', [
  1656.            'offreDevis' => $offreDevis,
  1657.            'devis' => $devis,
  1658.            'boutique' => $boutique
  1659.         ]);
  1660.         
  1661.     }
  1662.     
  1663.     /**
  1664.      * @Route("/{slug}/my-tickets", name="gestion.my_tickets")
  1665.      */
  1666.     public function ticketsAction(Boutique $boutique)
  1667.     {
  1668.         $em $this->getDoctrine()->getManager();
  1669.         
  1670.         $tickets $em->getRepository(Ticket::class)
  1671.                         ->findByBoutique($boutique);
  1672.     
  1673.           return $this->render('gestion/tickets.html.twig', [
  1674.           'tickets' => $tickets,
  1675.           'boutique' => $boutique
  1676.         ]);
  1677.         
  1678.     }
  1679.     
  1680.     /**
  1681.      * @Route("/{slug}/new-ticket", name="gestion.new_ticket")
  1682.      * @return \Symfony\Component\HttpFoundation\Response
  1683.      */
  1684.     public function newTicketAction(Request $request$slug)
  1685.     {
  1686.         $em $this->getDoctrine()
  1687.                     ->getManager();
  1688.                     
  1689.         $boutique $em->getRepository(Boutique::class)
  1690.                         ->findOneBySlug($slug);
  1691.         $user $this->getUser();
  1692.         
  1693.         $ticket = new Ticket;
  1694.         
  1695.         $user $this->getUser();
  1696.         $userBoutique $em->getRepository(UserBoutique::class)
  1697.                         ->findOneBy(
  1698.                             array(
  1699.                             'user' => $user->getId(),
  1700.                             'boutique' => $boutique->getId()
  1701.                             )
  1702.                         );
  1703.         $form $this->createForm(TicketType::class, $ticket);
  1704.         
  1705.         $ok_soumission '';
  1706.         $error '';
  1707.         
  1708.         if($request->getMethod() == 'POST'){
  1709.             
  1710.                $form->handleRequest($request);
  1711.                if($form->isValid()){
  1712.                    $ticket->setBoutique($boutique);
  1713.                    $ticket->setUser($user);
  1714.                    
  1715.                   $em->persist($ticket);
  1716.                   $em->flush();
  1717.                   
  1718.                 return $this->redirectToRoute('gestion.display_ticket', array('slug' => $boutique->getSlug(), 'id' => $ticket->getId()));
  1719.                 $ok_soumission =" Votre message a été pris en compte";
  1720.                     
  1721.                 $ticket = new Ticket;
  1722.                 
  1723.                 $form $this->createForm(TicketType::class, $ticket);
  1724.                     
  1725.                 } else {
  1726.                     $error =" Veillez corrigez vos erreurs";
  1727.                 }
  1728.         }
  1729.         
  1730.         return $this->render('gestion/new_ticket.html.twig', [
  1731.            'boutique' => $boutique,
  1732.            'form' => $form->createView(),
  1733.            'userBoutique' => $userBoutique
  1734.         ]);
  1735.     }
  1736.     
  1737.     /**
  1738.      * @Route("/{slug}/display-ticket/{id}", name="gestion.display_ticket")
  1739.      * @return \Symfony\Component\HttpFoundation\Response
  1740.      */
  1741.     public function displayTicketAction(Request $request$slug$id)
  1742.     {
  1743.         $em $this->getDoctrine()
  1744.                     ->getManager();
  1745.                     
  1746.         $boutique $em->getRepository(Boutique::class)
  1747.                         ->findOneBySlug($slug);
  1748.         $user $this->getUser();
  1749.         $userBoutique $em->getRepository(UserBoutique::class)
  1750.                         ->findOneBy(
  1751.                             array(
  1752.                             'user' => $user->getId(),
  1753.                             'boutique' => $boutique->getId()
  1754.                             )
  1755.                         );
  1756.         
  1757.         $ticket $em->getRepository(Ticket::class)
  1758.                     ->findOneBy(
  1759.                         array(
  1760.                             'boutique' => $boutique->getId(),
  1761.                             'id' => $id
  1762.                         )
  1763.                     );
  1764.         $commentaires $em->getRepository(CommentaireTicket::class)
  1765.                             ->findByTicket($ticket->getId());
  1766.         $commentaireTicket = new CommentaireTicket;
  1767.         
  1768.         $user $this->getUser();
  1769.         $form $this->createForm(CommentaireTicketType::class, $commentaireTicket);
  1770.         
  1771.         $ok_soumission '';
  1772.         $error '';
  1773.         
  1774.         if($request->getMethod() == 'POST'){
  1775.             
  1776.                $form->handleRequest($request);
  1777.                if($form->isValid()){
  1778.                    
  1779.                    $commentaireTicket->setTicket($ticket);
  1780.                    $commentaireTicket->setUser($user);
  1781.                    
  1782.                   $em->persist($commentaireTicket);
  1783.                   $em->flush();
  1784.                 
  1785.                 $commentaires $em->getRepository(CommentaireTicket::class)
  1786.                             ->findByTicket($ticket->getId());
  1787.                 $ok_soumission =" Votre message a été pris en compte";
  1788.                     
  1789.                 $commentaireTicket = new CommentaireTicket;
  1790.                 
  1791.                 
  1792.                 $form $this->createForm(CommentaireTicketType::class, $commentaireTicket);
  1793.                     
  1794.                 } else {
  1795.                     $error =" Veillez corrigez vos erreurs";
  1796.                 }
  1797.         }
  1798.         
  1799.         return $this->render('gestion/display_ticket.html.twig', [
  1800.            'boutique' => $boutique,
  1801.            'ticket' => $ticket,
  1802.            'form' => $form->createView(),
  1803.            'commentaires' => $commentaires,
  1804.            'userBoutique' => $userBoutique
  1805.         ]);
  1806.     }
  1807.     
  1808.     /**
  1809.      * @Route("/{slug}/close-ticket/{id}", name="gestion.close_ticket")
  1810.      * @return \Symfony\Component\HttpFoundation\Response
  1811.      */
  1812.     public function closeTicketAction(Request $request$slug$id)
  1813.     {
  1814.         $em $this->getDoctrine()
  1815.                     ->getManager();
  1816.                     
  1817.         $boutique $em->getRepository(Boutique::class)
  1818.                         ->findOneBySlug($slug);
  1819.         
  1820.         $ticket $em->getRepository(Ticket::class)
  1821.                     ->findOneBy(
  1822.                         array(
  1823.                             'boutique' => $boutique->getId(),
  1824.                             'id' => $id
  1825.                         )
  1826.                     );
  1827.         
  1828.         if(null !== $ticket){
  1829.             $ticket->setLesCommentairesSontFermes(true);
  1830.             $em->flush();
  1831.         }
  1832.         
  1833.         return $this->redirectToRoute('gestion.display_ticket',array('slug'=>$boutique->getSlug(), 'id'=>$ticket->getId()));
  1834.     }
  1835.     
  1836.     
  1837.     /**
  1838.      * @Route("/{slug}/delete-ticket/{id}", name="gestion.delete_ticket")
  1839.      * @return \Symfony\Component\HttpFoundation\Response
  1840.      */
  1841.     public function deleteTicketAction(Request $request$slug$id)
  1842.     {
  1843.         $em $this->getDoctrine()
  1844.                     ->getManager();
  1845.                     
  1846.         $boutique $em->getRepository(Boutique::class)
  1847.                         ->findOneBySlug($slug);
  1848.         $user $this->getUser();
  1849.         
  1850.         
  1851.         $ok_soumission '';
  1852.         $error '';
  1853.         
  1854.         $ticket $em->getRepository(Ticket::class)
  1855.                     ->findOneBy(
  1856.                         array(
  1857.                             'boutique' => $boutique->getId(),
  1858.                             'id' => $id
  1859.                         )
  1860.                     );
  1861.         if(null !== $ticket){
  1862.             $commentaireTickets $em->getRepository(CommentaireTicket::class)
  1863.                                     ->findByTicket($ticket->getId());
  1864.             foreach($commentaireTickets as $commentaireTicket)
  1865.             {
  1866.                 $em->remove($commentaireTicket);
  1867.             }
  1868.             $em->remove($ticket);
  1869.             $em->flush();
  1870.         }
  1871.         
  1872.         return $this->redirectToRoute('gestion.tickets',array('slug'=>$boutique->getSlug(), 'id'=>$user->getId()));
  1873.     }
  1874.     
  1875.     
  1876.     /**
  1877.      * @Route("/{slug}/delete-commentaire-ticket/{id}", name="gestion.delete_commentaire_ticket")
  1878.      * @return \Symfony\Component\HttpFoundation\Response
  1879.      */
  1880.     public function deleteCommentaireTicketAction(Request $request$slug$id)
  1881.     {
  1882.         $em $this->getDoctrine()
  1883.                     ->getManager();
  1884.                     
  1885.         $boutique $em->getRepository(Boutique::class)
  1886.                         ->findOneBySlug($slug);
  1887.         $user $this->getUser();
  1888.     
  1889.         $commentaireTicket $em->getRepository(CommentaireTicket::class)
  1890.                     ->findOneById($id);
  1891.                     
  1892.         if(null !== $commentaireTicket){
  1893.             
  1894.             $em->remove($commentaireTicket);
  1895.             $em->flush();
  1896.         }
  1897.         
  1898.         return $this->redirectToRoute('gestion.tickets',array('slug'=>$boutique->getSlug(), 'id'=>$user->getId()));
  1899.     }
  1900.     
  1901.     /**
  1902.      * @Route("/{slug}/reviews", name="gestion.reviews")
  1903.      */
  1904.     public function reviewsAction(Boutique $boutique)
  1905.     {
  1906.         $em $this->getDoctrine()->getManager();
  1907.         $user $this->getUser();
  1908.         $reviews $em->getRepository(AvisUtilisateur::class)
  1909.                         ->findByBoutique($boutique);
  1910.         $notifications $em->getRepository(Notification::class)
  1911.                                         ->findBy(
  1912.                                             array(
  1913.                                             'user' => $user,
  1914.                                             'vu'  => false,
  1915.                                             'typeNotification' => 'avis'
  1916.                                             )
  1917.                                         );
  1918.         foreach($notifications as $notification){
  1919.             $notification->setVu(true);
  1920.         }
  1921.         $em->flush();
  1922.           return $this->render('gestion/reviews.html.twig', [
  1923.           'reviews' => $reviews,
  1924.           'boutique' => $boutique
  1925.         ]);
  1926.         
  1927.     }
  1928.     
  1929.     /**
  1930.      * @Route("/{id}/delete-review", name="gestion.delete_review")
  1931.      */
  1932.     public function deleteReviewAction(AvisUtilisateur $review)
  1933.     {
  1934.         $em $this->getDoctrine()->getManager();
  1935.         $slug $review->getBoutique()->getSlug();
  1936.         $em->remove($review);
  1937.         $em->flush();
  1938.         
  1939.         return $this->redirectToRoute('gestion.reviews', array('slug' => $slug));
  1940.     }
  1941.     
  1942.     /**
  1943.      * @Route("/{id}/reply-review", name="gestion.reply_review")
  1944.      */
  1945.     public function replyReviewAction(Request $requestAvisUtilisateur $review)
  1946.     {
  1947.         $em $this->getDoctrine()->getManager();
  1948.         
  1949.         if($request->getMethod() == 'POST'){
  1950.             $reponseAvis $request->request->get('reponseAvis');
  1951.             $review->setReponseAvis($reponseAvis);
  1952.             $em->flush();
  1953.             
  1954.             $slug $review->getBoutique()->getSlug();
  1955.             return $this->redirectToRoute('gestion.reviews', array('slug' => $slug));
  1956.         }
  1957.     
  1958.           return $this->render('gestion/reply_review.html.twig', [
  1959.           'review' => $review,
  1960.           'boutique' => $review->getBoutique()
  1961.         ]);
  1962.         
  1963.     }
  1964.     
  1965.     /**
  1966.      * @Route("/{slug}/messages", name="gestion.messages")
  1967.      */
  1968.     public function messagesAction(Boutique $boutique)
  1969.     {
  1970.         $em $this->getDoctrine()->getManager();
  1971.         
  1972.         $conversations $em->getRepository(Conversation::class)
  1973.                         ->findByBoutique($boutique);
  1974.         $user $this->getUser();
  1975.         
  1976.         
  1977.     
  1978.         return $this->render('gestion/messages.html.twig', [
  1979.           'conversations' => $conversations,
  1980.           'boutique' => $boutique
  1981.         ]);
  1982.         
  1983.     }
  1984.     
  1985.     /**
  1986.      * @Route("/{slug}/{id}/conversation", name="gestion.one_conversation")
  1987.      */
  1988.     public function oneConversationAction(Request $request$slug$id)
  1989.     {
  1990.         $em $this->getDoctrine()->getManager();
  1991.         
  1992.         $boutique $em->getRepository(Boutique::class)
  1993.                         ->findOneBySlug($slug);
  1994.         $user $this->getUser();                
  1995.         $notifications $em->getRepository(Notification::class)
  1996.                                         ->findBy(
  1997.                                             array(
  1998.                                             'user' => $user,
  1999.                                             'vu'  => false,
  2000.                                             'typeNotification' => 'message',
  2001.                                             'extraData' => $id
  2002.                                             )
  2003.                                         );
  2004.         foreach($notifications as $notification){
  2005.             $notification->setVu(true);
  2006.         }
  2007.         $em->flush();
  2008.         
  2009.         $conversation $em->getRepository(Conversation::class)
  2010.                         ->findOneById($id);
  2011.                         
  2012.         if($request->getMethod() == 'POST'){
  2013.             $reponseMessage $request->request->get('reponseMessage');
  2014.             
  2015.             $message = new Message;
  2016.             $message->setContenu($reponseMessage);
  2017.             $message->setConversation($conversation);
  2018.             $em->persist($message);
  2019.             $em->flush();
  2020.             
  2021.             $notification = new Notification;
  2022.             $notification->setUser($conversation->getUser());
  2023.             $lien =  $this->generateUrl('profile.one_conversation', array('slug'=>$conversation->getBoutique()->getSlug(), 'id' => $conversation->getId()));
  2024.             $notification->setExtraData($conversation->getId());
  2025.             $notification->setLien($lien);
  2026.             $notification->setTypeNotification('message');
  2027.             $notification->setDescription('Vous avez un nouveau message');
  2028.             
  2029.             $conversation->setLastMessage($reponseMessage);
  2030.         
  2031.             $em->persist($notification);
  2032.             $em->flush();    
  2033.             
  2034.         }
  2035.         
  2036.         $messages $em->getRepository(Message::class)
  2037.                     ->findBy(
  2038.                         array(
  2039.                             'conversation' => $conversation
  2040.                         )
  2041.             );
  2042.     
  2043.           return $this->render('gestion/one_conversation.html.twig', [
  2044.           'conversation' => $conversation,
  2045.           'boutique' => $boutique,
  2046.           'messages' => $messages
  2047.         ]);
  2048.     }
  2049.     
  2050.     /**
  2051.      * @Route("/notification-to-join-team/{email}", name="notification_requette_ajout_boutique")
  2052.      * @return \Symfony\Component\HttpFoundation\Response
  2053.      */
  2054.     public function notificationRequetteAjoutBoutiqueAction(Request $request,  $email)
  2055.     {
  2056.               
  2057.         $em $this->getDoctrine()
  2058.                     ->getManager();
  2059.         
  2060.             
  2061.         $requeteBoutiques $em->getRepository(RequeteAjoutBoutique::class)
  2062.                         ->findBy(
  2063.                             array(
  2064.                                 'email' => $email
  2065.                             )
  2066.                             );
  2067.                             
  2068.         $nbRequete count($requeteBoutiques);
  2069.         
  2070.         return $this->render('entreprise/notification_requette_ajout_boutique.html.twig', [
  2071.            'nbRequete' => $nbRequete
  2072.         ]);
  2073.         
  2074.     }
  2075.     
  2076.     /**
  2077.      * @Route("/request-to-join-team/{email}", name="afficher_requette_ajout_boutique")
  2078.      * @return \Symfony\Component\HttpFoundation\Response
  2079.      */
  2080.     public function afficherRequetteAjoutBoutiqueAction(Request $request,  $email)
  2081.     {
  2082.               
  2083.         $em $this->getDoctrine()
  2084.                     ->getManager();
  2085.             
  2086.         $requeteBoutiques $em->getRepository(RequeteAjoutBoutique::class)
  2087.                         ->findByEmail($email);
  2088.                         
  2089.         foreach($requeteBoutiques as $requeteBoutique){
  2090.             $requeteBoutique->setVu(true);
  2091.         }
  2092.         
  2093.         $em->flush();
  2094.         
  2095.         return $this->render('entreprise/afficher_requette_ajout_boutique.html.twig', [
  2096.            'requeteBoutiques' => $requeteBoutiques
  2097.         ]);
  2098.         
  2099.     }
  2100.     
  2101.     /**
  2102.      * @Route("/respond-request-to-join-team/{id}/{status}", name="repondre_requette_ajout_boutique")
  2103.      * @return \Symfony\Component\HttpFoundation\Response
  2104.      */
  2105.     public function repondreRequetteAjoutBoutiqueAction(Request $request,  $id$status)
  2106.     {
  2107.               
  2108.         $em $this->getDoctrine()
  2109.                     ->getManager();
  2110.             
  2111.         $requeteAjout $em->getRepository(RequeteAjoutBoutique::class)
  2112.                         ->findOneById($id);
  2113.         $user $this->getUser();    
  2114.         if($status){
  2115.             $userBoutique $em->getRepository(UserBoutique::class)
  2116.                                 ->findOneBy(
  2117.                                     array(
  2118.                                         'user' => $user->getId(),
  2119.                                         'boutique' => $requeteAjout->getBoutique()->getId()
  2120.                                     )
  2121.                                 );
  2122.             if(null === $userBoutique){
  2123.                 $userBoutique = new UserBoutique;
  2124.                 $userBoutique->setUser($user);
  2125.                 $userBoutique->setBoutique($requeteAjout->getBoutique());
  2126.                 $userBoutique->setRole($requeteAjout->getRole());
  2127.                 $em->persist($userBoutique);
  2128.             }
  2129.         } 
  2130.         $em->remove($requeteAjout);
  2131.         $em->flush();
  2132.         
  2133.         return $this->redirectToRoute('home');
  2134.         
  2135.     }
  2136.     
  2137.     public function getDomain()
  2138.     {
  2139.         $domaine $_SERVER['HTTP_HOST'];
  2140.         $protocol '';
  2141.         if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'){
  2142.             $protocol 'https://';
  2143.         } else{
  2144.             $protocol 'http://';
  2145.         }
  2146.         
  2147.         return $protocol.$domaine;
  2148.     }
  2149.     
  2150.         public function gererFichierMultipleLogo(\App\Entity\Boutique $boutique$data)
  2151.         {
  2152.             
  2153.             $ex pathinfo($data['name'])['extension'];
  2154.             $exA = array('jpg''jpeg''png''gif''svg');
  2155.             
  2156.             if (!in_array(strtolower($ex), $exA)){
  2157.                 throw new \RuntimeException('Désolé, vous n\'avez pas le droit de télécharger ce type de fichier: '.$ex);
  2158.             }
  2159.             
  2160.             $name $boutique->getId().time();
  2161.             $namePourRepertoire $name;
  2162.             //hydratation des attributs de l'objet
  2163.             
  2164.             $domaine $_SERVER['HTTP_HOST'];
  2165.             $protocol '';
  2166.             if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'){
  2167.                 $protocol 'https://';
  2168.             } else{
  2169.                 $protocol 'http://';
  2170.             }
  2171.             $url $protocol.$domaine.'/uploads/img/logo/'.$name.'.'.$ex;
  2172.             $boutique->getLogo()->setUrl($url);
  2173.             $boutique->getLogo()->setAlt('Logo '.$boutique->getNom());
  2174.             
  2175.             //deplacement (création de l'image original)
  2176.             //$this->file->move($photo->getUploadRootDir().'/original/', $name.'.'.photo->getExtension()));
  2177.             
  2178.             
  2179.             if(!is_dir($boutique->getLogo()->getUploadRootDir().'/featured/') && !mkdir($boutique->getLogo()->getUploadRootDir().'/featured'0777true))
  2180.             {
  2181.                 throw new \RuntimeException('Impossible de créer le dossier de destination');
  2182.             }
  2183.             
  2184.             if (!move_uploaded_file($data['tmp_name'], $boutique->getLogo()->getUploadRootDir().'/featured/'.$name.'.'.$ex))
  2185.             {
  2186.                 throw new \RuntimeException('Désolé, une erreur s\'est produite.');
  2187.             }
  2188.                     
  2189.         $name $boutique->getLogo()->getUploadRootDir().'/featured/'.$name.'.'.$ex;
  2190.         $extension strtolower($ex);
  2191.             try{
  2192.                         $nvlleImgMenu = ( $extension =='jpg' || $extension == 'jpeg') ? imagecreatefromjpeg($name) : imagecreatefrompng($name);
  2193.                         
  2194.                         $miniatureMenu imagecreatetruecolor(4848);
  2195.                         
  2196.                         $largeurNvlleImgMenu imagesx($nvlleImgMenu);
  2197.                         $hauteurNvlleImgMenu imagesy($nvlleImgMenu);
  2198.                         $largeurMiniatureMenu imagesx($miniatureMenu);
  2199.                         $hauteurMiniatureMenu imagesy($miniatureMenu);
  2200.                         
  2201.                         //fusion et generation des miniatures
  2202.                         
  2203.                         imagecopyresampled($miniatureMenu$nvlleImgMenu0000$largeurMiniatureMenu$hauteurMiniatureMenu,
  2204.                                    $largeurNvlleImgMenu$hauteurNvlleImgMenu);
  2205.                         
  2206.                         //deplacer les nouvelles images(miniatures) dans les repertoires correspondants
  2207.                         
  2208.                         if(!is_dir($boutique->getLogo()->getUploadRootDir().'/logo/') && !mkdir($boutique->getLogo()->getUploadRootDir().'/logo/'0777true)){
  2209.                             throw \RuntimeException('Impossible de créer le dossier de destination');
  2210.                         }
  2211.                         $name $boutique->getLogo()->getUploadRootDir().'/logo/'.$namePourRepertoire.'.'.$extension;
  2212.                         if($extension == 'jpg' || $extension == 'jpeg'){
  2213.                             imagejpeg($miniatureMenu$name90);
  2214.                         } else{
  2215.                             imagepng($miniatureMenu$name9);
  2216.                         }
  2217.                         $fromSecure 'http://';
  2218.                         if( isset($_SERVER['HTTPS'] ) ){
  2219.                             $fromSecure 'https://';
  2220.                         }
  2221.                         $boutique->getLogo()->setUrl($fromSecure.$_SERVER['HTTP_HOST'].'/uploads/img/logo/'.$namePourRepertoire.'.'.$extension);
  2222.                     
  2223.                         //
  2224.                     } catch(Exception $e){
  2225.                     }
  2226.                     
  2227.         
  2228.         
  2229.         $this->getDoctrine()->getManager()->flush();
  2230.         
  2231.     }
  2232.     
  2233.     public function gererFichierMultiple(\App\Entity\Produit $produit$data$imagePrincipale false)
  2234.     {
  2235.         $nbFichier 0
  2236.         
  2237.         if($imagePrincipale){
  2238.             
  2239.                 $photo = new ProductPhoto;
  2240.                 $photo->setFile($data);
  2241.                 
  2242.                 $produit->setImagePrincipale($photo);
  2243.                 
  2244.                 $ex pathinfo($data['name'])['extension'];
  2245.                 $exA = array('jpg''jpeg''png''gif');
  2246.                 
  2247.                 if (in_array(strtolower($ex), $exA)){
  2248.                 
  2249.                     $photo->setExtension($ex);
  2250.                 } else {
  2251.                     throw new \RuntimeException('Désolé, vous n\'avez pas le droit de télécharger ce type de fichier: '.$ex);
  2252.                 }
  2253.                 
  2254.                 $name $produit->getId().time();
  2255.                 $namePourRepertoire $name;
  2256.                 //hydratation des attributs de l'objet
  2257.                 $photo->setUrl($name.'.'.$photo->getExtension());
  2258.                 $photo->setAlt('Image de '.$produit->getNom());
  2259.                 $extension $photo->getExtension();
  2260.                 //deplacement (création de l'image original)
  2261.                 //$this->file->move($photo->getUploadRootDir().'/original/', $name.'.'.photo->getExtension()));
  2262.                 
  2263.                 
  2264.                 if(!is_dir($photo->getUploadRootDir().'/original/') && !mkdir($photo->getUploadRootDir().'/original'0777true))
  2265.                 {
  2266.                     throw new \RuntimeException('Impossible de créer le dossier de destination');
  2267.                 }
  2268.                 
  2269.                 if (!move_uploaded_file($data['tmp_name'], $photo->getUploadRootDir().'/original/'.$name.'.'.$photo->getExtension()))
  2270.                 {
  2271.                     throw new \RuntimeException('Désolé, une erreur s\'est produite.');
  2272.                 }
  2273.                 try{
  2274.                     $name $photo->getUploadRootDir().'/original/'.$name.'.'.$photo->getExtension();
  2275.                         $nvlleImgMenu = ( $ex =='jpg' || $ex == 'jpeg') ? imagecreatefromjpeg($name) : imagecreatefrompng($name);
  2276.                         
  2277.                         $miniatureMenu imagecreatetruecolor(600600);
  2278.                         
  2279.                         $largeurNvlleImgMenu imagesx($nvlleImgMenu);
  2280.                         $hauteurNvlleImgMenu imagesy($nvlleImgMenu);
  2281.                         $largeurMiniatureMenu imagesx($miniatureMenu);
  2282.                         $hauteurMiniatureMenu imagesy($miniatureMenu);
  2283.                         
  2284.                         //fusion et generation des miniatures
  2285.                         
  2286.                         imagecopyresampled($miniatureMenu$nvlleImgMenu0000$largeurMiniatureMenu$hauteurMiniatureMenu,
  2287.                                    $largeurNvlleImgMenu$hauteurNvlleImgMenu);
  2288.                         
  2289.                         //deplacer les nouvelles images(miniatures) dans les repertoires correspondants
  2290.                         
  2291.                         if(!is_dir($photo->getUploadRootDir().'/featured/') && !mkdir($photo->getUploadRootDir().'/featured/'0777true)){
  2292.                             throw \RuntimeException('Impossible de créer le dossier de destination');
  2293.                         }
  2294.                         $name $photo->getUploadRootDir().'/featured/'.$photo->getUrl();
  2295.                         if($extension == 'jpg' || $extension == 'jpeg'){
  2296.                             imagejpeg($miniatureMenu$name85);
  2297.                         } else{
  2298.                             imagepng($miniatureMenu$name8);
  2299.                         }
  2300.                         $fromSecure 'http://';
  2301.                         if( isset($_SERVER['HTTPS'] ) ){
  2302.                             $fromSecure 'https://';
  2303.                         }
  2304.                         $photo->setUrl($fromSecure.$_SERVER['HTTP_HOST'].'/'.$photo->getUploadDir().'/featured/'.$photo->getUrl());
  2305.                     
  2306.                         //
  2307.                     } catch(Exception $e){
  2308.                     }
  2309.                 $this->getDoctrine()->getManager()->persist($photo);                
  2310.         } else{
  2311.             $tableauFichier $this->reArrayFiles($data);
  2312.             //var_dump($tableauFichier);
  2313.             $i 0;
  2314.             foreach ($tableauFichier as $file)
  2315.             {
  2316.                 $i++;
  2317.             //print 'File Name: ' . $file['name'];
  2318.             //print 'File Type: ' . $file['type'];
  2319.             //print 'File Size: ' . $file['size'];
  2320.         
  2321.             
  2322.                 $photo = new ProductPhoto;
  2323.                 $photo->setFile($file);
  2324.                 
  2325.                 
  2326.                 
  2327.                 $ex pathinfo($file['name'])['extension'];
  2328.                 $exA = array('jpg''jpeg''png''gif');
  2329.                 
  2330.                 if (in_array(strtolower($ex), $exA)){
  2331.                 
  2332.                     $photo->setExtension($ex);
  2333.                 } else {
  2334.                     throw new \RuntimeException('Désolé, vous n\'avez pas le droit de télécharger ce type de fichier: '.$ex);
  2335.                 }
  2336.                 
  2337.                 $name $produit->getId().$i.time();
  2338.                 $namePourRepertoire $name;
  2339.                 //hydratation des attributs de l'objet
  2340.                 $photo->setUrl($name.'.'.$photo->getExtension());
  2341.                 $photo->setAlt('Image de '.$produit->getNom());
  2342.                 $fromSecure 'http://';
  2343.                         if( isset($_SERVER['HTTPS'] ) ){
  2344.                             $fromSecure 'https://';
  2345.                         }
  2346.                 $photo->setUrl($fromSecure.$_SERVER['HTTP_HOST'].'/'.$photo->getUploadDir().'/original/'.$photo->getUrl());
  2347.                     
  2348.                 //deplacement (création de l'image original)
  2349.                 //$this->file->move($photo->getUploadRootDir().'/original/', $name.'.'.photo->getExtension()));
  2350.                 
  2351.                 $produit->addPhoto($photo);
  2352.                 if(!is_dir($photo->getUploadRootDir().'/original/') && !mkdir($photo->getUploadRootDir().'/original'0777true))
  2353.                 {
  2354.                     throw new \RuntimeException('Impossible de créer le dossier de destination');
  2355.                 }
  2356.                 
  2357.                 if (!move_uploaded_file($file['tmp_name'], $photo->getUploadRootDir().'/original/'.$name.'.'.$photo->getExtension()))
  2358.                 {
  2359.                     throw new \RuntimeException('Désolé, une erreur s\'est produite.');
  2360.                 }
  2361.                 $this->getDoctrine()->getManager()->persist($photo);
  2362.         }
  2363.         }
  2364.         
  2365.         $this->getDoctrine()->getManager()->flush();
  2366.         
  2367.     }
  2368.     
  2369.     public function reArrayFiles($file_post)
  2370.     {
  2371.         $file_ary = array();
  2372.         $file_count count($file_post['name']);
  2373.         $file_keys array_keys($file_post);
  2374.         for ($i=0$i<$file_count$i++)
  2375.         {
  2376.             foreach ($file_keys as $key)
  2377.             {
  2378.                 $file_ary[$i][$key] = $file_post[$key][$i];
  2379.             }
  2380.         }
  2381.         return $file_ary;
  2382.     }
  2383.     
  2384.     public function allowRemoteRequest($response)
  2385.     {
  2386.         
  2387.         $response->headers->set('Access-Control-Allow-Origin''*');
  2388.         $response->headers->set('Content-Type''application/json;');
  2389.         $response->headers->set('Access-Control-Allow-Headers''Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Allow-Origin,Authorization,Access-Control-Request-Headers');
  2390.         
  2391.         //$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
  2392.         //$response->headers->set('Access-Control-Allow-Headers', 'Origin, Accept, Access-Control-Allow-Origin, Content-Type, X-Auth-Token');
  2393.         //$response->headers->set('Access-Control-Allow-Headers', 'Content-Type');
  2394.         
  2395.         //$response->headers->set('Access-Control-Allow-Credentials', true);
  2396.         //$response->headers->set('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Authorization,Access-Control-Request-Headers');
  2397.         //$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
  2398.         
  2399.         //header("Access-Control-Allow-Headers: 'Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Allow-Origin,Authorization,Access-Control-Request-Headers'");
  2400.         return $response;
  2401.     }
  2402.     
  2403. }