src/Controller/ProductController.php line 252

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Product;
  4. use App\Services\InsightService;
  5. use App\Services\ProductService;
  6. use App\Entity\SonataClassificationCategory;
  7. use App\Entity\SonataClassificationTag;
  8. use Doctrine\ORM\ORMException;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Security\Core\Security;
  15. class ProductController extends BaseController
  16. {
  17.     /** @var ProductService $productService */
  18.     protected $productService;
  19.     /** @var InsightService $insightService */
  20.     protected $insightService;
  21.     /**
  22.      * InsightController constructor.
  23.      *
  24.      * @param ProductService $productService
  25.      * @param InsightService $insightService
  26.      * @param Security $security
  27.      */
  28.     public function __construct(ProductService $productServiceInsightService $insightServiceSecurity $security)
  29.     {
  30.         parent::__construct($security);
  31.         $this->productService $productService;
  32.         $this->insightService $insightService;
  33.     }
  34.     /**
  35.      * HomePage Products
  36.      * @Route("/products/services", name="product_homepage")
  37.      * @Route("/products", name="products")
  38.      * @Route("/products/", name="products_slash")
  39.      * @Route("/products/services/", name="product_homepage_slash")
  40.      */
  41.     public function indexAction(SessionInterface $sessionRequest $request)
  42.     {
  43.         if ($request != null && $request->get('removeProfile') != null) {
  44.             $session->remove('productsAndServices');
  45.         }
  46.         $includeActive $this->includeInactive($session);
  47.         $categories $this->getDoctrine()->getRepository(SonataClassificationCategory::class)->findBy(['context' => 'products'], ['position' => 'ASC']);
  48.         $tags $this->getDoctrine()->getRepository(SonataClassificationTag::class)->findBy(['context' => 'user_profiles']);
  49.         /** @noinspection PhpUndefinedMethodInspection */
  50.         $current_profile $session->get('productsAndServices') ? $this->getDoctrine()->getRepository(SonataClassificationTag::class)
  51.             ->findOneBySlug($session->get('productsAndServices')) : null;
  52.         /** @noinspection PhpUndefinedMethodInspection */
  53.         $current_tag $request->get('filter') ? $this->getDoctrine()->getRepository(SonataClassificationTag::class)
  54.             ->findOneBySlug($request->get('filter')) : $current_profile;
  55.         $products $this->productService->getProducts($includeActive);
  56.         /**
  57.          * We retrieve products declined
  58.          *
  59.          * @var SonataClassificationTag $current_tag
  60.          */
  61.         if ($current_tag !== null) {
  62.             $products $this->productService->getProductsDeclined($products$current_tag);
  63.             $session->set('productsAndServices'$current_tag->getSlug());
  64.         }
  65.         $adminUrl null;
  66.         if ($this->security->isGranted("ROLE_ADMIN_PRODUCT_ADMINISTRATOR")) {
  67.             /** @noinspection PhpRouteMissingInspection */
  68.             $adminUrl $this->generateUrl('admin_app_product_list');
  69.         }
  70.         return $this->render('product/homepage.html.twig', [
  71.             'categories' => $categories,
  72.             'current_tag' => $current_tag,
  73.             'products' => $products,
  74.             'tags' => $tags,
  75.             BaseController::PARAM_ADMIN_URL => $adminUrl
  76.         ]);
  77.     }
  78.     /**
  79.      * Display Product By Category
  80.      * @Route("/products/services/content-production", name="product_by_category_content_production")
  81.      * @Route("/products/services/content-production/", name="product_by_category_content_production_slash")
  82.      */
  83.     public function displayByCategoryContentProductionAction(Request $request)
  84.     {
  85.         return $this->displayByCategoryAction($request->getSession(), $request'content-production');
  86.     }
  87.     /**
  88.      * Display Product By Category
  89.      * @Route("/products/services/{category_slug}", name="product_by_category")
  90.      * @Route("/products/services/{category_slug}/", name="product_by_category_slash")
  91.      *
  92.      * @param SessionInterface $session
  93.      * @param Request $request
  94.      * @param string $category_slug
  95.      * @return RedirectResponse|Response
  96.      * @throws ORMException
  97.      */
  98.     public function displayByCategoryAction(SessionInterface $sessionRequest $requeststring $category_slug)
  99.     {
  100.         if ($category_slug == null) {
  101.             return $this->redirectToRoute('product_homepage');
  102.         }
  103.         $includeActive $this->includeInactive($session);
  104.         $categories $this->getDoctrine()->getRepository(SonataClassificationCategory::class)->findBy(['context' => 'products'], ['position' => 'ASC']);
  105.         $current_category $this->getDoctrine()->getRepository(SonataClassificationCategory::class)
  106.             ->findOneBy(['slug' => $category_slug]);
  107.         $tags $this->getDoctrine()->getRepository(SonataClassificationTag::class)->findBy(['context' => 'user_profiles']);
  108.         /** @noinspection PhpUndefinedMethodInspection */
  109.         $current_profile $session->get('productsAndServices') ? $this->getDoctrine()->getRepository(SonataClassificationTag::class)
  110.             ->findOneBySlug($session->get('productsAndServices')) : null;
  111.         /** @noinspection PhpUndefinedMethodInspection */
  112.         $current_tag $request->get('filter') ? $this->getDoctrine()->getRepository(SonataClassificationTag::class)
  113.             ->findOneBySlug($request->get('filter')) : $current_profile;
  114.         $products $this->productService->getProductsByCategory($current_category$includeActive);
  115.         /**
  116.          * @var SonataClassificationTag $current_tag
  117.          * We retrieve products declined
  118.          */
  119.         if ($current_tag !== null) {
  120.             $products $this->productService->getProductsDeclined($products$current_tag);
  121.             $session->set('productsAndServices'$current_tag->getSlug());
  122.         }
  123.         $adminUrl null;
  124.         if ($this->security->isGranted("ROLE_ADMIN_PRODUCT_ADMINISTRATOR")) {
  125.             /** @noinspection PhpRouteMissingInspection */
  126.             $adminUrl $this->generateUrl('admin_app_product_list');
  127.         }
  128.         return $this->render('product/homepage.html.twig', [
  129.             'categories' => $categories,
  130.             'products' => $products,
  131.             'current_category' => $current_category,
  132.             'tags' => $tags,
  133.             'current_tag' => $current_tag
  134.         ]);
  135.     }
  136.     /**
  137.      * Display Product By Category
  138.      * @Route("/products/services/broadcast-services", name="product_by_category_broadcast_services")
  139.      * @Route("/products/services/broadcast-services/", name="product_by_category_broadcast_services_slash")
  140.      */
  141.     public function displayByCategoryBroadcastServicesAction(Request $request)
  142.     {
  143.         return $this->displayByCategoryAction($request->getSession(), $request'broadcast-services');
  144.     }
  145.     /**
  146.      * Display Product By Category
  147.      * @Route("/products/services/content-distribution", name="product_by_category_content_distribution")
  148.      * @Route("/products/services/content-distribution/", name="product_by_category_content_distribution_slash")
  149.      */
  150.     public function displayByCategoryContenDistributionAction(Request $request)
  151.     {
  152.         return $this->displayByCategoryAction($request->getSession(), $request'content-distribution');
  153.     }
  154.     /**
  155.      * Display Product Details
  156.      * @Route("/product-from-id/{productId}", name="product_detail_from_id")
  157.      *
  158.      * @param string $productId
  159.      * @return RedirectResponse
  160.      */
  161.     public function showDetailFromIdAction(string $productId)
  162.     {
  163.         $product $this->productService->findById($productId);
  164.         if ($product != null) {
  165.             return $this->redirectToRoute('product_detail',
  166.                 ['category_slug' => $product->getCategory()->getSlug(), 'product_slug' => $product->getSlug()]);
  167.         }
  168.         return $this->redirectToRoute("product_homepage");
  169.     }
  170.     /**
  171.      * Display Product Details
  172.      * @Route("/products/services/{category_slug}/{product_slug}", name="product_detail")
  173.      *
  174.      * @param SessionInterface $session
  175.      * @param Request $request
  176.      * @param string $category_slug
  177.      * @param string $product_slug
  178.      * @return RedirectResponse|Response
  179.      * @throws ORMException
  180.      */
  181.     public function showDetailAction(SessionInterface $sessionRequest $requeststring $category_slugstring $product_slug)
  182.     {
  183.         if ($request != null && $request->get('removeProfile') != null) {
  184.             $session->remove('productsAndServices');
  185.         }
  186.         /**
  187.          * @var Product $product
  188.          */
  189.         $product $this->productService->findBySlug($product_slug);
  190.         if ($product == null) {
  191.             return $this->redirectToRoute('product_homepage');
  192.         }
  193.         if ($product->getCategory() != null && $product->getCategory()->getSlug() != $category_slug) {
  194.             return $this->redirectToRoute("product_detail",
  195.                 ["category_slug" => $product->getCategory()->getSlug(), "product_slug" => $product_slug]);
  196.         }
  197.         $tagRepository $this->getDoctrine()->getRepository(SonataClassificationTag::class);
  198.         $tags $tagRepository->findBy(['context' => 'user_profiles']);
  199.         $current_tag null;
  200.         /**
  201.          * @var SonataClassificationTag $current_tag
  202.          */
  203.         if ($request != null && $request->get('filter') != null) {
  204.             /** @noinspection PhpUndefinedMethodInspection */
  205.             $current_tag $tagRepository
  206.                 ->findOneBySlug($request->get('filter'));
  207.             /** We retrieve products declined */
  208.             $product $this->productService->getProductDeclinedWithKeyBenefit($product$current_tag);
  209.             if ($current_tag != null) {
  210.                 $session->set('productsAndServices'$current_tag->getSlug());
  211.             }
  212.         } else {
  213.             /** @noinspection PhpUndefinedMethodInspection */
  214.             $current_tag $session->get('productsAndServices') ? $tagRepository
  215.                 ->findOneBySlug($session->get('productsAndServices'))
  216.                 : $tagRepository->findOneBySlug([
  217.                     'context' => 'user_profiles',
  218.                     'name' => 'all'
  219.                 ]);
  220.             $product $this->productService->getProductDeclinedWithKeyBenefit($product$current_tag);
  221.             if ($current_tag != null) {
  222.                 $session->set('productsAndServices'$current_tag->getSlug());
  223.             }
  224.         }
  225.         $relatedInsights $this->insightService->getProductRelatedInsights($product$this->includeInactive($session), 3);
  226.         $adminUrl null;
  227.         if ($this->security->isGranted("ROLE_ADMIN_PRODUCT_ADMINISTRATOR")) {
  228.             /** @noinspection PhpRouteMissingInspection */
  229.             $adminUrl $this->generateUrl('admin_app_product_edit', ['id' => $product->getId()]);
  230.         }
  231.         return $this->render('product/detail.html.twig',
  232.             [
  233.                 'product' => $product,
  234.                 'current_tag' => $current_tag,
  235.                 'relatedInsights' => $relatedInsights,
  236.                 'tags' => $tags,
  237.                 BaseController::PARAM_ADMIN_URL => $adminUrl
  238.             ]);
  239.     }
  240.     /**
  241.      * @Route("/intern/services", name="services_list", options={"expose" = true })
  242.      */
  243.     public function getServicesAction()
  244.     {
  245.         // Exclude product with id 26 = Content Hub
  246.         $services $this->productService->getProductsWithExclusion([26]);
  247.         return $this->render(
  248.             'product/services.html.twig', [
  249.             'services' => $services
  250.         ]);
  251.     }
  252.     /**
  253.      * Content hub service
  254.      * @Route("/products/production-hub", name="product_production_hub")
  255.      * @Route("/products/production-hub/", name="product_production_hub_slash")
  256.      */
  257.     public function productionHubAction()
  258.     {
  259.         return $this->render('product/production-hub.html.twig');
  260.     }
  261.     /**
  262.      * Content hub service
  263.      * @Route("/products/content-hub", name="product_content_hub")
  264.      * @Route("/products/content-hub/", name="product_content_hub_slash")
  265.      */
  266.     public function contentHubAction()
  267.     {
  268.         return $this->render('product/content-hub.html.twig');
  269.     }
  270.     /**
  271.      * Contribution service
  272.      * @Route("/products/contribution", name="product_contribution")
  273.      * @Route("/products/contribution/", name="product_contribution_slash")
  274.      */
  275.     public function contributionAction()
  276.     {
  277.         return $this->render('product/contribution.html.twig');
  278.     }
  279.     /**
  280.      * Distribution service
  281.      * @Route("/products/distribution", name="product_distribution")
  282.      * @Route("/products/distribution/", name="product_distribution_slash")
  283.      */
  284.     public function distributionAction()
  285.     {
  286.         return $this->render('product/distribution.html.twig');
  287.     }
  288.     /**
  289.      * Major events
  290.      * @Route("/products/major-events", name="product_major_events")
  291.      * @Route("/products/major-events/", name="product_major_events_slash")
  292.      */
  293.     public function majorEventsAction()
  294.     {
  295.         return $this->render('product/major-events.html.twig');
  296.     }
  297.     /**
  298.      * Dedicated services
  299.      * @Route("/products/dedicated-services", name="product_dedicated_services")
  300.      * @Route("/products/dedicated-services/", name="product_dedicated_services_slash")
  301.      */
  302.     public function dedicatedServicesAction()
  303.     {
  304.         return $this->render('product/dedicated-services.html.twig');
  305.     }
  306.     /**
  307.      * Aggregation services
  308.      * @Route("/products/aggregation-services", name="product_aggregation_services")
  309.      * @Route("/products/aggregation-services/", name="product_aggregation_services_slash")
  310.      */
  311.     public function aggregationServicesAction()
  312.     {
  313.         return $this->render('product/aggregation-services.html.twig');
  314.     }
  315.     /**
  316.      * Permanent services
  317.      * @Route("/products/permanent-services", name="product_permanent_services")
  318.      * @Route("/products/permanent-services/", name="product_permanent_services_slash")
  319.      */
  320.     public function permanentServicesAction()
  321.     {
  322.         return $this->render('product/permanent-services.html.twig');
  323.     }
  324. }