<?php
namespace App\Controller\Pages\Pages;
use App\Entity\St_Settings;
use App\Entity\Db_Products;
use App\Entity\Gl_Images;
use App\Entity\Db_Categoriesassign;
use App\Entity\Db_Accessories;
use App\Entity\Db_Accesscategory;
use App\Entity\Db_Seotable;
use App\Entity\Db_Categories;
use App\Entity\Db_Cart;
use App\Entity\Db_Contents;
use App\Entity\Db_Accesscategoryassign;
use App\Entity\Db_Categoryaccessassign;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class CategoriesController extends Controller
{
function __construct(SessionInterface $session)
{
$this->lang = (isset($_COOKIE['langFront']) && !empty($_COOKIE['langFront'])) ? $this->lang = $_COOKIE['langFront'] : $this->lang = "HU";
$this->session = $session;
}
/**
* @Route("/category/set-cookie/{categoryId}", name="set-category-cookie")
*/
public function setCookie(Security $security, Request $request, $categoryId) {
$c = $this->getDoctrine()->getRepository(Db_Categories::class)->find($categoryId);
if ( $request->request->all() ) {
setcookie("access", json_encode($request->request->get("access")), time() + (86400 * 30), "/kategoria/".$c->getUrlName()."/oldal/1");
return $this->redirect("/kategoria/".$c->getUrlName()."/oldal/1");
} else {
setcookie("access", NULL, time() + (86400 * 30), "/kategoria/".$c->getUrlName()."/oldal/1");
return $this->redirect("/kategoria/".$c->getUrlName()."/oldal/1");
}
}
/**
* @Route("/search/set-cookie/{urlname}", name="set-search-cookie")
*/
public function setCookieSearch(Security $security, Request $request, $urlname) {
if ( $request->request->all() ) {
setcookie("access", json_encode($request->request->get("access")), time() + (86400 * 30), "/kereso/".$urlname."/oldal/1");
return $this->redirect("/kereso/".$urlname."/oldal/1");
} else {
setcookie("access", NULL, time() + (86400 * 30), "/kereso/".$urlname."/oldal/1");
return $this->redirect("/kereso/".$urlname."/oldal/1");
}
}
/**
* @Route("/kategoria/{urlName}/oldal/{actualPage}", name="get-categories-page")
*/
public function getCategoriesPage(Security $security, $urlName, $actualPage, Request $request) {
//Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if ( $request->cookies->get("access") ) {
$cookie = $request->cookies->get("access");
} else {
$cookie = NULL;
}
$category = $this->getDoctrine()->getRepository(Db_Categories::class)->findOneBy(["UrlName" => $urlName]);
$products = $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findByProductAndImagePerPage($actualPage, $category->getID(), $cookie);
$allProducts = $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findByProductAndImageAll($category->getID(), $cookie);
$categories = $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
$allPage = count($allProducts);
if ( isset( $_COOKIE['paginationCookie'] ) && !empty($_COOKIE['paginationCookie']) ) {
$perPage = $_COOKIE['paginationCookie'];
} else {
$perPage = 20;
}
$allPage = ceil($allPage/$perPage);
$accessArray = array();
$accessories = $this->getDoctrine()->getRepository(Db_Categoryaccessassign::class)->findBy(["categoryid" => $category->getID()]);
$i = 0;
foreach( $accessories as $value ) {
$accessArray[$i] = array(
"accessCategory" => $value->getAccesscategoryid(),
"accessElements" => $this->getDoctrine()->getRepository(Db_Accessories::class)->findBy(["AccessCategory" => $value->getAccesscategoryid()->getID()]),
);
$i++;
}
return $this->render("templates/default/pages/category.html.twig", array(
"category" => $category,
"seo"=> $this->getDoctrine()->getRepository(Db_Seotable::class)->findSeoDataByPageIDAndType($category->getID(), "Category"),
"products" => $products,
"categories" => $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage(),
"subCategories" => $this->getDoctrine()->getRepository(Db_Categories::class)->findBy(["Visible" => "y", "ParentID" => $category->getID()]),
"newProducts" => $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy(["CategoryID" => $category->getID()],["ID" => "DESC"],5),
"allPage" => $allPage,
"actualPage" => $actualPage,
"accessArray" => $accessArray,
"allProducts" => count($allProducts),
));
}
/**
* @Route("/termekek/{urlname}", name="get-product-page")
*/
public function getProductPage(Security $security, $urlname, Request $request) {
//Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$product = $this->getDoctrine()->getRepository(Db_Products::class)->findOneBy(["UrlName" => $urlname]);
if ( $request->cookies->get("related") ) {
$array = json_decode($request->cookies->get("related"));
if ( !in_array($product->getID(), $array) ) {
array_unshift($array, $product->getId());
setcookie("related", json_encode($array), time() + ((86400 * 30)*12), "/");
}
} else {
setcookie("related", json_encode(array()), time() + ((86400 * 30)*12), "/");
}
if ( isset($_COOKIE['orderCookieId']) && !empty($_COOKIE['orderCookieId']) ) {
$cartElements = $this->getDoctrine()->getRepository(Db_Cart::class)->findBy(['CookieID' => $_COOKIE['orderCookieId']]);
} else {
$cartElements = array();
}
$seo = $this->getDoctrine()->getRepository(Db_Seotable::class)->findSeoDataByPageIDAndType($product->getID(), "Product");
$categories = $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
$productCategories = $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy(["ProductID" => $product->getID()]);
$gallery = $this->getDoctrine()->getRepository(Gl_Images::class)->findBy(["ProductID" => $product->getID()]);
$accessories = $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findAllCategoryByProduct($product->getID());
$accessArray = array();
$i = 0;
foreach ( $accessories as $value ) {
$accessArray[$i] = array(
"categoryName" => $value->getCategoryId()->getNameHU(),
"accessValues" => $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findBy(["categoryid" => $value->getCategoryId()->getId(),"productid" => $product->getID()]),
);
$i++;
}
$content = new Db_Contents();
$content->setTitle($product->getNameHU());
return $this->render("templates/default/pages/product.html.twig", array(
"product" => $product,
"seo" => $seo,
"categories" => $categories,
"productCategories" => $productCategories,
"gallery" => $gallery,
"accessArray" => $accessArray,
"cartElements" => $cartElements,
"content" => $content,
"pages" => $this->getDoctrine()->getRepository(Db_Contents::class)->findBy(['TypeID' => 7, "Visible" => "y", "ParentID" => ["", NULL]],["Short" => "ASC"]),
));
}
/**
* @Route("/{categoryUrl}/{urlname}", name="get-product-page-category")
*/
public function getProductPageCategory(Security $security, $urlname, Request $request, $categoryUrl) {
//Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if ($urlname == "biztonsag") {
return $this->redirect("/biztonsag");
}
$product = $this->getDoctrine()->getRepository(Db_Products::class)->findOneBy(["UrlName" => $urlname]);
if ( $request->cookies->get("related") ) {
$array = json_decode($request->cookies->get("related"));
if ( !in_array($product->getID(), $array) ) {
array_unshift($array, $product->getId());
setcookie("related", json_encode($array), time() + ((86400 * 30)*12), "/");
}
} else {
setcookie("related", json_encode(array()), time() + ((86400 * 30)*12), "/");
}
if ( isset($_COOKIE['orderCookieId']) && !empty($_COOKIE['orderCookieId']) ) {
$cartElements = $this->getDoctrine()->getRepository(Db_Cart::class)->findBy(['CookieID' => $_COOKIE['orderCookieId']]);
} else {
$cartElements = array();
}
$seo = $this->getDoctrine()->getRepository(Db_Seotable::class)->findSeoDataByPageIDAndType($product->getID(), "Product");
$category = $this->getDoctrine()->getRepository(Db_Categories::class)->findOneBy(["UrlName" => $categoryUrl]);
$categories = $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
$productCategories = $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy(["ProductID" => $product->getID()]);
$gallery = $this->getDoctrine()->getRepository(Gl_Images::class)->findBy(["ProductID" => $product->getID()]);
$accessories = $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findAllCategoryByProduct($product->getID());
$accessArray = array();
$i = 0;
foreach ( $accessories as $value ) {
$accessArray[$i] = array(
"categoryName" => $value->getCategoryId()->getNameHU(),
"accessValues" => $this->getDoctrine()->getRepository(Db_Accesscategoryassign::class)->findBy(["categoryid" => $value->getCategoryId()->getId(),"productid" => $product->getID()]),
);
$i++;
}
$content = new Db_Contents();
$content->setTitle($product->getNameHU());
return $this->render("templates/default/pages/product.html.twig", array(
"product" => $product,
"seo" => $seo,
"categories" => $categories,
"productCategories" => $productCategories,
"gallery" => $gallery,
"accessArray" => $accessArray,
"category" => $category,
"cartElements" => $cartElements,
"content" => $content,
"pages" => $this->getDoctrine()->getRepository(Db_Contents::class)->findBy(['TypeID' => 7, "Visible" => "y", "ParentID" => ["", NULL]],["Short" => "ASC"]),
));
}
/**
* @Route("/kereso", name="get-search-page")
*/
public function getProductSearch(Security $security, Request $request) {
return $this->redirect("/kereso/".$request->query->get("search")."/oldal/1");
}
/**
* @Route("/kereso/{urlname}/oldal/{actualPage}", name="get-search-page-per-page")
*/
public function getProductSearchPerPage(Security $security, $urlname, $actualPage, Request $request) {
//Beállítjuk az adott oldalt header adatait, hogy ne cacheljen.
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if ( $request->cookies->get("access") ) {
$cookie = $request->cookies->get("access");
} else {
$cookie = NULL;
}
$products = $this->getDoctrine()->getRepository(Db_Products::class)->findByProductAndImagePerPageBySearch($actualPage, $urlname, $cookie);
$allProducts = $this->getDoctrine()->getRepository(Db_Products::class)->findByProductAndImageBySearchAll($urlname, $cookie);
$categories = $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage();
$allPage = count($allProducts);
if ( isset( $_COOKIE['paginationCookie'] ) && !empty($_COOKIE['paginationCookie']) ) {
$perPage = $_COOKIE['paginationCookie'];
} else {
$perPage = 20;
}
$allPage = ceil($allPage/$perPage);
$accessArray = array();
$accessories = $this->getDoctrine()->getRepository(Db_Accesscategory::class)->findAll();
$i = 0;
foreach( $accessories as $value ) {
$accessArray[$i] = array(
"accessCategory" => $value,
"accessElements" => $this->getDoctrine()->getRepository(Db_Accessories::class)->findBy(["AccessCategory" => $value->getID()]),
);
$i++;
}
return $this->render("templates/default/pages/search.html.twig", array(
"products" => $products,
"categories" => $this->getDoctrine()->getRepository(Db_Categories::class)->findAllCategoryAndImage(),
"newProducts" => $this->getDoctrine()->getRepository(Db_Categoriesassign::class)->findBy([],["ID" => "DESC"],5),
"allPage" => $allPage,
"actualPage" => $actualPage,
"accessArray" => $accessArray,
"allProducts" => count($allProducts),
"urlname" => $urlname,
));
}
/**
* @Route("/teszt-cookie/related/{max}", name="get-search-page-related")
*/
public function getRelatedProducts(Security $security, Request $request, $max) {
$cookie = $request->cookies->get("related");
if ( $cookie ) {
$array = json_decode($cookie);
$inArray = implode(",",$array);
$relatedProducts = $this->getDoctrine()->getRepository(Db_Products::class)->getRelatedProducts($inArray, $max);
} else {
return new Response("Jelenleg nem találhatóak megtekintett termékek!");
}
}
}