src/Controller/Front/FrontHomeController.php line 44

Open in your IDE?
  1. <?php
  2. namespace Acme\SudcmsBundle\Controller\Front;
  3. use Acme\SudcmsBundle\Entity\EcoProducts;
  4. use Acme\SudcmsBundle\Entity\EcoProductsReferences;
  5. use Acme\SudcmsBundle\Entity\Site;
  6. use Acme\SudcmsBundle\Repository\ActualiteRepository;
  7. use Acme\SudcmsBundle\Repository\AutopromoRepository;
  8. use Acme\SudcmsBundle\Repository\CatalogRepository;
  9. use Acme\SudcmsBundle\Repository\EcoProductsRepository;
  10. use Acme\SudcmsBundle\Repository\FlashMessageRepository;
  11. use Acme\SudcmsBundle\Repository\FormAdressesRepository;
  12. use Acme\SudcmsBundle\Repository\SiteReferencementRepository;
  13. use Acme\SudcmsBundle\Repository\SiteRepository;
  14. use Acme\SudcmsBundle\Service\BrevoService;
  15. use Acme\SudcmsBundle\Service\MailerService;
  16. use Acme\SudcmsBundle\Service\OtideaUtils;
  17. use Brevo\Client\Api\TransactionalEmailsApi;
  18. use Brevo\Client\ApiException;
  19. use Brevo\Client\Configuration;
  20. use Brevo\Client\Model\SendSmtpEmail;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use GuzzleHttp\Client;
  23. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  24. use Symfony\Component\Asset\UrlPackage;
  25. use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\Session\Session;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use Twig\Environment;
  30. use const SITE_NAME;
  31. class FrontHomeController extends AbstractController {
  32.     private $twig false;
  33.     private $session;
  34.     public function __construct(private EntityManagerInterface $entityManager) {
  35.         $this->session = new Session();
  36.     }
  37.     #[Route(path'/'name'front_home')]
  38.     public function index(Request                $requestEnvironment $twig,
  39.                           AutopromoRepository    $autopromoRepositoryOtideaUtils $otideaUtils,
  40.                           FlashMessageRepository $flashMessageSiteReferencementRepository $repoAccRef,
  41.                           EcoProductsRepository  $repoProdCatalogRepository $repoCatalog,
  42.                           ActualiteRepository    $repoActuSiteRepository $siteRepository) {
  43.         $this->twig $twig;
  44.         // use to delete old data in ContactHistorique for ex.
  45.         $otideaUtils->deleteOldData();
  46.         $accRef $repoAccRef->findOneBy(['site_lang' => $request->getLocale(), 'site_uid' => CURRENT_SITE_ID]);
  47.         if (is_null($accRef)) {
  48.             $accRef $repoAccRef->findOneBy(['site_uid'  => $this->session->get('admin_site_uid'),
  49.                                               'site_lang' => 'fr']);
  50.         }
  51.         //autopromo
  52.         $tabPromoZone1 $tabPromoZone2 $tabPromoZone3 null;
  53.         $autoPromos $autopromoRepository->findBy(array("isOnline" => 1'siteLang' => $request->getLocale(),
  54.                                                          'siteUid'  => CURRENT_SITE_ID),
  55.                                                    array('autopromoOrder' => 'ASC'));
  56.         $productsBestSellers $repoProd->findBestSellerHome();
  57.         $productsNews $repoProd->findNouveauteHome();
  58.         foreach ($autoPromos as $auto) {
  59.             if ($auto->getSection() == 1)
  60.                 $tabPromoZone1[] = $auto;
  61.             elseif ($auto->getSection() == 2)
  62.                 $tabPromoZone2[] = $auto;
  63.             elseif ($auto->getSection() == 3)
  64.                 $tabPromoZone3[] = $auto;
  65.         }
  66.         $verifVideo $this->verifVideo();
  67.         $flashInfo $flashMessage->findBy(array('flash_enligne' => 1'site_lang' => $request->getLocale(),
  68.                                                  'site_uid'      => CURRENT_SITE_ID), array('flash_ordre' => 'ASC'));
  69.         $limitActu $siteRepository->findOneBy(['id' => CURRENT_SITE_ID]);
  70.         $tabPromoZone3_1 = [];
  71.         if ($tabPromoZone3 != null && sizeof($tabPromoZone3) > 0) {
  72.             $tabPromoZone3_1 $tabPromoZone3[0];
  73.         }
  74.         $sellCatalog $repoCatalog->findByCatAllCatalog(['site_lang' => $request->getLocale(),
  75.                                                           'site_uid'  => CURRENT_SITE_ID'categorie' => 0,
  76.                                                           'isSell'    => 1], ['cat_date_publication' => 'DESC']);
  77.         $rentCatalog $repoCatalog->findByCatAllCatalog(['site_lang' => $request->getLocale(),
  78.                                                           'site_uid'  => CURRENT_SITE_ID'categorie' => 0,
  79.                                                           'isSell'    => 2], ['cat_date_publication' => 'DESC']);
  80.         return $this->render('front/front_home/index.html.twig', [
  81.             'autoPromoList'       => $autoPromos,
  82.             'sellCatalog'         => $sellCatalog,
  83.             'rentCatalog'         => $rentCatalog,
  84.             'tabPromoZone1'       => $tabPromoZone1,
  85.             'tabPromoZone2'       => $tabPromoZone2,
  86.             'tabPromoZone3'       => $tabPromoZone3_1,
  87.             'actualites'          => $repoActu->findByCatAllActu(['site_lang' => $request->getLocale(),
  88.                                                                   'site_uid'  => CURRENT_SITE_ID,
  89.                                                                   'limit'     => $limitActu->getNbNewsHomePage(),
  90.                                                                   'categorie' => 0]),
  91.             'flashInfo'           => $flashInfo,
  92.             'verifVideo'          => $verifVideo,
  93.             'accRef'              => $accRef,
  94.             'productsNews'        => $productsNews,
  95.             'productsBestSellers' => $productsBestSellers,
  96.             'isHome'              => true,
  97.         ]);
  98.     }
  99.     public function verifVideo() {
  100.         $exist false;
  101.         $directory[] = $this->getParameter("upload_directory_" CURRENT_SITE_ID) . '/video_accueil';
  102.         foreach ($directory as $dir) {
  103.             if (!file_exists($dir)) {
  104.                 mkdir($dir755);
  105.             }
  106.         }
  107.         //        $allFiles = scandir($this->getParameter("upload_directory") . '/video_accueil');
  108.         $allFiles scandir($this->getParameter("upload_directory_" CURRENT_SITE_ID) . '/video_accueil');
  109.         $files array_diff($allFiles, array('.''..'));
  110.         foreach ($files as $file) {
  111.             if ($file == 'home-loop.mp4') {
  112.                 $exist true;
  113.             }
  114.         }
  115.         return $exist;
  116.     }
  117.     public function emailExemple(MailerService $mailerServiceFormAdressesRepository $adressesRepository) {
  118.         $files = array();
  119.         $mailerService->fromEmail "no-reply@domaine.fr";
  120.         $mailerService->fromName SITE_NAME;
  121.         $mailerService->subject "Validation de votre commande";
  122.         $allRecipients = [];
  123.         $recipients $adressesRepository->findBy(["form" => "contact"]);
  124.         if (sizeof($recipients) > 0) {
  125.             foreach ($recipients as $element) {
  126.                 $allRecipients[] = [
  127.                     "nom"    => $element->getNom(),
  128.                     "prenom" => $element->getPrenom(),
  129.                     "email"  => $element->getEmail(),
  130.                     "type"   => $element->getType()
  131.                 ];
  132.             }
  133.         }
  134.         $htmlContent $this->renderView('layouts_emails/validation_commande.html.twig', [
  135.             'articles' => '',
  136.         ]);
  137.         $mailerService->sendMail($allRecipients$htmlContent$files);
  138.     }
  139. }