src/Controller/HomeController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use App\Repository\UserPlatformRepository;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use App\Acme\Bundle\Utility\ViewUtility\UtilityMenusBackend;
  10. use App\Acme\Bundle\Utility\TemplatesUtility\MenusStandard;
  11. use App\Form\SubscriptionForm\UserMultilType;
  12. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  13. use App\Entity\UserPlatform;
  14. use App\Entity\Product;
  15. use App\Form\UserPlatformType;
  16. use App\Repository\CategoriProductRepository;
  17. use App\Repository\CommissionRepository;
  18. use App\Repository\CoursDeChangeRepository;
  19. use App\Repository\PriceProductRepository;
  20. use App\Repository\ProductListRepository;
  21. use App\Repository\ProductRepository;
  22. use App\Repository\StockRepository;
  23. use Exception;
  24. use Symfony\Component\Security\Core\Security;
  25. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  26. class HomeController extends AbstractController
  27. {
  28.     /**
  29.      * @Route("/", name="app_home")
  30.      */
  31.     public function index(EntityManagerInterface $entityManagerAuthorizationCheckerInterface $authorizationCheckerProductRepository $productRepositoryUserPlatformRepository $userPlatformRepositoryPriceProductRepository $priceProductRepositoryStockRepository $stockRepositoryCategoriProductRepository $categoriProductRepositoryProductListRepository $productListRepositoryCoursDeChangeRepository $coursDeChangeRepositoryCommissionRepository $commissionRepository): Response
  32.     {
  33.         // return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER);
  34.         // $templatesMenus = new UtilityMenusBackend(0);
  35.         // MenusStandard::setTitleTemplate($templatesMenus);
  36.         // MenusStandard::setTitleApplication($templatesMenus);
  37.         // MenusStandard::setMenusStandard($templatesMenus, $authorizationChecker);
  38.         $clainService $userPlatformRepository->findBy(['email' => 'clainservice@gmail.com']);
  39.         $user $this->getUser();
  40.         if ($clainService) {
  41.             $allProducts =  $productRepository->getAllProductsByUser($clainService[0]->getId());
  42.             $allProductsDay $productRepository->getAllProductsDayByUser($clainService[0]->getId());
  43.             $productsDayLeft $productRepository->getAllProductsDayByUserForLeft($clainService[0]->getId());
  44.             $productsDayRight $productRepository->getAllProductsDayByUserForRight($clainService[0]->getId());
  45.             // section mode produits
  46.             $priceMode = [];
  47.             $modeProducts $productRepository->getCatModeAffiche($clainService[0]->getId());
  48.             foreach ($modeProducts as $key => $value) {
  49.                 // dd($priceProductRepository->findBy(['product'=> $value->getId()]));
  50.                 $priceMode[] = [
  51.                     "idProduct" => $value->getId(),
  52.                     "productTitle" => $value->getDesctription(),
  53.                     "productImage" => $value->getPicture(),
  54.                     "prix" => $priceProductRepository->findBy(['product' => $value->getId()])[0]->getPriceCustomer()
  55.                 ];
  56.             }
  57.             // dd($priceMode);
  58.             // tous les catégories
  59.             $catTable = [];
  60.             $categories $categoriProductRepository->findAll();
  61.             foreach ($categories as $key => $value) {
  62.                 $catTable[] = [
  63.                     "id" => $value->getId(),
  64.                     "title" => $value->getTitle(),
  65.                     "image" => $value->getImageName()
  66.                 ];
  67.             }
  68.             // dd($catTable);
  69.             $productPriceAndStock = [];
  70.             $productDayPriceAndStock = [];
  71.             $productDayLeftPriceAndStock = [];
  72.             $productDayRightPriceAndStock = [];
  73.             foreach ($allProducts as $key => $value) {
  74.                 $idValue $value->getId();
  75.                 $price $priceProductRepository->getPriceProduct($idValue);
  76.                 $stock $stockRepository->getProduitStock($value);
  77.                 $productPriceAndStock[] = [
  78.                     "id" => $value->getId(),
  79.                     "name" => $value->getTitle(),
  80.                     "description" => $value->getDesctription(),
  81.                     "imageName" => $value->getPicture(),
  82.                     "devise" => $value->getFkdevise()->getId(),
  83.                     "priceCust" => $price->getPriceCustomer(),
  84.                     "priceDealer" => $price->getPriceDealer(),
  85.                     "stockDispo" => $stock->getStockDispo(),
  86.                     "stockReel" => $stock->getStockReel()
  87.                 ];
  88.             }
  89.             // tous les produits du jour
  90.             foreach ($allProductsDay as $key => $value) {
  91.                 $idValue $value->getId();
  92.                 $price $priceProductRepository->getPriceProduct($idValue);
  93.                 // dd($price);
  94.                 $stock $stockRepository->getProduitStock($value);
  95.                 $productDayPriceAndStock[] = [
  96.                     "id" => $value->getId(),
  97.                     "name" => $value->getTitle(),
  98.                     "description" => $value->getDesctription(),
  99.                     "imageName" => $value->getPicture(),
  100.                     "devise" => $value->getFkdevise()->getId(),
  101.                     "priceCust" => $price->getPriceCustomer(),
  102.                     "priceDealer" => $price->getPriceDealer(),
  103.                     "stockDispo" => $stock->getStockDispo(),
  104.                     "stockReel" => $stock->getStockReel()
  105.                 ];
  106.             }
  107.             // offre du jour du gauche
  108.             foreach ($productsDayLeft as $key => $value) {
  109.                 $idValue $value->getId();
  110.                 $price $priceProductRepository->getPriceProduct($idValue);
  111.                 $stock $stockRepository->getProduitStock($value);
  112.                 $productDayLeftPriceAndStock[] = [
  113.                     "id" => $value->getId(),
  114.                     "name" => $value->getTitle(),
  115.                     "description" => $value->getDesctription(),
  116.                     "imageName" => $value->getPicture(),
  117.                     "devise" => $value->getFkdevise()->getId(),
  118.                     "priceCust" => $price->getPriceCustomer(),
  119.                     "priceDealer" => $price->getPriceDealer(),
  120.                     "stockDispo" => $stock->getStockDispo(),
  121.                     "stockReel" => $stock->getStockReel()
  122.                 ];
  123.             }
  124.             // offre du jour du droite
  125.             foreach ($productsDayRight as $key => $value) {
  126.                 $idValue $value->getId();
  127.                 $price $priceProductRepository->getPriceProduct($idValue);
  128.                 $stock $stockRepository->getProduitStock($value);
  129.                 $productDayRightPriceAndStock[] = [
  130.                     "id" => $value->getId(),
  131.                     "name" => $value->getTitle(),
  132.                     "description" => $value->getDesctription(),
  133.                     "imageName" => $value->getPicture(),
  134.                     "devise" => $value->getFkdevise()->getId(),
  135.                     "priceCust" => $price->getPriceCustomer(),
  136.                     "priceDealer" => $price->getPriceDealer(),
  137.                     "stockDispo" => $stock->getStockDispo(),
  138.                     "stockReel" => $stock->getStockReel(),
  139.                 ];
  140.             }
  141.         } else {
  142.             $productPriceAndStock = [];
  143.             $productDayPriceAndStock = [];
  144.             $productDayLeftPriceAndStock = [];
  145.             $productDayRightPriceAndStock = [];
  146.         }
  147.         shuffle($productPriceAndStock);
  148.         $chaussure = [];
  149.         $montre = [];
  150.         $femmes = [];
  151.         $timberland = [];
  152.         $air = [];
  153.         $gucci = [];
  154.         $alo = [];
  155.         $loui = [];
  156.         $dior = [];
  157.         $chaussures $productListRepository->getProduitMarque("Chaussures"1);
  158.         $montres $productListRepository->getProduitMarque("Montre"1);
  159.         $femme $productListRepository->getProduitMarque("Pour femme"1);
  160.         $timberlands $productListRepository->getProduitMarque("Chaussure timberland"1);
  161.         $airs $productListRepository->getProduitMarque("Chaussure air jord"1);
  162.         $guccis $productListRepository->getProduitMarque("Gucci"1);
  163.         $alos $productListRepository->getProduitMarque("Alo yoga"1);
  164.         $louis $productListRepository->getProduitMarque("sac Louis Vuitton"1);
  165.         $diors $productListRepository->getProduitMarque("marque ⁠Christian Dior"1);
  166.         $cours_change =  $coursDeChangeRepository->findAll();
  167.         $commission $commissionRepository->findAll();
  168.         // Traitement des produits récupérés
  169.         foreach ($chaussures as $key => $value) {
  170.             // dd($value->getProduct());
  171.             if (isset($cours_change[0])) {
  172.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  173.                 if (isset($commission[0])) {
  174.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  175.                     $prixFinal $prix $commiss;
  176.                 } else {
  177.                     $prixFinal $prix;
  178.                 }
  179.             } else {
  180.                 $prixFinal $value->getProduct()[0]['price'];
  181.             }
  182.             // Préparation des produits pour le retour
  183.             $chaussure[] = [
  184.                 "title" => $value->getProduct()[0]['title'],
  185.                 "price" => $prixFinal,
  186.                 "pic_url" => $value->getProduct()[0]['img'],
  187.                 "num_iid" => $value->getIdProduct(),
  188.                 // "detail_url" => $value['product_url'],
  189.             ];
  190.         }
  191.         // Traitement des produits récupérés
  192.         foreach ($montres as $key => $value) {
  193.             // dd($value->getProduct());
  194.             if (isset($cours_change[0])) {
  195.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  196.                 if (isset($commission[0])) {
  197.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  198.                     $prixFinal $prix $commiss;
  199.                 } else {
  200.                     $prixFinal $prix;
  201.                 }
  202.             } else {
  203.                 $prixFinal $value->getProduct()[0]['price'];
  204.             }
  205.             // Préparation des produits pour le retour
  206.             $montre[] = [
  207.                 "title" => $value->getProduct()[0]['title'],
  208.                 "price" => $prixFinal,
  209.                 "pic_url" => $value->getProduct()[0]['img'],
  210.                 "num_iid" => $value->getIdProduct(),
  211.                 // "detail_url" => $value['product_url'],
  212.             ];
  213.         }
  214.         // Traitement des produits récupérés
  215.         foreach ($femme as $key => $value) {
  216.             // dd($value->getProduct());
  217.             if (isset($cours_change[0])) {
  218.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  219.                 if (isset($commission[0])) {
  220.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  221.                     $prixFinal $prix $commiss;
  222.                 } else {
  223.                     $prixFinal $prix;
  224.                 }
  225.             } else {
  226.                 $prixFinal $value->getProduct()[0]['price'];
  227.             }
  228.             // Préparation des produits pour le retour
  229.             $femmes[] = [
  230.                 "title" => $value->getProduct()[0]['title'],
  231.                 "price" => $prixFinal,
  232.                 "pic_url" => $value->getProduct()[0]['img'],
  233.                 "num_iid" => $value->getIdProduct(),
  234.                 // "detail_url" => $value['product_url'],
  235.             ];
  236.         }
  237.         foreach ($timberlands as $key => $value) {
  238.             // dd($value->getProduct());
  239.             if (isset($cours_change[0])) {
  240.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  241.                 if (isset($commission[0])) {
  242.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  243.                     $prixFinal $prix $commiss;
  244.                 } else {
  245.                     $prixFinal $prix;
  246.                 }
  247.             } else {
  248.                 $prixFinal $value->getProduct()[0]['price'];
  249.             }
  250.             // Préparation des produits pour le retour
  251.             $timberland[] = [
  252.                 "title" => $value->getProduct()[0]['title'],
  253.                 "price" => $prixFinal,
  254.                 "pic_url" => $value->getProduct()[0]['img'],
  255.                 "num_iid" => $value->getIdProduct(),
  256.                 // "detail_url" => $value['product_url'],
  257.             ];
  258.         }
  259.         foreach ($airs as $key => $value) {
  260.             // dd($value->getProduct());
  261.             if (isset($cours_change[0])) {
  262.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  263.                 if (isset($commission[0])) {
  264.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  265.                     $prixFinal $prix $commiss;
  266.                 } else {
  267.                     $prixFinal $prix;
  268.                 }
  269.             } else {
  270.                 $prixFinal $value->getProduct()[0]['price'];
  271.             }
  272.             // Préparation des produits pour le retour
  273.             $air[] = [
  274.                 "title" => $value->getProduct()[0]['title'],
  275.                 "price" => $prixFinal,
  276.                 "pic_url" => $value->getProduct()[0]['img'],
  277.                 "num_iid" => $value->getIdProduct(),
  278.                 // "detail_url" => $value['product_url'],
  279.             ];
  280.         }
  281.         foreach ($guccis as $key => $value) {
  282.             // dd($value->getProduct());
  283.             if (isset($cours_change[0])) {
  284.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  285.                 if (isset($commission[0])) {
  286.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  287.                     $prixFinal $prix $commiss;
  288.                 } else {
  289.                     $prixFinal $prix;
  290.                 }
  291.             } else {
  292.                 $prixFinal $value->getProduct()[0]['price'];
  293.             }
  294.             // Préparation des produits pour le retour
  295.             $gucci[] = [
  296.                 "title" => $value->getProduct()[0]['title'],
  297.                 "price" => $prixFinal,
  298.                 "pic_url" => $value->getProduct()[0]['img'],
  299.                 "num_iid" => $value->getIdProduct(),
  300.                 // "detail_url" => $value['product_url'],
  301.             ];
  302.         }
  303.         foreach ($alos as $key => $value) {
  304.             // dd($value->getProduct());
  305.             if (isset($cours_change[0])) {
  306.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  307.                 if (isset($commission[0])) {
  308.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  309.                     $prixFinal $prix $commiss;
  310.                 } else {
  311.                     $prixFinal $prix;
  312.                 }
  313.             } else {
  314.                 $prixFinal $value->getProduct()[0]['price'];
  315.             }
  316.             // Préparation des produits pour le retour
  317.             $alo[] = [
  318.                 "title" => $value->getProduct()[0]['title'],
  319.                 "price" => $prixFinal,
  320.                 "pic_url" => $value->getProduct()[0]['img'],
  321.                 "num_iid" => $value->getIdProduct(),
  322.                 // "detail_url" => $value['product_url'],
  323.             ];
  324.         }
  325.         foreach ($louis as $key => $value) {
  326.             // dd($value->getProduct());
  327.             if (isset($cours_change[0])) {
  328.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  329.                 if (isset($commission[0])) {
  330.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  331.                     $prixFinal $prix $commiss;
  332.                 } else {
  333.                     $prixFinal $prix;
  334.                 }
  335.             } else {
  336.                 $prixFinal $value->getProduct()[0]['price'];
  337.             }
  338.             // Préparation des produits pour le retour
  339.             $loui[] = [
  340.                 "title" => $value->getProduct()[0]['title'],
  341.                 "price" => $prixFinal,
  342.                 "pic_url" => $value->getProduct()[0]['img'],
  343.                 "num_iid" => $value->getIdProduct(),
  344.                 // "detail_url" => $value['product_url'],
  345.             ];
  346.         }
  347.         foreach ($diors as $key => $value) {
  348.             // dd($value->getProduct());
  349.             if (isset($cours_change[0])) {
  350.                 $prix = ($cours_change[0]->getAriary() * $value->getProduct()[0]['price']);
  351.                 if (isset($commission[0])) {
  352.                     $commiss = ($commission[0]->getMontant() / 100) * $prix;
  353.                     $prixFinal $prix $commiss;
  354.                 } else {
  355.                     $prixFinal $prix;
  356.                 }
  357.             } else {
  358.                 $prixFinal $value->getProduct()[0]['price'];
  359.             }
  360.             // Préparation des produits pour le retour
  361.             $dior[] = [
  362.                 "title" => $value->getProduct()[0]['title'],
  363.                 "price" => $prixFinal,
  364.                 "pic_url" => $value->getProduct()[0]['img'],
  365.                 "num_iid" => $value->getIdProduct(),
  366.                 // "detail_url" => $value['product_url'],
  367.             ];
  368.         }
  369.         return $this->render('clainFront/accueil/index.html.twig', [
  370.             'user' => $user,
  371.             'products' => $productPriceAndStock,
  372.             'productsDay' => $allProductsDay,
  373.             'productsDayAll' => $productDayPriceAndStock,
  374.             'productsDayLeft' => $productDayLeftPriceAndStock,
  375.             'productsDayRight' => $productDayRightPriceAndStock,
  376.             'modeProducts' => $modeProducts,
  377.             'priceMode' => $priceMode,
  378.             'categories' => $categories,
  379.             'catTable' => $catTable,
  380.             'chaussures' => $chaussure,
  381.             'montres' => $montre,
  382.             'femmes' => $femmes,
  383.             'timberlands' => $timberland,
  384.             'airs' => $air,
  385.             'guccis' => $gucci,
  386.             'alos' => $alo,
  387.             'louis' => $loui,
  388.             'diors' => $dior
  389.         ]);
  390.     }
  391.     /**
  392.      * @Route("/inscription-client", name="app_home_inscription", methods={"GET", "POST"})
  393.      */
  394.     public function inscription(Request $requestUserPlatformRepository $userPlatformRepositoryUserPasswordEncoderInterface $passwordEncoder): Response
  395.     {
  396.         $user = new UserPlatform();
  397.         $form $this->createForm(UserMultilType::class, $user);
  398.         $form->handleRequest($request);
  399.         $arrayresult = array("error" => false"msg" => "");
  400.         if ($form->isSubmitted() && $form->isValid()) {
  401.             try {
  402.                 if ($user->getPassword() != $form->get('confirmpass')->getData()) {
  403.                     $arrayresult['error'] = true;
  404.                     $arrayresult['msg'] = "Mot de passe non confirmé.";
  405.                 } else if (strpos($user->getMail(), " ")) {
  406.                     $arrayresult['error'] = true;
  407.                     $arrayresult['msg'] = "l'identifiant \"" $user->getMail() . "\" ne doit pas contenir un espace.";
  408.                 } else if (strlen($user->getMail()) < 5) {
  409.                     $arrayresult['error'] = true;
  410.                     $arrayresult['msg'] = "l'identifiant \"" $user->getMail() . "\" doit contenir plus de 5 caracteres.";
  411.                 } else {
  412.                     $user->setEmail($user->getMail());
  413.                     $user->setRoles(["ROLE_CUSTOMER"]);
  414.                     $user->setPassword(
  415.                         $passwordEncoder->encodePassword($user$user->getPassword())
  416.                     );
  417.                     $userPlatformRepository->add($usertrue);
  418.                     // Stocker l'email dans la session
  419.                     $request->getSession()->set(Security::LAST_USERNAME$user->getEmail());
  420.                     return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
  421.                 }
  422.             } catch (Exception $exc) {
  423.                 // dd($exc->getMessage());
  424.                 return $this->render('frontView/error.html.twig', [
  425.                     'msg' => $exc->getMessage(),
  426.                 ]);
  427.             }
  428.         }
  429.         return $this->renderForm('frontView/inscription/inscription.html.twig', [
  430.             'form' => $form,
  431.             'arrayresult' => $arrayresult,
  432.         ]);
  433.     }
  434.     /**
  435.      * @Route("/edit-profil/{id}", name="app_home_edit_profil", methods={"GET", "POST"})
  436.      */
  437.     public function editProfil(Request $requestUserPlatform $userPlatformUserPlatformRepository $userPlatformRepositoryUserPasswordEncoderInterface $passwordEncoder): Response
  438.     {
  439.         $form $this->createForm(UserMultilType::class, $userPlatform);
  440.         $form->handleRequest($request);
  441.         if ($form->isSubmitted() && $form->isValid()) {
  442.             $userPlatformRepository->add($userPlatformtrue);
  443.         }
  444.         return $this->renderForm('frontView/inscription/editprofil.html.twig', [
  445.             'admin' => $userPlatform,
  446.             'form' => $form
  447.         ]);
  448.     }
  449.     /**
  450.      * @Route("/aroma-madagascar", name="app_aroma_madagascar", methods={"GET", "POST"})
  451.      */
  452.     public function aromaMadagascar(EntityManagerInterface $entityManager): Response
  453.     {
  454.         $orderby = array('points' => 'DESC');
  455.         $criteria = array();
  456.         return $this->render('frontView/boutique/indexaroma.html.twig', [
  457.             'products' => $entityManager->getRepository(Product::class)->getProductShop(3)
  458.         ]);
  459.     }
  460.     /**
  461.      * @Route("/kiki-creation-madagascar", name="app_kiki_madagascar", methods={"GET", "POST"})
  462.      */
  463.     public function kikiMadagascar(EntityManagerInterface $entityManager): Response
  464.     {
  465.         $orderby = array('points' => 'DESC');
  466.         $criteria = array();
  467.         return $this->render('frontView/boutique/indexkiki.html.twig', [
  468.             'products' => $entityManager->getRepository(Product::class)->getProductShop(4)
  469.         ]);
  470.     }
  471.     /**
  472.      * @Route("/infos", name="app_rapeto_infos", methods={"GET", "POST"})
  473.      */
  474.     public function infosRapeto(): Response
  475.     {
  476.         return $this->render('frontView/boutique/infos.html.twig', []);
  477.     }
  478.     /**
  479.      * @Route("/access-denied", name="app_home_access_denied")
  480.      */
  481.     public function accesDenied(EntityManagerInterface $entityManager): Response
  482.     {
  483.         return $this->render('security/error403.html.twig', []);
  484.     }
  485. }