<?php
namespace App\Controller;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Serializer;
use App\Entity\Category;
use App\Entity\Currency;
use App\Entity\Gallery;
use App\Entity\GalleryItem;
use App\Entity\Eshop;
use App\Entity\Module;
use App\Entity\Order;
use App\Entity\OrderItem;
use App\Entity\Product;
use App\Entity\Contact;
use App\Entity\User;
use Symfony\Component\Finder\Finder;
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
use App\Entity\Gallery3D;
use App\Entity\FreeWorld3D;
use App\Entity\Eshop3D;
use Symfony\Contracts\Translation\TranslatorInterface;
class Eshop3DController extends DefaultController
{
protected ManagerRegistry $doctrine;
protected TranslatorInterface $translator;
protected $appKernel;
public function __construct(ManagerRegistry $doctrine,
TranslatorInterface $translator,
KernelInterface $appKernel)
{
$this->doctrine = $doctrine;
$this->translator = $translator;
$this->appKernel = $appKernel;
}
protected $dynamicEntityManager;
protected $currentEshop;
/**
* @Route("/eshop3d", name="eshop3dHome")
*/
public function indexAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we render data */
return $this->render('eshopHome.html.php',
array('headerData' => $this -> getPageHeader($request)
)
);
}
/**
* @Route("/eshop3d/{eshopId}", name="eshop3d")
*/
public function eshop3dAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$logger = $this->getLogger(null, 'e-shop 3D');
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exists.');
return $this->redirectToRoute('eshopHome');
}
/* we get current 3D eshop */
$eshop3D = $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
$userDirs = $this->getUserFolderPathsFromUserId($user->getUserId());
//isModule Pack Sale
$module = $em->getRepository(Module::class)->getModule(42);
$isPackSaleModule = $em->getRepository(User::class)->userHasModule($user, $module);
//print('<br>qqw eshop: ');
//\Doctrine\Common\Util\Debug::dump($eshop);
$eshopId = $eshop->getEshopId();
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
$childNodeImages = array();
$categoryImages = array();
$products = array();
$categoryProducts = array();
$categoryProductImages = array();
$productListTitles = array();
$productDescriptions = array();
$categoryProductPrices = array();
/* we get parent gallery items */
$textureItemCollection = null;
if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
$textureItemCollection = $dem->getRepository(GalleryItem::class)->getGalleryItemList($eshop3D->getTextureGallery()->getGalleryId());
}
// print('<br>QQW locale: '.$session->get('lang')->getLangKey());
foreach($rootNodes as $cat) {
if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
$catId = $cat->getCategoryId();
$productList = array();
$childNodes[] = $cat;
$childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'category_'.$catId, 400, 60, 40, 48);
$cat->setLocale($session->get('lang')->getLangKey());
$dem->refresh($cat);
// print('<br>QQW category: '.$cat->getCategoryName());
// \Doctrine\Common\Util\Debug::dump($cat);
//getImageFromText($text="", $colorType="default", $imagePath, $imageWebPath, $countCharactersInLine = 30, $imageName="image_name", $imageWidth=400, $imageHeight=60, $fontSize=40, $positionY = 40)
if($cat->getImage1() != "") {
$categoryImagePath = $userDirs['web'].'/images/'.$cat->getImage1();
} else {
$categoryImagePath = '';
}
$categoryImages[$catId] = $categoryImagePath;
/* we get products in the cateory */
$productList = $dem->getRepository(Product::class)->getProductListByCategory($catId);
/* we generate images for product titles */
foreach($productList as $product) {
$productId = $product->getProductId();
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
}
// print('<br>QQW productList in category: '.$cat->getCategoryName());
// \Doctrine\Common\Util\Debug::dump($productList);
/* we display products from subfolders */
if(!empty($eshop->isDisplayProductsFromSubfolders()) && $eshop->isDisplayProductsFromSubfolders() == true) {
$catChildNodes = $cat->getChildren();
foreach($catChildNodes as $catChild) {
$subCatId = $catChild->getCategoryId();
$nodeProductList = $dem->getRepository(Product::class)->getProductListByCategory($catChild->getCategoryId());
//$productList = array_merge($productList, $nodeProductList);
$categoryProducts[$catChild->getCategoryId()] = $nodeProductList;
$productIds = [];
foreach($nodeProductList as $product) {
$productId = $product->getProductId();
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
$productIds[] = $productId;
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
$categoryProductPrices[$subCatId] = $productPriceList;
//$logger->notice('QQW subCatId: '.,;
//$logger->notice('QQW subCat '.$catChild->getCategoryName().' prices:', ['subCatPrices' => count($productPriceList)]);
}
/*
print('<br>-------------------QQW DisplayProductsFromSubfolders: ');
\Doctrine\Common\Util\Debug::dump($productList);
*/
}
$categoryProducts[$cat->getCategoryId()] = $productList;
/* we generate images for product titles */
$productIds = [];
foreach($productList as $product) {
$productId = $product->getProductId();
$productIds[] = $productId;
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
$categoryProductPrices[$cat->getCategoryId()] = $productPriceList;
//$logger->notice('QQW Cat '.$cat->getCategoryName().' prices:', ['catPrices' => count($productPriceList)]);
}
}
/*
print('<hr>QQW categoryProductPrices: ');
\Doctrine\Common\Util\Debug::dump($categoryProductPrices);
$logger->notice('QQW Hallo logger e-shop 3D: ');
foreach($productListTitles as $tit){
$logger->notice('tit: '.$tit);
}
*/
/*
print('<hr>QQW productList: ');
\Doctrine\Common\Util\Debug::dump($categoryProducts);
print('<hr>');
*/
//die();
if($_SERVER['HTTP_HOST'] != 'localhost') {
$urlPattern = "http://www.easycommerc.com/";
} else {
$urlPattern = "http://localhost/alliancemarkets2/web/";
}
$debug = 1;
if($request->request->get('header')==='false') {
$isHeader = false;
} else {
$isHeader = true;
}
if(!empty($request->request->get('is_footer')) && $request->request->get('footer')=='false') {
$isFooter = false;
} else {
$isFooter = true;
}
if(!empty($request->get('isStartGuide'))) {
$isStartGuide = $request->get('isStartGuide');
//print('isStartGuide: '.$request->get('isStartGuide'));
} else {
$isStartGuide = false;
//print('isStartGuide: FALSE');
}
if(!empty($request->request->get('debug'))) {
//if(!empty($debug)) {
/* we render HTML */
$response = $this->render('eshop3D.html.php',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'userDirs' => $userDirs,
'childNodes' => $childNodes,
'childNodeImages' => $childNodeImages,
'categoryImages' => $categoryImages,
'productListTitles' => $productListTitles,
'productDescriptions' => $productDescriptions,
'products' => $products,
'categoryProducts' => $categoryProducts,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'urlPattern' => $urlPattern,
'textureItemCollection' => $textureItemCollection,
'isFooter' => $isFooter,
'isHeader' => $isHeader
)
);
} else {
/* we render virtual reality data */
$response = $this->render('eshop3D/eshop3D.html.twig',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'userDirs' => $userDirs,
'childNodes' => $childNodes,
'childNodeImages' => $childNodeImages,
'categoryImages' => $categoryImages,
'productListTitles' => $productListTitles,
'productDescriptions' => $productDescriptions,
'products' => $products,
'categoryProducts' => $categoryProducts,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'logger' => $logger,
'urlPattern' => $urlPattern,
'textureItemCollection' => $textureItemCollection,
'categoryProductPrices' => $categoryProductPrices,
'isPackSaleModule' => $isPackSaleModule,
'eshop3D' => $eshop3D,
'isStartGuide' => $isStartGuide
)
);
/*
$response = new Response(
$this->renderView('eshop3D.vrml.php',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'eshop' => $eshop,
'user' => $user,
'userDirs' => $userDirs,
'childNodes' => $childNodes,
'childNodeImages' => $childNodeImages,
'categoryImages' => $categoryImages,
'productListTitles' => $productListTitles,
'productDescriptions' => $productDescriptions,
'products' => $products,
'categoryProducts' => $categoryProducts,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'logger' => $logger,
'urlPattern' => $urlPattern,
)
), 200
);
*/
// $response->headers->set('Content-Type', 'model/vrml');
}
return $response;
}
/**
* @Route("/api/eshop3d/{eshopId}", name="apiEshop3d")
*/
public function getEshop3d(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$logger = $this->getLogger(null, 'e-shop 3D');
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exists.');
return $this->redirectToRoute('eshopHome');
}
/* we get current 3D eshop */
$eshop3D = $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
$userDirs = $this->getUserFolderPathsFromUserId($user->getUserId());
//isModule Pack Sale
$module = $em->getRepository(Module::class)->getModule(42);
$isPackSaleModule = $em->getRepository(User::class)->userHasModule($user, $module);
//print('<br>qqw eshop: ');
//\Doctrine\Common\Util\Debug::dump($eshop);
$eshopId = $eshop->getEshopId();
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
$childNodeImages = array();
$categoryImages = array();
$products = array();
$categoryProducts = array();
$categoryProductImages = array();
$productListTitles = array();
$productDescriptions = array();
$categoryProductPrices = array();
/* we get parent gallery items */
$textureItemCollection = null;
if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
$textureItemCollection = $dem->getRepository(GalleryItem::class)->getGalleryItemList($eshop3D->getTextureGallery()->getGalleryId());
}
foreach($rootNodes as $cat) {
if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
$catId = $cat->getCategoryId();
$productList = array();
$childNodes[] = $cat;
$childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'category_'.$catId, 400, 60, 40, 48);
//getImageFromText($text="", $colorType="default", $imagePath, $imageWebPath, $countCharactersInLine = 30, $imageName="image_name", $imageWidth=400, $imageHeight=60, $fontSize=40, $positionY = 40)
if($cat->getImage1() != "") {
$categoryImagePath = $userDirs['web'].'/images/'.$cat->getImage1();
} else {
$categoryImagePath = '';
}
$categoryImages[$catId] = $categoryImagePath;
/* we get products in the cateory */
$productList = $dem->getRepository(Product::class)->getProductListByCategory($catId);
/* we generate images for product titles */
foreach($productList as $product) {
$productId = $product->getProductId();
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
}
/*
print('<br>QQW productList in category: '.$cat->getCategoryName());
\Doctrine\Common\Util\Debug::dump($productList);
*/
/* we display products from subfolders */
if(!empty($eshop->getDisplayProductsFromSubfolders()) && $eshop->getDisplayProductsFromSubfolders() == true) {
$catChildNodes = $cat->getChildren();
foreach($catChildNodes as $catChild) {
$subCatId = $catChild->getCategoryId();
$nodeProductList = $dem->getRepository(Product::class)->getProductListByCategory($catChild->getCategoryId());
//$productList = array_merge($productList, $nodeProductList);
$categoryProducts[$catChild->getCategoryId()] = $nodeProductList;
$productIds = [];
foreach($nodeProductList as $product) {
$productId = $product->getProductId();
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
$productIds[] = $productId;
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
$categoryProductPrices[$subCatId] = $productPriceList;
//$logger->notice('QQW subCatId: '.,;
//$logger->notice('QQW subCat '.$catChild->getCategoryName().' prices:', ['subCatPrices' => count($productPriceList)]);
}
/*
print('<br>-------------------QQW DisplayProductsFromSubfolders: ');
\Doctrine\Common\Util\Debug::dump($productList);
*/
}
$categoryProducts[$cat->getCategoryId()] = $productList;
/* we generate images for product titles */
$productIds = [];
foreach($productList as $product) {
$productId = $product->getProductId();
$productIds[] = $productId;
$title = $this->getImageFromText($product->getProductName(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 30, 'product_'.$productId.'_title', 500, 40, 25, 30);
$description = $this->getImageFromText($product->getProductDescription(), 'orange-black', $userDirs['images'], $userDirs['web'].'/images', 50, 'product_'.$productId.'_description', 500, 27, 12, 40);
$productListTitles[$productId] = $title;
$productDescriptions[$productId] = $description;
$products[$productId] = $product;
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
}
$categoryProductPrices[$cat->getCategoryId()] = $productPriceList;
//$logger->notice('QQW Cat '.$cat->getCategoryName().' prices:', ['catPrices' => count($productPriceList)]);
}
}
/*
print('<hr>QQW categoryProductPrices: ');
\Doctrine\Common\Util\Debug::dump($categoryProductPrices);
$logger->notice('QQW Hallo logger e-shop 3D: ');
foreach($productListTitles as $tit){
$logger->notice('tit: '.$tit);
}
*/
/*
print('<hr>QQW productList: ');
\Doctrine\Common\Util\Debug::dump($categoryProducts);
print('<hr>');
*/
//die();
if($_SERVER['HTTP_HOST'] != 'localhost') {
$urlPattern = "http://www.easycommerc.com/";
} else {
$urlPattern = "http://localhost/alliancemarkets2/web/";
}
$debug = 1;
if($request->request->get('header')==='false') {
$isHeader = false;
} else {
$isHeader = true;
}
if(!empty($request->request->get('is_footer')) && $request->request->get('footer')=='false') {
$isFooter = false;
} else {
$isFooter = true;
}
$limit = 300;
$offset = 0;
$count = 0;
$pages = 10;
$page = 1;
$system = array('code' => 200, 'message' => 'OK');
$metadata = array('count' => $count, 'limit' => 100, 'pages' => $pages, 'page' => $page);
//die();
$data = array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'userDirs' => $userDirs,
'childNodes' => $childNodes,
'childNodeImages' => $childNodeImages,
'categoryImages' => $categoryImages,
'productListTitles' => $productListTitles,
'productDescriptions' => $productDescriptions,
'products' => $products,
'categoryProducts' => $categoryProducts,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'urlPattern' => $urlPattern,
'textureItemCollection' => $textureItemCollection,
'isFooter' => $isFooter,
'isHeader' => $isHeader
);
/* we prepare data for view */
$viewData = array('system' => $system,
'data' => $data,
'metadata' => $metadata,
);
// we output json
return new JsonResponse($viewData);
}
/**
* @Route("/eshop3d/{eshop3dId}/category/{categoryId}", name="eshop3dCategory")
*/
public function eshopCategoryAction(Request $request, $eshopId, $categoryId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with tis ID does not exists.');
return $this->redirectToRoute('eshopHome');
}
$category = $dem->getRepository(Eshop::class)->getCategory($categoryId);
$categoryPath = $dem->getRepository(Category::class)->getPath($category);
$childNodes = $category->getChildren();
/*
print('<br>QQW Category ID: '.$categoryId);
foreach($categoryPath as $cat) {
print('<hr>QQW category Path: ');
\Doctrine\Common\Util\Debug::dump($cat);
*/
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
$productList = $dem->getRepository(Product::class)->getProductListByCategory($categoryId);
/*
print('<br>QQW productList: ');
\Doctrine\Common\Util\Debug::dump($productList);
*/
/* we display products from subfolders */
if(!empty($eshop->getDisplayProductsFromSubfolders()) && $eshop->getDisplayProductsFromSubfolders() == true) {
/*
print('<br>QQW DisplayProductsFromSubfolders: ');
\Doctrine\Common\Util\Debug::dump($eshop->getDisplayProductsFromSubfolders());
*/
foreach($childNodes as $cat) {
$nodeProductList = $dem->getRepository(Product::class)->getProductListByCategory($cat->getCategoryId());
$productList = array_merge($productList, $nodeProductList);
}
}
/* we load product ids into array */
/* we setup and validate images */
$productIds = array();
$productImages = array();
$productThumbs = array();
foreach($productList as $product) {
$pId = $product->getProductId();
$productIds[] = $pId;
if($product->getImage1() != "") {
$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
//print('<br>qqw imagePath: '.$imagePath);
/* we check if thumbnail exists */
if(!is_file($imageThumbPath)) {
//print('<br>qqw creating thumb');
$imageData = getimagesize($imagePath);
$thumbWidth = $eshop->getImageThumbWidth();
$thumbHeight = ($imageData[1]/$imageData[0])*$thumbWidth;
if($eshop->getImageThumbHeight() > 0) {
$eshopThumbHeight = $eshop->getImageThumbHeight();
} else {
$eshopThumbHeight = 200;
}
/* if the thumb height is bigger than allowed thumb height we generate thumb according to height*/
if($thumbHeight > $eshopThumbHeight) {
$thumbHeight = $eshopThumbHeight;
$thumbWidth = ($imageData[0]/$imageData[1])*$thumbHeight;
}
$srcimg = $this->GetImage($imagePath);
$destimg = imagecreatetruecolor($thumbWidth,$thumbHeight);
if(is_file($imagePath)) {
ImageCopyResized($destimg,$srcimg,0,0,0,0,$thumbWidth,$thumbHeight,ImageSX($srcimg),ImageSY($srcimg));
ImageJPEG($destimg,$imageThumbPath, 100);
}
}
$productThumbs[$pId] = $imageThumbPath;
}
}
/* we load prices */
$productPriceList = $dem->getRepository(Product::class)->getProductPriceList($productIds);
$defaultCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
$targetCurrency = $session->get('eshopCurrency');
/* we load currency rated prices */
$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
/* we get price(s) to display */
$displayPrice = null;
foreach($productPriceList as $price) {
if($price->getProductId() == $product->getProductId()) {
/* we get default price level */
if($price->getPriceLevelId() == 1) {
$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
}
}
}
/* we add product(s) to basket - POST form action */
if(!empty($request->request->get('basket'))) {
/* we call method to add to basket */
$this->addToBasket($request, $eshopId, $request->request->get('productId'));
}
$productView = $eshop->getProductView();
/*
print('<br>qqw eshop: '.$eshop->getWireFrameId());
\Doctrine\Common\Util\Debug::dump($eshop);
*/
/* we render data */
return $this->render('eshop3DCategory.html.php',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'productView' => $productView,
'productList' => $productList,
'productPriceList' => $productPriceList,
'productThumbs' => $productThumbs,
'wireFrame' => $wireFrame,
'category' => $category,
'childNodes' => $childNodes,
'categoryPath' => $categoryPath,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'eshopHeader' => $eshopHeader,
'eshopFooter' => $eshopFooter,
'homePage' => $homePage,
)
);
}
/**
* @Route("/eshop3dAdmin", name="eshop3dAdmin")
*/
public function eshop3dAdminAction(Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
$userDirs = $this->getUserFolderPathsFromUserId($currentUserId);
/* setting current eshop */
if(!empty($request->query->get('setCurrent'))) {
$eshop = $em->getRepository(Eshop::class)->getEshop($request->query->get('setCurrent'));
$em->getRepository(Eshop::class)->setCurrentEshop($currentUserId, $request->query->get('setCurrent'));
$session->set('eshop', $eshop);
$this->addFlash('notice', 'The eshop '.$eshop->getEshopName().' was set as current one.');
return $this->redirectToRoute('eshopAdmin');
}
/* we get current website */
$currentEshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
/*
print('<br>qqw currentEshop: ');
\Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
*/
/* we load list of eshops for logged user */
$eshopList = $em->getRepository(Eshop::class)->getEshopListByUser($currentUserId);
/* we prepare array of count(products) */
$productCountArray = array();
/*
foreach($websiteList as $website) {
$productCountArray[$website->getWebsiteId()] = $dem->getRepository('AppBundle:WebPage')->getWebPageCountByWebsite($website->getWebsiteId());
}
*/
/*
$eshopId = $currentEshop->getEshopId();
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
foreach($rootNodes as $cat) {
if($cat->getEshopId() == $eshopId) {
$childNodes[] = $cat;
$childNodeImages[$cat->getCategoryId()] = $this->getImageFromText($cat->getCategoryName(), 'silver-black', $userDirs['images'], $userDirs['web'].'/images');
}
}
print('<br>qqw Root Nodes: ');
\Doctrine\Common\Util\Debug::dump($childNodeImages);
*/
//$childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'black-white', $userDirs['images'], $userDirs['web'].'/images');
/*
$text = "Probably the most famous novel of Russian literature of the 20th century depicts the key moments of the life of the title hero Yuri Zivag associated with important social events in Russia: 1905 - Russian revolution and labor strikes, World War I, Revolution 1917, post-revolutionary development. As a red thread, the novel comes with love, a plot is also permeated by reflections on the meaning of life and art. An extraordinary role plays a random fatality in the work that enters into the lives of individual characters and interconnects them. According to the novel, in 1965, a successful film was awarded with five Oscars.";
$newText = $this->getImageFromText($text, 'black-white', $userDirs['images'], $userDirs['web'].'/images', 50, 'test_text_image', 500, 27, 12);
print('<br>QQW image text: <br>'.$newText);
*/
/* we render data */
return $this->render('eshop3DAdmin.html.twig',
array('headerData' => $this -> getPageHeader($request),
'eshopList' => $eshopList,
'user' => $user,
'productCountArray' => $productCountArray,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
)
);
}
public function categoryTreeMenu($eshop, Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $eshop->getUserId();
$session->set('eshop', $eshop);
/* we get current e-shop */
//$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
$repo = $dem->getRepository(Category::class);
$this->dynamicEntityManager = $dem;
$this->currentEshop = $eshop;
$options = array(
'decorate' => true,
'rootOpen' => '<ul class="tree">',
'rootClose' => '</ul>',
'childOpen' => function($node) {
/*
print('<br>QQW node: ');
\Doctrine\Common\Util\Debug::dump($node);
*/
if($node['eshopId'] == $this->currentEshop->getEshopId()) {
return '<li class="treeItem">';
} else {
return '<li class="treeItemHidden">';
}
return '<li class="treeItem">';
},
'childClose' => '</li>',
'nodeDecorator' => function($node) {
$url = $this->generateUrl('eshop',array('eshopId'=>$this->currentEshop->getEshopId()));
return '<a href="'.$url.'/category/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>';
}
);
$htmlTree = $repo->childrenHierarchy(
null,
false,
$options
);
return $htmlTree;
}
public function categoryTopMenu($eshop, Request $request)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
//$categoryList = $dem->getRepository(Eshop::class)->getRootCategoryListByEshop($eshop->getEshopId());
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
foreach($rootNodes as $cat) {
if($cat->getEshopId() == $eshop->getEshopId()) {
$childNodes[] = $cat;
}
}
/*
print('<br>QQW categoryTopMenu: ');
\Doctrine\Common\Util\Debug::dump($childNodes);
*/
return $childNodes;
}
/**
* @Route("/eshop3d/{eshopId}/basket", name="basket3d")
*/
public function basket3dAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
$logger = $this->getLogger(null, 'basket 3D');
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$user = $em->getRepository(User::class)->getUser($eshop->getUserId());
/* we check if eshop exists */
if($eshop === null) {
$this->addFlash('error', 'E-shop with this ID does not exists.');
return $this->redirectToRoute('eshopHome');
}
/* we set iteration to display basket info in 3D template */
if(empty($session->get('basket3DIteration'))) {
$session->set('basket3DIteration', 1);
} else {
$session->set('basket3DIteration', ($session->get('basket3DIteration') + 1));
}
$basket3DIteration = $session->get('basket3DIteration');
$targetCurrency = $session->get('eshopCurrency');
$userDirs = $this->getUserFolderPathsFromUserId($user->getUserId());
//print('<br>qqw eshop: ');
//\Doctrine\Common\Util\Debug::dump($eshop);
$eshopId = $eshop->getEshopId();
$rootNodes = $dem->getRepository(Category::class)->getRootNodes();
$childNodes = array();
$childNodeImages = array();
$categoryImages = array();
$products = array();
$categoryProducts = array();
$categoryProductImages = array();
$productListTitles = array();
$productDescriptions = array();
if(!empty($session->get('order'))) {
$order = $session->get('order');
} else {
$order = null;
}
if($_SERVER['HTTP_HOST'] != 'localhost') {
$urlPattern = "http://www.easycommerc.com/";
} else {
$urlPattern = "http://localhost/alliancemarkets2/web/";
}
$debug = 1;
$orderPrice = 0;
if(!empty($order)) {
$orderPrice = $dem->getRepository('AppBundle:Order')->getOrderPrice($order->getOrderId());
}
$basketMessage = "Basket message";
/* we add product(s) to basket - GET action */
if(!empty($request->get('add2basket'))) {
/* we call method to add to basket */
$this->addToBasket($request, $eshopId, $request->get('productId'));
$basketMessage = "Total amount: ".$orderPrice;
$basketMessage .= " | Adding product id: ".$request->get('productId');
}
if(!empty($request->request->get('debug'))) {
//if(!empty($debug)) {
/* we render HTML */
$response = $this->render('basket3D.html.php',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'userDirs' => $userDirs,
'childNodes' => $childNodes,
'childNodeImages' => $childNodeImages,
'categoryImages' => $categoryImages,
'productListTitles' => $productListTitles,
'productDescriptions' => $productDescriptions,
'products' => $products,
'categoryProducts' => $categoryProducts,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'basket3DIteration' => $basket3DIteration,
'order' => $order,
'urlPattern' => $urlPattern,
)
);
} else {
/* we render virtual reality data */
$response = new Response(
$this->renderView('basket3D.vrml.php',
array( 'headerData' => $this -> getPageHeader($request),
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'eshop' => $eshop,
'user' => $user,
'userDirs' => $userDirs,
'childNodes' => $childNodes,
'childNodeImages' => $childNodeImages,
'categoryImages' => $categoryImages,
'productListTitles' => $productListTitles,
'productDescriptions' => $productDescriptions,
'products' => $products,
'categoryProducts' => $categoryProducts,
'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),
'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),
'logger' => $logger,
'basketMessage' => $basketMessage,
'basket3DIteration' => $basket3DIteration,
'order' => $order,
'urlPattern' => $urlPattern,
)
), 200
);
$response->headers->set('Content-Type', 'model/vrml');
}
return $response;
}
public function addToBasket(Request $request, $eshopId, $productId)
{
//print("<br>qqw adding to basket pid: ".$productId);
/* we load session data */
parent::init($request);
$session = $request->getSession();
//print('<br>QQW eshop ID: '.$eshopId);
//\Doctrine\Common\Util\Debug::dump($category);
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
/* we load product */
$product = $dem->getRepository(Product::class)->getProduct($productId);
/* we get price levels */
$priceLevelCollection = $dem->getRepository('AppBundle:PriceLevel')->getPriceLevelList();
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
$eshopCurrency = $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
/* if there is no order in basket then we create new order */
if(empty($session->get('order'))) {
//print('<br>QQW Creating New Order');
$order = new Order;
$order->setEshopId($eshopId);
$session->set('order', $order);
$session->get('order')->setIp($request->getClientIp());
}
/* we set product units */
$units = 1;
if(!empty($request->request->get('units'))) {
$unitInt = intval($request->request->get('units'));
if($unitInt > 0) {
$units = $request->request->get('units');
} else {
$units = 1;
}
}
/* we check if we have this order item in basket already */
$isInBasket = false;
foreach($session->get('order')->getOrderItems() as $orderItem) {
if($orderItem->getProductId() == $product->getProductId()) {
//print('<br>qqw item exists in basket');
$orderItem->setOrderItemUnits($orderItem->getOrderItemUnits() + $units);
$isInBasket = true;
}
}
if(!$isInBasket) {
/* we create order item and load it with product data */
//print('<br>qqw product is NOT in basket yet');
$orderItem = new OrderItem;
$orderItem->setOrderItemTitle($product->getProductName());
//print('<br>qqw units: '.$units);
$orderItem->setOrderItemUnits($units);
$orderItem->setProductId($product->getProductId());
//$itemPrice = $units * $request->request->get('productPrice');
/* we set price */
$displayPrice = null;
/* product prices */
foreach($priceLevelCollection as $priceLevel) {
/* we check if the price for this product and price level exists */
$productPrice = $dem->getRepository('AppBundle:Price')->getPrice(intval($productId), $priceLevel->getPriceLevelId());
if($productPrice == null) {
$priceValue = '';
$priceSuffix2 = '';
} else {
if(!empty($eshop->getDisplayNettoPrices()) && $eshop->getDisplayNettoPrices()==true) {
$priceValue = $productPrice->getNettoValue();
$priceSuffix2 = 'netto';
} else {
$priceValue = $productPrice->getBruttoValue();
$priceSuffix2 = 'brutto';
}
}
$displayPrice = $priceValue;
}
/*
foreach($product->getPrices() as $price) {
$displayPrice = 22;
// we get default price level
if($price->getPriceLevelId() == 1) {
//$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
$displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
}
}
*/
$orderItem->setOrderItemPrice($displayPrice);
$orderItem->setCurrencyKey($eshopCurrency->getCurrencyKey());
$session->get('order')->addOrderItem($orderItem);
}
$orderItemId = $dem->getRepository('AppBundle:Order')->getMaxOrderItemId($session->get('order'));
//$orderItem->setOrderItemId(2);
//product.added_to_basket
//$this->addFlash('notice', $this->translator->trans('product.added_to_basket').'<a href="/eshop/'.$eshopId.'/basket" class="viewBasket">'.$this->translator->trans('eshop.basket_view').'</a>');
/*
print('<br>qqw basket items: ');
\Doctrine\Common\Util\Debug::dump($session->get('order')->getOrderItems());
*/
}
/**
* @Route("/eshop3DEdit/{eshopId}", name="eshop3DEdit")
*/
public function eshop3DEditAction(Request $request, $eshopId)
{
/* we load session data */
parent::init($request);
$session = $request->getSession();
/* we check if an user is logged in */
if(empty($session->get('user'))) {
return $this->redirectToRoute('login');
}
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
/* we get current user */
$user = $em->getRepository(User::class)->getUser($userId);
/* we get current e-shop */
$eshop = $em->getRepository(Eshop::class)->getEshop($eshopId);
/* we get current 3D eshop */
$eshop3D = $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
if(empty($eshop3D)) {
$eshop3D = new Eshop3D;
$eshop3D->setEshop3DName($eshop->getEshopName());
$eshop3D->setUserId($userId);
/* we persist and save */
$dem->persist($eshop3D);
$dem->flush();
}
/* we get eshop list */
$eshopCollection = $dem->getRepository(Eshop::class)->getEshopListByUser($userId);
/* we get free worlds */
$freeWorldCollection = $dem->getRepository(FreeWorld3D::class)->getFreeWorld3DList();
/* we get gallery list */
$galleryCollection = $dem->getRepository(Gallery::class)->getGalleryListByUser($userId);
$galleryItemCollection = null;
if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
$galId = $eshop3D->getTextureGallery()->getGalleryId();
$galleryItemCollection = $dem->getRepository(GalleryItem::class)->getGalleryItemList($galId);
}
/* we find 3D templates */
$rootDir = $this->appKernel->getProjectDir();
$views = $rootDir.'/templates/eshop3D/';
$finder = new Finder();
$finder->in($views);
/* we build edit form */
$formBuilder = $this->createFormBuilder($eshop3D);
$userDirs = $this->getUserFolderPaths($request);
$formBuilder->add('eshop3DName', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('module.eshop_name'),
'attr' => array('class' => 'text_form', 'size' => 50, 'value' => $eshop3D->getEshop3DName()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('eshopLogoUrl', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.logo_url'),
'attr' => array('class' => 'text_form', 'size' => 50, 'value' => $eshop3D->getEshopLogoUrl()),
'label_attr' => array('class' => 'form_field_label')
));
/*
$formBuilder->add('template3DPath', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('module.gallery3D_template'),
'attr' => array('class' => 'text_form', 'size' => 50, 'value' => $gallery->getTemplate3DPath()),
'label_attr' => array('class' => 'form_field_label')
));
*/
$formBuilder->add('eshop3DDescription', TextAreaType::class, array(
'required' => false,
'label' => $this->translator->trans('module.eshopLink_description'),
'attr' => array('class' => 'textarea_form', 'cols' => 77, 'rows' => 5, 'value' => $eshop3D->getEshop3DDescription()),
'label_attr' => array('class' => 'form_textarea_label2'),
'data' => $eshop3D->getEshop3DDescription(),
));
/* we add eshop list */
$eshops = array();
$eshops['-- select --'] = 0;
foreach($eshopCollection as $shop)
{
$shopId = $shop->getEshopId();
//print('<br>qqw shop: '.$shopId);
$shopKey = $shop->getEshopName().' (id:'.$shop->getEshopId().')';
$eshops[$shopKey] = $shopId;
}
$selectedEshop = 0;
if(!empty($eshop3D->getEshop())) {
$selectedEshop = $eshop3D->getEshop()->getEshopId();
}
$formBuilder->add('xmlSourcePath', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('system.xml_source'),
'attr' => array('class' => 'text_form', 'size' => 50, 'value' => $eshop3D->getXmlSourcePath()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('eshopId', ChoiceType::class, array(
'choices' => $eshops,
'mapped' => false,
'label' => $this->translator->trans('module.eshop_parent'),
'attr' => array('class' => 'selector'),
'label_attr' => array('class' => 'form_field_label'),
'data' => $selectedEshop
));
/* we add gallery list */
$galleries = array();
$galleries['-- select --'] = 0;
foreach($galleryCollection as $gal)
{
$galId = $gal->getGalleryId();
//print('<br>qqw dep: '.$depId);
$galKey = $gal->getGalleryName().' (id:'.$gal->getGalleryId().')';
$galleries[$galKey] = $galId;
}
$selectedGallery = 0;
if(!empty($eshop3D->getTextureGallery())) {
$selectedGallery = $eshop3D->getTextureGallery()->getGalleryId();
}
$formBuilder->add('textureGalleryId', ChoiceType::class, array(
'choices' => $galleries,
'mapped' => false,
'label' => $this->translator->trans('module.gallery_texture'),
'attr' => array('class' => 'selector'),
'label_attr' => array('class' => 'form_field_label'),
'data' => $selectedGallery
));
/* we add 3D template list */
$templates3D = array();
foreach ($finder as $file) {
$templates3D[$file->getRelativePathname()] = $file->getRelativePathname();
}
$selectedTemplate3D = 0;
if(!empty($eshop3D->getTemplate3DPath())) {
$selectedTemplate3D = $eshop3D->getTemplate3DPath();
}
$formBuilder->add('template3DPath', ChoiceType::class, array(
'choices' => $templates3D,
'label' => $this->translator->trans('module.gallery3D_template'),
'attr' => array('class' => 'selector'),
'label_attr' => array('class' => 'form_field_label'),
'data' => $selectedTemplate3D
));
/* we add free world list */
$freeWorlds = array();
foreach($freeWorldCollection as $freeWorld)
{
$freeWorldId = $freeWorld->getFreeWorld3DId();
$freeWorlds[$freeWorld->getFreeWorld3DName()] = $freeWorld->getFreeWorld3DId();
}
$selectedFreeWorlds = array();
foreach($eshop3D->getFreeWorlds() as $freeWorld) {
$selectedFreeWorlds[] = $freeWorld->getFreeWorld3DId();
}
$formBuilder->add('freeWorlds', ChoiceType::class, array(
'choices' => $freeWorlds,
'required' => false,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'label_attr' => array('class' => 'form_field_label'),
'attr' => array('class' => 'form_field_text'),
'data' => $selectedFreeWorlds
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
$formData = $form->getData();
$eshop3D->setEshop3DName($formData->getEshop3DName());
/* we remove old freeWorld associations */
foreach($eshop3D->getFreeWorlds() as $freeWorld) {
$eshop3D->removeFreeWorld($freeWorld);
}
/* we load selected freeWorlds */
if(!empty($form['freeWorlds']->getData())) {
foreach($form['freeWorlds']->getData() as $freeWorldId) {
$addFreeWorld = $dem->getRepository(FreeWorld3D::class)->getFreeWorld3D($freeWorldId);
$eshop3D->addFreeWorld($addFreeWorld);
}
}
if(!empty($formData->getEshop3DDescription())) {
$eshop3D->setEshop3DDescription($formData->getEshop3DDescription());
}
$eshop3D->setEshopLogoUrl($formData->getEshopLogoUrl());
$eshop3D->setXmlSourcePath($formData->getXmlSourcePath());
$eshop3D->setTemplate3DPath($formData->getTemplate3DPath());
if(!empty($form['eshopId']->getData()) && $form['eshopId']->getData()>0) {
$newEshop = $dem->getRepository(Eshop::class)->getEshop($form['eshopId']->getData());
$eshop3D->setEshop($newEshop);
}
/*
else {
$newEshop = $dem->getRepository(Eshop::class)->getEshop($eshopId);
$eshop3D->setEshop($newEshop);
}
*/
if(!empty($form['textureGalleryId']->getData()) && $form['textureGalleryId']->getData()>0) {
$textureGallery = $dem->getRepository(Gallery::class)->getGallery($form['textureGalleryId']->getData());
$eshop3D->setTextureGallery($textureGallery);
} else {
$eshop3D->setTextureGallery(null);
}
/* we persist and save */
$dem->persist($eshop3D);
$dem->flush();
$this->addFlash('notice', '3D Eshop was updated.');
return $this->redirectToRoute('eshop3DEdit', array('eshopId' => $eshop3D->getEshop()->getEshopId()));
}
}
/* we render data */
return $this->render('eshop3DEdit.html.twig',
array('headerData' => $this -> getPageHeader($request),
'eshop3D' => $eshop3D,
'form' => $formBuilder->getForm()->createView(),
'user' => $user,
'userDirs' => $userDirs,
'galleryItemCollection' => $galleryItemCollection,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
)
);
}
public function adminMenu(Request $request)
{
$menuItems = array(0 => array('link' => 'services3dAdmin', 'langKey' => 'service.services3d', 'routeName' => 'services3dAdmin'),
1 => array('link' => 'eshop3dAdmin', 'langKey' => 'module.eshop3dAdmin', 'routeName' => 'eshop3dAdmin')
);
return $menuItems;
}
}