src/Controller/FrontController.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Categorie;
  4. use App\Entity\Subcategorie;
  5. use App\Entity\Products;
  6. use App\Entity\CustomerVotes;
  7. use App\Entity\Complaint;
  8. use App\Entity\Province;
  9. use App\Service\FileUploader;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. class FrontController extends AbstractController
  16. {
  17.     private $requestStack;
  18.     public function __construct(RequestStack $requestStack)
  19.     {
  20.         $this->requestStack $requestStack;
  21.     }
  22.     /**
  23.      * @Route("/switch_lang/{lang}/{page}", name="app_switch_lang")
  24.      */
  25.     public function switch_lang($lang,$page)
  26.     {
  27.         if($lang == 1){
  28.             $session $this->requestStack->getSession();
  29.             $session->set('lang''english');
  30.         }else{
  31.             $session $this->requestStack->getSession();
  32.             $session->set('lang''french');
  33.         }
  34.         return $this->redirect($_SERVER['HTTP_REFERER']); 
  35.     }  
  36.     /**
  37.      * @Route("/", name="app_front")
  38.      */
  39.     public function index(Request $request,RequestStack $requestStack): Response
  40.     {
  41.         $session $this->requestStack->getSession();
  42.         $language $session->get('lang');
  43.         if($language == 'english'){
  44.             $pageContent=["all_product"=>"All Products",
  45.                           "product_campaign"=>"Product Campaign",
  46.                           "home"=>"Home",
  47.                           "search"=>"Search",
  48.                           "privacy_policy"=>"Privacy Policy",
  49.                           "filterproducts"=>"Filter Products",
  50.                           "filters"=>"Filters",
  51.                           "category"=>"Category",
  52.                           "subcategory"=>"Sub-Category",
  53.                           "submit"=>"Submit",
  54.                           "back"=>"Back",
  55.                           "productdetails"=>"Product Details",
  56.                           "productname"=>"Product Name",
  57.                           "wholesaleprice"=>"Wholesale Price",
  58.                           "retailprice"=>"Retail Price",
  59.                           "semiretailprice"=>"Semi Retail Price",
  60.                           "description"=>"Description",
  61.                           "markcomplaint"=>"Mark Complaint",
  62.                           "shopkeepername"=>"Shopkeeper Name",
  63.                           "entershopkeepername"=>"Enter Shopkeeper Name",
  64.                           "shopkeeperaddress"=>"Shopkeeper's Address",
  65.                           "entershopkeeperaddress"=>"Enter Shopkeeper's Address*",
  66.                           "zipcode"=>"Zipcode",
  67.                           "enterzipcode"=>"Enter Zipcode",
  68.                           "province"=>"Province",
  69.                           "selectprovince"=>"Select Province",
  70.                           "selectcity"=>"Select City",
  71.                           "city"=>"City",
  72.                           "image"=>"Add Entrance Image",
  73.                           "placeholdimage"=>"Upload or capture image",
  74.                           "remark"=>"Remark",
  75.                           "enterremark"=>"Enter Remark",
  76.                           "submitcomplaint"=>"Submit Complaint",
  77.             ];
  78.         }else{
  79.             $pageContent=["all_product"=>"Tous les produits",
  80.                           "product_campaign"=>"Campagne produit",
  81.                           "home"=>"Accueil",
  82.                           "search"=>"Chercher",
  83.                           "privacy_policy"=>"Politique de confidentialité",
  84.                           "filterproducts"=>"Filtrer les produits",
  85.                           "filters"=>"Filtres",
  86.                           "category"=>"Catégorie",
  87.                           "subcategory"=>"Sous-catégorie",
  88.                           "submit"=>"Enregistrer",
  89.                           "back"=>"Retour",
  90.                           "productdetails"=>"Détails du produit",
  91.                           "productname"=>"Nom du produit",
  92.                           "wholesaleprice"=>"Prix de gros",
  93.                           "retailprice"=>"Prix en détail",
  94.                           "semiretailprice"=>"Prix semi-grossiste",
  95.                           "description"=>"La description",
  96.                           "markcomplaint"=>"Denoncer",
  97.                           "shopkeepername"=>"Nom du commerçant",
  98.                           "entershopkeepername"=>"Entrer le nom du commerçant",
  99.                           "shopkeeperaddress"=>"Adresse du commerçant",
  100.                           "entershopkeeperaddress"=>"Entrer l'adresse du commerçant",
  101.                           "zipcode"=>"Code postal",
  102.                           "enterzipcode"=>"Entrer le code postal",
  103.                           "province"=>"Province",
  104.                           "city"=>"Ville",
  105.                           "selectprovince"=>"Sélectionnez une province",
  106.                           "selectcity"=>"Sélectionnez une ville",
  107.                           "image"=>"Ajouter une image d'entrée",
  108.                           "placeholdimage"=>"Télécharger ou capturer une image",
  109.                           "remark"=>"Remarque",
  110.                           "enterremark"=>"Entrez une remarque",
  111.                           "submitcomplaint"=>"Soumettre une plainte",
  112.             ];
  113.         }  
  114.         // dd($pageContent);
  115.         $input=$request->request->all();
  116.         if (!empty($input)) {
  117.             if(!empty($input['category'])  && empty($input['subcategory'])){
  118.                 $category=$input['category'];
  119.                 $products $this->getDoctrine()->getRepository('App\Entity\Products')->findOneBySomeField($category)->findBy(
  120.                         array('status'=>true));
  121.             }elseif(!empty($input['category']) && !empty($input['subcategory'])){
  122.                 $category=$input['category'];
  123.                 $subcategory=$input['subcategory'];
  124.                 $products $this->getDoctrine()->getRepository('App\Entity\Products')->findOneByCatSubcatField($category,$subcategory);
  125.             }else{
  126.             $products $this->getDoctrine()->getRepository('App\Entity\Products')->findBy(
  127.                         array('status'=>true),
  128.                         array('id'=>'desc'),);
  129.             }
  130.         }else{
  131.             $products $this->getDoctrine()->getRepository('App\Entity\Products')->findBy(
  132.                         array('status'=>true),
  133.                         array('id'=>'desc'),);
  134.         }
  135.         $citys $this->getDoctrine()->getRepository('App\Entity\City')->findBy(
  136.             array(),
  137.             array('name'=>'asc'),
  138.         );
  139.         $province $this->getDoctrine()->getRepository('App\Entity\Province')->findBy(
  140.             array(),
  141.             array('name'=>'asc'),
  142.         );
  143.         $categorie $this->getDoctrine()->getRepository(Categorie::class)->findBy(array(),array('id'=>'desc'));
  144.         $subcategorie $this->getDoctrine()->getRepository(Subcategorie::class)->findBy(array('status'=>'1')); 
  145.         return $this->render('front/index.html.twig', [
  146.             'products'=>$products,
  147.             'category'=>$categorie,
  148.             'subcategory'=>$subcategorie,  
  149.             'citys'=>$citys,  
  150.             'province'=>$province,  
  151.             'pageContent'=>$pageContent,  
  152.             'language'=>$language,  
  153.         ]);
  154.     }
  155.     /**
  156.      * @Route("/product-campaign", name="app_product_campaign")
  157.      */
  158.     public function product_campaign(RequestStack $requestStack): Response
  159.     {
  160.         $session $this->requestStack->getSession();
  161.         $language $session->get('lang');
  162.         if($language == 'english'){
  163.             $pageContent=["all_product"=>"All Products",
  164.                           "product_campaign"=>"Product Campaign",
  165.                           "home"=>"Home",
  166.                           "search"=>"Search",
  167.                           "privacy_policy"=>"Privacy Policy",
  168.                           "voteforproduct"=>"Vote for Product",
  169.             ];
  170.         }else{
  171.             $pageContent=["all_product"=>"Tous les produits",
  172.                           "product_campaign"=>"Campagne produit",
  173.                           "home"=>"Accueil",
  174.                           "search"=>"Chercher",
  175.                           "privacy_policy"=>"Politique de confidentialité",
  176.                           "voteforproduct"=>"Votez pour le produit",
  177.             ];
  178.         }  
  179.         $campaign $this->getDoctrine()->getRepository('App\Entity\Campaign')->findByExampleField();
  180.         return $this->render('front/compaign.html.twig', [
  181.             'campaign'=>$campaign
  182.             'pageContent'=>$pageContent
  183.             'language'=>$language
  184.         ]);
  185.     }
  186.     /**
  187.      * @Route("/privacy-policy", name="app_privacy_policy")
  188.      */
  189.     public function privacy_policy(RequestStack $requestStack): Response
  190.     {
  191.         $session $this->requestStack->getSession();
  192.         $language $session->get('lang');
  193.         if($language == 'english'){
  194.             $pageContent=["all_product"=>"All Products",
  195.                           "product_campaign"=>"Product Campaign",
  196.                           "home"=>"Home",
  197.                           "search"=>"Search",
  198.                           "privacy_policy"=>"Privacy Policy",
  199.             ];
  200.         }else{
  201.             $pageContent=["all_product"=>"Tous les produits",
  202.                           "product_campaign"=>"Campagne produit",
  203.                           "home"=>"Accueil",
  204.                           "search"=>"Chercher",
  205.                           "privacy_policy"=>"Politique de confidentialité",
  206.             ];
  207.         }  
  208.         return $this->render('front/privacy_policy.html.twig', [
  209.             'language'=>$language
  210.             'pageContent'=>$pageContent,  
  211.         ]);
  212.     }
  213.     /**
  214.      * @Route("/campaign-all-product/{id}", name="app_campaign_allproduct")
  215.      */
  216.     public function campaign_allproduct(Request $request,$id,RequestStack $requestStack): Response
  217.     {
  218.         $session $this->requestStack->getSession();
  219.         $language $session->get('lang');
  220.         if($language == 'english'){
  221.             $pageContent=["all_product"=>"All Products",
  222.                           "product_campaign"=>"Product Campaign",
  223.                           "home"=>"Home",
  224.                           "privacy_policy"=>"Privacy Policy",
  225.                           "search"=>"Search",
  226.                           "voteforproduct"=>"Vote for Product",
  227.                           "filterproducts"=>"Filter Products",
  228.                           "filters"=>"Filters",
  229.                           "category"=>"Category",
  230.                           "subcategory"=>"Sub-Category",
  231.                           "submit"=>"Submit",
  232.                           "back"=>"Back",
  233.                           "vote"=>"Vote",
  234.                           "votes"=>"Vote",
  235.             ];
  236.         }else{
  237.             $pageContent=["all_product"=>"Tous les produits",
  238.                           "product_campaign"=>"Campagne produit",
  239.                           "home"=>"Accueil",
  240.                           "privacy_policy"=>"Politique de confidentialité",
  241.                           "search"=>"Chercher",
  242.                           "voteforproduct"=>"Votez pour le produit",
  243.                           "filterproducts"=>"Filtrer les produits",
  244.                           "filters"=>"Filtres",
  245.                           "category"=>"Catégorie",
  246.                           "subcategory"=>"Sous-catégorie",
  247.                           "submit"=>"Nous faire parvenir",
  248.                           "back"=>"Retour",
  249.                           "vote"=>"Voter",
  250.                           "votes"=>"Voix",
  251.             ];
  252.         }    
  253.         $input=$request->request->all();
  254.         if (!empty($input)) {
  255.             if(!empty($input['category'])  && empty($input['subcategory'])){
  256.                 $campaign $this->getDoctrine()->getRepository('App\Entity\Campaign')->findOneBy(array('id'=>$id,'status'=>true));
  257.                 $allcatid=explode(","$campaign->getcategoryId());
  258.                 $category=$input['category'];
  259.                 $results $this->getDoctrine()->getRepository('App\Entity\Products')->findBy(
  260.                         array('category'=>$category));
  261.                 foreach($results as $key => $value){
  262.                     $CustomerVotes $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findBy(array('product_id'=>$value->getId(),'campaign_id'=>$id));
  263.                     $vote_count =count($CustomerVotes);
  264.                     $results[$key]->vote_counts=$vote_count;
  265.                     $ipadress=$request->getClientIp();  
  266.                     $search_vote $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findOneBy(array('product_id'=>$value->getId(),'campaign_id'=>$id,'ipaddress'=>$ipadress));
  267.                     if(!empty($search_vote)){
  268.                         $results[$key]->voted=1;
  269.                     }else{
  270.                         $results[$key]->voted=0;        
  271.                     }
  272.                 }
  273.             }elseif(!empty($input['category']) && !empty($input['subcategory'])){
  274.                 $campaign $this->getDoctrine()->getRepository('App\Entity\Campaign')->findOneBy(array('id'=>$id,'status'=>true));
  275.                 $allcatid=explode(","$campaign->getcategoryId());
  276.                 $category=$input['category'];
  277.                 $subcategory=$input['subcategory'];
  278.                 $results $this->getDoctrine()->getRepository('App\Entity\Products')->findOneByCatSubcatField($category,$subcategory);
  279.                 foreach($results as $key => $value){
  280.                     $CustomerVotes $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findBy(array('product_id'=>$value->getId(),'campaign_id'=>$id));
  281.                     $vote_count =count($CustomerVotes);
  282.                     $results[$key]->vote_counts=$vote_count;
  283.                     $ipadress=$request->getClientIp();  
  284.                     $search_vote $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findOneBy(array('product_id'=>$value->getId(),'campaign_id'=>$id,'ipaddress'=>$ipadress));
  285.                     if(!empty($search_vote)){
  286.                         $results[$key]->voted=1;
  287.                     }else{
  288.                         $results[$key]->voted=0;        
  289.                     }
  290.                 }
  291.             }else{
  292.                 $campaign $this->getDoctrine()->getRepository('App\Entity\Campaign')->findOneBy(array('id'=>$id,'status'=>true));
  293.                 $allcatid=explode(","$campaign->getcategoryId());
  294.                 $results $this->getDoctrine()->getRepository('App\Entity\Products')->findOneBySomeField($allcatid);
  295.                 foreach($results as $key => $value){
  296.                     $CustomerVotes $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findBy(array('product_id'=>$value->getId(),'campaign_id'=>$id));
  297.                     $vote_count =count($CustomerVotes);
  298.                     $results[$key]->vote_counts=$vote_count;
  299.                     $ipadress=$request->getClientIp();  
  300.                     $search_vote $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findOneBy(array('product_id'=>$value->getId(),'campaign_id'=>$id,'ipaddress'=>$ipadress));
  301.                     if(!empty($search_vote)){
  302.                         $results[$key]->voted=1;
  303.                     }else{
  304.                         $results[$key]->voted=0;        
  305.                     }
  306.                 }
  307.             }
  308.         }else{
  309.             $campaign $this->getDoctrine()->getRepository('App\Entity\Campaign')->findOneBy(array('id'=>$id,'status'=>true));
  310.             $allcatid=explode(","$campaign->getcategoryId());
  311.             $results $this->getDoctrine()->getRepository('App\Entity\Products')->findOneBySomeField($allcatid);
  312.             foreach($results as $key => $value){
  313.                 $CustomerVotes $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findBy(array('product_id'=>$value->getId(),'campaign_id'=>$id));
  314.                 $vote_count =count($CustomerVotes);
  315.                 $results[$key]->vote_counts=$vote_count;
  316.                 $ipadress=$request->getClientIp();  
  317.                 $search_vote $this->getDoctrine()->getRepository('App\Entity\CustomerVotes')->findOneBy(array('product_id'=>$value->getId(),'campaign_id'=>$id,'ipaddress'=>$ipadress));
  318.                 if(!empty($search_vote)){
  319.                     $results[$key]->voted=1;
  320.                 }else{
  321.                     $results[$key]->voted=0;        
  322.                 }
  323.             }
  324.         }
  325.         // dd($results);
  326.         $categorie $this->getDoctrine()->getRepository(Categorie::class)->findOneBySomeField($allcatid);
  327.         $subcategorie $this->getDoctrine()->getRepository(Subcategorie::class)->findBy(array('status'=>'1')); 
  328.         return $this->render('front/compaign_product.html.twig', [
  329.             'results'=>$results,
  330.             'campaign'=>$campaign,
  331.             'category'=>$categorie,
  332.             'subcategory'=>$subcategorie,  
  333.             'camp_id'=>$id,  
  334.             'pageContent'=>$pageContent,  
  335.             'language'=>$language
  336.         ]);
  337.     }
  338.     /**
  339.      * @Route("/voting-product/{id}/{product}", name="app_voting_on_product")
  340.      */
  341.     public function voting_on_product(Request $request,$id,$product,RequestStack $requestStack)
  342.     {
  343.         // dd($id);
  344.         $em $this->getDoctrine()->getManager();  
  345.         $ipadress=$request->getClientIp();     
  346.         $addRequest = new CustomerVotes;
  347.         $addRequest->setCampaignId($id);
  348.         $addRequest->setProductId($product);
  349.         $addRequest->setVoteCount('1');
  350.         $addRequest->setIpaddress($ipadress);
  351.         $addRequest->setVoteDate(date"Y-m-d"strtotime(date('Y-m-d'))));
  352.         $em $this->getDoctrine()->getManager();
  353.         $em->persist($addRequest);
  354.         $em->flush();
  355.         $session $this->requestStack->getSession();
  356.         $language $session->get('lang');
  357.         if($language == 'english'){
  358.             $this->addFlash('green''You have vote this product successfully. Thank You!'); 
  359.         }else{
  360.             $this->addFlash('green''Vous avez voté ce produit avec succès. Merci!'); 
  361.         }
  362.         return $this->redirectToRoute('app_campaign_allproduct', array('id' => $id));
  363.     }
  364.     /**
  365.      * @Route("/product-complaint", name="app_product_complaint")
  366.      */
  367.     public function product_complaint(Request $request,string $uploadDirthree,FileUploader $uploader,RequestStack $requestStack)
  368.     {
  369.         $session $this->requestStack->getSession();
  370.         $language $session->get('lang');
  371.         $input=$request->request->all();
  372.         if(count($request->files->get('image')) <= && !empty($input['product_id']) && !empty($input['shopkeepername']) && !empty($input['longitude']) && !empty($input['latitude'])){
  373.             if ($request->getMethod() === "POST") {
  374.         // dd($request->request->all());
  375.                 $product_id $this->getDoctrine()->getRepository('App\Entity\Products')->findOneBy(
  376.                  array('id'=>$request->request->get('product_id')),
  377.                 );
  378.                 $Province $this->getDoctrine()->getRepository('App\Entity\Province')->findOneBy(
  379.                     array('id'=>$request->request->get('province')),
  380.                 );
  381.                 $citys $this->getDoctrine()->getRepository('App\Entity\City')->findOneBy(
  382.                     array('id'=>$request->request->get('city')),
  383.                 );
  384.                 $files $request->files->get('image');
  385.                 if (!empty($files))
  386.                 {
  387.                     $imgs=array();
  388.                     foreach ($files as $key => $file) {
  389.                         $filename $file->getClientOriginalName();
  390.                         $extensions=$file->getClientOriginalExtension();
  391.                         $imagename='images/complaint_img/product_complaint_'.rand(1111,9999).time().'.'.$extensions;
  392.                         $uploader->upload($uploadDirthree$file$imagename);
  393.                         $imgs[]=$imagename;
  394.                     }
  395.                     $product_image=implode(","$imgs); 
  396.                 }else{
  397.                     $product_image null;
  398.                 } 
  399.                 $ipadress=$request->getClientIp();  
  400.                 $addRequest = new Complaint;
  401.                 $addRequest->setProduct($product_id);
  402.                 $addRequest->setShopkeepername($input['shopkeepername']);
  403.                 $addRequest->setAddress($input['address']);
  404.                 $addRequest->setLongitude($input['longitude']);
  405.                 $addRequest->setLatitude($input['latitude']);
  406.                 $addRequest->setProvince($Province);
  407.                 $addRequest->setCity($citys);
  408.                 $addRequest->setZipcode($input['zipcode']);
  409.                 $addRequest->setRemark($input['remark']);
  410.                 $addRequest->setIpaddress($ipadress);
  411.                 $addRequest->setImage($product_image);
  412.                 $addRequest->setCdate(date"Y-m-d"strtotime(date('Y-m-d'))));
  413.                 $addRequest->setResolvedDate(date"Y-m-d"strtotime(date('Y-m-d'))));
  414.                 $addRequest->setAssignDate(date"Y-m-d"strtotime(date('Y-m-d'))));
  415.                 $addRequest->setGrpid('0');
  416.                 $addRequest->setCompstatus('Pending');
  417.                 $addRequest->setStatus('0');
  418.                 $addRequest->setShowStatus('1');
  419.                 $addRequest->setFraud('0');
  420.                 $addRequest->setAgentid('0');
  421.                 $addRequest->setOperationalId('0');
  422.                 $em $this->getDoctrine()->getManager();
  423.                 $em->persist($addRequest);
  424.                 $em->flush();
  425.                 $addRequest->getId();
  426.                 $complaint $this->getDoctrine()->getRepository('App\Entity\Complaint')->findBy(array('id'=>$addRequest->getId()));
  427.                 if($language == 'english'){
  428.                     $this->addFlash('green''Your complaint has been submitted successfully. Thank You!'); 
  429.                 }else{
  430.                     $this->addFlash('green''Votre plainte a été soumise avec succès. Merci!'); 
  431.                 }
  432.                 return $this->redirectToRoute('app_front');
  433.                 // $output['data'] = $complaint;
  434.             }else{
  435.                 $output['status'] = false;
  436.                 return $this->redirectToRoute('app_front');
  437.             }
  438.         }else{
  439.             if(empty($input['product_id']) || empty($input['shopkeepername']) || empty($input['address']) || empty($input['longitude']) || empty($input['latitude']) || empty($input['zipcode']) || empty($input['remark'])){
  440.                 if($language == 'english'){
  441.                     $this->addFlash('red''Please enter all the required fields.'); 
  442.                 }else{
  443.                     $this->addFlash('red''Veuillez remplir tous les champs obligatoires.');  
  444.                 }
  445.             }
  446.             if($language == 'english'){
  447.                 $this->addFlash('red''You are only allowed to upload a maximum of 4 files.'); 
  448.             }else{
  449.                 $this->addFlash('red'"Vous n'êtes autorisé à télécharger que 4 fichiers au maximum."); 
  450.             }
  451.             return $this->redirectToRoute('app_front');
  452.         }
  453.     }
  454.     /**
  455.      * @Route("/request-subcategoryall/", name="app_get_subcategoryall")
  456.      */
  457.     public function get_subcategoryall(Request $request)
  458.     {
  459.         // print_r($request->request->get('cacheckboxValues'));die;
  460.         if($request->request->get('cacheckboxValues'))
  461.         {
  462.             $result $this->getDoctrine()->getRepository('App\Entity\Subcategorie')->findOneBySomeFieldIds($request->request->get('cacheckboxValues'));
  463.         }
  464.         return $this->json($result);
  465.     }
  466. //class end
  467. }