src/Controller/Pages/Pages/CategoriesController.php line 244

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Pages\Pages;
  3. use App\Entity\St_Settings;
  4. use App\Entity\Db_Products;
  5. use App\Entity\Gl_Images;
  6. use App\Entity\Db_Categoriesassign;
  7. use App\Entity\Db_Accessories;
  8. use App\Entity\Db_Accesscategory;
  9. use App\Entity\Db_Seotable;
  10. use App\Entity\Db_Categories;
  11. use App\Entity\Db_Cart;
  12. use App\Entity\Db_Contents;
  13. use App\Entity\Db_Accesscategoryassign;
  14. use App\Entity\Db_Categoryaccessassign;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Bundle\FrameworkBundle\Controller\Controller;    
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Security\Core\Security;
  20. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  21.     class CategoriesController extends Controller
  22.     {
  23.         
  24.         
  25.         function __construct(SessionInterface $session)
  26.         {
  27.             
  28.            
  29.             $this->lang = (isset($_COOKIE['langFront']) && !empty($_COOKIE['langFront'])) ? $this->lang $_COOKIE['langFront'] : $this->lang "HU";
  30.             $this->session $session;
  31.             
  32.         }
  33.         /**
  34.         * @Route("/category/set-cookie/{categoryId}", name="set-category-cookie")
  35.         */
  36.         public function setCookie(Security $securityRequest $request$categoryId) {
  37.             $c $this->getDoctrine()->getRepository(Db_Categories::class)->find($categoryId);
  38.             if ( $request->request->all() ) {
  39.                 setcookie("access"json_encode($request->request->get("access")), time() + (86400 30), "/kategoria/".$c->getUrlName()."/oldal/1"); 
  40.                 return $this->redirect("/kategoria/".$c->getUrlName()."/oldal/1");
  41.             } else {
  42.                 setcookie("access"NULLtime() + (86400 30), "/kategoria/".$c->getUrlName()."/oldal/1"); 
  43.                 return $this->redirect("/kategoria/".$c->getUrlName()."/oldal/1");
  44.             }
  45.         }
  46.         /**
  47.         * @Route("/search/set-cookie/{urlname}", name="set-search-cookie")
  48.         */
  49.         public function setCookieSearch(Security $securityRequest $request$urlname) {
  50.             
  51.             if ( $request->request->all() ) {
  52.                 setcookie("access"json_encode($request->request->get("access")), time() + (86400 30), "/kereso/".$urlname."/oldal/1"); 
  53.                 return $this->redirect("/kereso/".$urlname."/oldal/1");
  54.             } else {
  55.                 setcookie("access"NULLtime() + (86400 30), "/kereso/".$urlname."/oldal/1"); 
  56.                 return $this->redirect("/kereso/".$urlname."/oldal/1");
  57.             }
  58.         }
  59.        
  60.         /**
  61.         * @Route("/kategoria/{urlName}/oldal/{actualPage}", name="get-categories-page")
  62.         */
  63.         public function getCategoriesPage(Security $security$urlName$actualPageRequest $request) {
  64.             //Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
  65.             header("Expires: 0");
  66.             header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
  67.             header("Cache-Control: no-store, no-cache, must-revalidate");
  68.             header("Cache-Control: post-check=0, pre-check=0"false);
  69.             header("Pragma: no-cache");
  70.             if ( $request->cookies->get("access") ) {
  71.                 $cookie $request->cookies->get("access");
  72.             } else {
  73.                 $cookie NULL;
  74.             }
  75.             $category $this->getDoctrine()->getRepository(Db_Categories::class)->findOneBy(["UrlName" => $urlName]);
  76.             $products $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findByProductAndImagePerPage($actualPage$category->getID(), $cookie);
  77.             $allProducts $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findByProductAndImageAll($category->getID(), $cookie);
  78.             $categories $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
  79.             $allPage count($allProducts);
  80.             if ( isset( $_COOKIE['paginationCookie'] ) && !empty($_COOKIE['paginationCookie']) ) {
  81.                 $perPage $_COOKIE['paginationCookie'];
  82.             } else {
  83.                 $perPage 20;
  84.             }
  85.             $allPage ceil($allPage/$perPage);
  86.                $accessArray = array();
  87.                $accessories $this->getDoctrine()->getRepository(Db_Categoryaccessassign::class)->findBy(["categoryid" => $category->getID()]);
  88.                $i 0;
  89.                foreach( $accessories as $value ) {
  90.                    $accessArray[$i] = array(
  91.                        "accessCategory" => $value->getAccesscategoryid(),
  92.                        "accessElements" => $this->getDoctrine()->getRepository(Db_Accessories::class)->findBy(["AccessCategory" => $value->getAccesscategoryid()->getID()]),
  93.                    );
  94.                    $i++;
  95.                }
  96.             return $this->render("templates/default/pages/category.html.twig", array(
  97.                 "category" => $category,
  98.                 "seo"=> $this->getDoctrine()->getRepository(Db_Seotable::class)->findSeoDataByPageIDAndType($category->getID(), "Category"),
  99.                 "products" => $products,
  100.                 "categories" => $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage(),
  101.                 "subCategories"    => $this->getDoctrine()->getRepository(Db_Categories::class)->findBy(["Visible" => "y""ParentID" => $category->getID()]),
  102.                 "newProducts" => $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy(["CategoryID" => $category->getID()],["ID" => "DESC"],5),
  103.                 "allPage" => $allPage,
  104.                 "actualPage" => $actualPage,
  105.                 "accessArray" => $accessArray,
  106.                 "allProducts" => count($allProducts),
  107.             ));
  108.         }
  109.         /**
  110.         * @Route("/termekek/{urlname}", name="get-product-page")
  111.         */
  112.         public function getProductPage(Security $security$urlnameRequest $request) {
  113.             //Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
  114.             header("Expires: 0");
  115.             header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
  116.             header("Cache-Control: no-store, no-cache, must-revalidate");
  117.             header("Cache-Control: post-check=0, pre-check=0"false);
  118.             header("Pragma: no-cache");
  119.             
  120.             $product $this->getDoctrine()->getRepository(Db_Products::class)->findOneBy(["UrlName" => $urlname]);
  121.             if ( $request->cookies->get("related") ) {
  122.                 $array json_decode($request->cookies->get("related"));
  123.                 if ( !in_array($product->getID(), $array) ) {
  124.                     array_unshift($array$product->getId());
  125.                     setcookie("related"json_encode($array), time() + ((86400 30)*12), "/"); 
  126.                 }
  127.             } else {
  128.                 setcookie("related"json_encode(array()), time() + ((86400 30)*12), "/"); 
  129.             }
  130.             if ( isset($_COOKIE['orderCookieId']) && !empty($_COOKIE['orderCookieId']) ) {
  131.                 $cartElements $this->getDoctrine()->getRepository(Db_Cart::class)->findBy(['CookieID' => $_COOKIE['orderCookieId']]);
  132.             } else {
  133.                 $cartElements = array();
  134.             }
  135.             
  136.             
  137.             $seo $this->getDoctrine()->getRepository(Db_Seotable::class)->findSeoDataByPageIDAndType($product->getID(), "Product");
  138.             $categories $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
  139.             $productCategories $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy(["ProductID" => $product->getID()]);
  140.             $gallery $this->getDoctrine()->getRepository(Gl_Images::class)->findBy(["ProductID" => $product->getID()]);
  141.             
  142.             $accessories $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findAllCategoryByProduct($product->getID());
  143.             
  144.             $accessArray = array();
  145.             $i 0;
  146.             foreach ( $accessories as $value ) {
  147.                 $accessArray[$i] = array(
  148.                     "categoryName" => $value->getCategoryId()->getNameHU(),
  149.                     "accessValues" => $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findBy(["categoryid" => $value->getCategoryId()->getId(),"productid" => $product->getID()]),
  150.                 );
  151.                 $i++;
  152.             }
  153.             $content = new Db_Contents();
  154.             $content->setTitle($product->getNameHU());
  155.             return $this->render("templates/default/pages/product.html.twig", array(
  156.                 "product" => $product,
  157.                 "seo" => $seo,
  158.                 "categories" => $categories,
  159.                 "productCategories" => $productCategories,
  160.                 "gallery" => $gallery,
  161.                 "accessArray" => $accessArray,
  162.                 "cartElements" => $cartElements,
  163.                 "content" => $content,
  164.                 "pages" => $this->getDoctrine()->getRepository(Db_Contents::class)->findBy(['TypeID' => 7"Visible" => "y""ParentID" => [""NULL]],["Short" => "ASC"]),
  165.             ));
  166.         }
  167.         /**
  168.         * @Route("/{categoryUrl}/{urlname}", name="get-product-page-category")
  169.         */
  170.         public function getProductPageCategory(Security $security$urlnameRequest $request$categoryUrl) {
  171.             //Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
  172.             header("Expires: 0");
  173.             header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
  174.             header("Cache-Control: no-store, no-cache, must-revalidate");
  175.             header("Cache-Control: post-check=0, pre-check=0"false);
  176.             header("Pragma: no-cache");
  177.             if ($urlname == "biztonsag") {
  178.                 return $this->redirect("/biztonsag");
  179.             }
  180.             $product $this->getDoctrine()->getRepository(Db_Products::class)->findOneBy(["UrlName" => $urlname]);
  181.             if ( $request->cookies->get("related") ) {
  182.                 $array json_decode($request->cookies->get("related"));
  183.                 if ( !in_array($product->getID(), $array) ) {
  184.                     array_unshift($array$product->getId());
  185.                     setcookie("related"json_encode($array), time() + ((86400 30)*12), "/"); 
  186.                 }
  187.             } else {
  188.                 setcookie("related"json_encode(array()), time() + ((86400 30)*12), "/"); 
  189.             }
  190.             if ( isset($_COOKIE['orderCookieId']) && !empty($_COOKIE['orderCookieId']) ) {
  191.                 $cartElements $this->getDoctrine()->getRepository(Db_Cart::class)->findBy(['CookieID' => $_COOKIE['orderCookieId']]);
  192.             } else {
  193.                 $cartElements = array();
  194.             }
  195.             $seo $this->getDoctrine()->getRepository(Db_Seotable::class)->findSeoDataByPageIDAndType($product->getID(), "Product");
  196.             $category $this->getDoctrine()->getRepository(Db_Categories::class)->findOneBy(["UrlName" => $categoryUrl]);
  197.             $categories $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
  198.             $productCategories $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy(["ProductID" => $product->getID()]);
  199.             $gallery $this->getDoctrine()->getRepository(Gl_Images::class)->findBy(["ProductID" => $product->getID()]);
  200.             
  201.             $accessories $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findAllCategoryByProduct($product->getID());
  202.             
  203.             $accessArray = array();
  204.             $i 0;
  205.             foreach ( $accessories as $value ) {
  206.                 $accessArray[$i] = array(
  207.                     "categoryName" => $value->getCategoryId()->getNameHU(),
  208.                     "accessValues" => $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findBy(["categoryid" => $value->getCategoryId()->getId(),"productid" => $product->getID()]),
  209.                 );
  210.                 $i++;
  211.             }
  212.             $content = new Db_Contents();
  213.             $content->setTitle($product->getNameHU());
  214.             return $this->render("templates/default/pages/product.html.twig", array(
  215.                 "product" => $product,
  216.                 "seo" => $seo,
  217.                 "categories" => $categories,
  218.                 "productCategories" => $productCategories,
  219.                 "gallery" => $gallery,
  220.                 "accessArray" => $accessArray,
  221.                 "category" => $category,
  222.                 "cartElements" => $cartElements,
  223.                 "content" => $content,
  224.                 "pages" => $this->getDoctrine()->getRepository(Db_Contents::class)->findBy(['TypeID' => 7"Visible" => "y""ParentID" => [""NULL]],["Short" => "ASC"]),
  225.             ));
  226.         }
  227.         /**
  228.         * @Route("/kereso", name="get-search-page")
  229.         */
  230.         public function getProductSearch(Security $securityRequest $request) {
  231.             return $this->redirect("/kereso/".$request->query->get("search")."/oldal/1");
  232.         }
  233.         /**
  234.         * @Route("/kereso/{urlname}/oldal/{actualPage}", name="get-search-page-per-page")
  235.         */
  236.         public function getProductSearchPerPage(Security $security$urlname$actualPageRequest $request) {
  237.             //Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
  238.             header("Expires: 0");
  239.             header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
  240.             header("Cache-Control: no-store, no-cache, must-revalidate");
  241.             header("Cache-Control: post-check=0, pre-check=0"false);
  242.             header("Pragma: no-cache");
  243.             
  244.             if ( $request->cookies->get("access") ) {
  245.                 $cookie $request->cookies->get("access");
  246.             } else {
  247.                 $cookie NULL;
  248.             }
  249.             
  250.             $products $this->getDoctrine()->getRepository(Db_Products::class)->findByProductAndImagePerPageBySearch($actualPage$urlname$cookie);
  251.             $allProducts $this->getDoctrine()->getRepository(Db_Products::class)->findByProductAndImageBySearchAll($urlname$cookie);
  252.             $categories $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
  253.             $allPage count($allProducts);
  254.             if ( isset( $_COOKIE['paginationCookie'] ) && !empty($_COOKIE['paginationCookie']) ) {
  255.                 $perPage $_COOKIE['paginationCookie'];
  256.             } else {
  257.                 $perPage 20;
  258.             }
  259.             $allPage ceil($allPage/$perPage);
  260.                $accessArray = array();
  261.                $accessories $this->getDoctrine()->getRepository(Db_Accesscategory::class)->findAll();
  262.                $i 0;
  263.                foreach( $accessories as $value ) {
  264.                    $accessArray[$i] = array(
  265.                        "accessCategory" => $value,
  266.                        "accessElements" => $this->getDoctrine()->getRepository(Db_Accessories::class)->findBy(["AccessCategory" => $value->getID()]),
  267.                    );
  268.                    $i++;
  269.                }
  270.             return $this->render("templates/default/pages/search.html.twig", array(
  271.                 
  272.                 
  273.                 "products" => $products,
  274.                 "categories" => $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage(),
  275.                 "newProducts" => $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy([],["ID" => "DESC"],5),
  276.                 "allPage" => $allPage,
  277.                 "actualPage" => $actualPage,
  278.                 "accessArray" => $accessArray,
  279.                 "allProducts" => count($allProducts),
  280.                 "urlname" => $urlname,
  281.             ));
  282.         }
  283.         /**
  284.         * @Route("/teszt-cookie/related/{max}", name="get-search-page-related")
  285.         */
  286.         public function getRelatedProducts(Security $securityRequest $request$max) {
  287.             $cookie $request->cookies->get("related");
  288.             if ( $cookie ) {
  289.                 $array json_decode($cookie);
  290.                 $inArray implode(",",$array);
  291.                 $relatedProducts $this->getDoctrine()->getRepository(Db_Products::class)->getRelatedProducts($inArray$max); 
  292.             } else {
  293.                 return new Response("Jelenleg nem találhatóak megtekintett termékek!");
  294.             }
  295.         }
  296.     }