src/Controller/Front/HomeController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\MarketBulletin;
  4. use App\Entity\Supplier;
  5. use App\Model\ProductFeaturingFactory;
  6. use App\Model\SupplierFactory;
  7. use App\Model\User\User;
  8. use App\Service\MessageMatcherService;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\Routing\RouterInterface;
  16. class HomeController extends FrontController
  17. {
  18.     /**
  19.      * @Route("/", name="malys_front_home")
  20.      */
  21.     public function home(
  22.         SupplierFactory $supplierFactory,
  23.         EntityManagerInterface $em,
  24.         RouterInterface $router,
  25.         ParameterBagInterface $parameterBag,
  26.         User $user,
  27.         ProductFeaturingFactory  $prodFeaturingFactory,
  28.         MessageMatcherService $messageMatcherService
  29.     ): Response {
  30.         $user->fromCurrentUser();
  31.         /*
  32.          * if last route is login : set cart > orderToModify to null
  33.          * if not : do nothing
  34.          */
  35.         $request Request::createFromGlobals();
  36.         $referer $request->headers->get('referer');
  37.         if ($referer) {
  38.             $refererPathInfo Request::create($referer)->getPathInfo();
  39.             $welcomePath $router->getRouteCollection()->get('malys_front_welcome')->getPath();
  40.             if ($refererPathInfo === $welcomePath) {
  41.                 $cartEntity $user->getCurrentCartEntity();
  42.                 if ($cartEntity !== null) {
  43.                     $cartEntity->setOrderToModify(null);
  44.                     $em->flush($cartEntity);
  45.                 }
  46.             }
  47.         }
  48.         $shop $user->getCurrentShop();
  49.         // Product featuring
  50.         $prodFeaturings       $prodFeaturingFactory->currentFeaturings();
  51.         // Messages
  52.         $messagematches $messageMatcherService
  53.             ->setUser($this->getUser())
  54.             ->getHomeUserMessages();
  55.         // Active suppliers
  56.         $supplierRepo            $em->getRepository(Supplier::class);
  57.         $activeSuppliersEntities $supplierRepo->search([
  58.             'limit'       => 999999,
  59.             'workingWith' => $shop->getEntity()
  60.         ]);
  61.         $activeSuppliers = [];
  62.         $activeSuppliersIds = [];
  63.         foreach ($activeSuppliersEntities as $supplierEntity) {
  64.             $supplier $supplierFactory->createModel();
  65.             $supplier->setEntity($supplierEntity);
  66.             $activeSuppliers[] = $supplier;
  67.             $activeSuppliersIds[] = $supplierEntity->getId();
  68.         }
  69.         // Market info
  70.         $marketBulletinRepo $em->getRepository(MarketBulletin::class);
  71.         $bulletin           current($marketBulletinRepo->findAll());
  72.         // Suggested suppliers
  73.         $suggestedSuppliers = [];
  74.         if (!is_null($shop)) {
  75.             $suggestedSupplierEntities $shop->getEntity()->getSuggestedSuppliers();
  76.             if ($suggestedSupplierEntities->count() === 0) {
  77.                 $defaultSuggestedSuppliersIds $parameterBag->get('default_suggested_suppliers');
  78.                 // array_diff car on ne veut pas afficher des fournisseurs suggérés avec lesquels on travaille déjà
  79.                 $suggestedSupplierEntities $supplierRepo->search(['ids' => array_diff($defaultSuggestedSuppliersIds$activeSuppliersIds)]);
  80.             }
  81.             foreach ($suggestedSupplierEntities as $supplierEntity) {
  82.                 $supplier $supplierFactory->createModel();
  83.                 $supplier->setEntity($supplierEntity);
  84.                 $suggestedSuppliers[] = $supplier;
  85.             }
  86.         }
  87.         return $this->render('front/home/home.html.twig', [
  88.             'prodFeaturings'     => $prodFeaturings,
  89.             'messagematches'     => $messagematches,
  90.             'activeSuppliers'    => $activeSuppliers,
  91.             'suggestedSuppliers' => $suggestedSuppliers,
  92.             'currentShop'        => $shop,
  93.             'bulletin'           => $bulletin,
  94.         ]);
  95.     }
  96.     /**
  97.      * @Route("/login_check", name="malys_front_login_check_redir", methods={"GET"})
  98.      */
  99.     public function loginCheckGet(): RedirectResponse
  100.     {
  101.         return $this->redirectToRoute('malys_front_home');
  102.     }
  103.     /**
  104.      * @Route("/resetting/send-email", name="malys_front_resetting_redir", methods={"GET"})
  105.      */
  106.     public function resetEmailGet(): RedirectResponse
  107.     {
  108.         return $this->redirectToRoute('malys_front_home');
  109.     }
  110. }