src/Controller/Eshop3DController.php line 211

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\JsonResponse
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\FileType;
  15. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  16. use Symfony\Component\Console\Input\ArrayInput;
  17. use Symfony\Bundle\FrameworkBundle\Console\Application;
  18. use Symfony\Component\HttpKernel\KernelInterface;
  19. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  20. use Symfony\Component\Validator\Constraints\DateTime;
  21. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  22. use Symfony\Component\Serializer\Serializer;
  23. use App\Entity\Category;
  24. use App\Entity\Currency;
  25. use App\Entity\Gallery;
  26. use App\Entity\GalleryItem;
  27. use App\Entity\Eshop;
  28. use App\Entity\Module;
  29. use App\Entity\Order;
  30. use App\Entity\OrderItem;
  31. use App\Entity\Product;
  32. use App\Entity\Contact;
  33. use App\Entity\User;
  34. use Symfony\Component\Finder\Finder;
  35. use Ivory\CKEditorBundle\Form\Type\CKEditorType;
  36. use App\Entity\Gallery3D;
  37. use App\Entity\FreeWorld3D;
  38. use App\Entity\Eshop3D;
  39. use Symfony\Contracts\Translation\TranslatorInterface;
  40. class Eshop3DController extends DefaultController
  41. {
  42.     protected ManagerRegistry $doctrine;
  43.     protected TranslatorInterface $translator;
  44.     protected $appKernel;
  45.     public function __construct(ManagerRegistry $doctrine,
  46.                                 TranslatorInterface $translator,
  47.                                 KernelInterface $appKernel)
  48.     {
  49.         $this->doctrine $doctrine;
  50.         $this->translator $translator;
  51.         $this->appKernel $appKernel;
  52.     }
  53.     protected $dynamicEntityManager;
  54.     
  55.     protected $currentEshop;
  56.     
  57.     /**
  58.      * @Route("/eshop3d", name="eshop3dHome")
  59.      */
  60.     public function indexAction(Request $request)
  61.     {
  62.         /* we load session data */
  63.         parent::init($request); 
  64.         $session $request->getSession();
  65.         /* we render data */
  66.         return $this->render('eshopHome.html.php',
  67.                     array('headerData' => $this -> getPageHeader($request)
  68.                 )
  69.         );        
  70.     }
  71.     
  72.     /**
  73.      * @Route("/eshop3d/{eshopId}", name="eshop3d")
  74.      */
  75.     public function eshop3dAction(Request $request$eshopId)
  76.     {
  77.     
  78.         /* we load session data */
  79.         parent::init($request);
  80.         $session $request->getSession();
  81.         $logger $this->getLogger(null'e-shop 3D');
  82.         //print('<br>QQW eshop ID: '.$eshopId);
  83.         //\Doctrine\Common\Util\Debug::dump($category);
  84.     
  85.         /* we load entity managers */
  86.         $em $this->doctrine->getManager();
  87.         $dem $this->doctrine->getManager('dynamic_em');
  88.         
  89.         /* we get current e-shop */
  90.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  91.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  92.             
  93.         /* we check if eshop exists */
  94.         if($eshop === null) {
  95.             $this->addFlash('error''E-shop with this ID does not exists.');
  96.             return $this->redirectToRoute('eshopHome');
  97.         }
  98.         
  99.         /* we get current 3D eshop */
  100.         $eshop3D $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
  101.         $userDirs $this->getUserFolderPathsFromUserId($user->getUserId());
  102.         
  103.         //isModule Pack Sale
  104.         $module $em->getRepository(Module::class)->getModule(42);
  105.         $isPackSaleModule $em->getRepository(User::class)->userHasModule($user$module);           
  106.         //print('<br>qqw eshop: ');
  107.         //\Doctrine\Common\Util\Debug::dump($eshop);    
  108.         $eshopId $eshop->getEshopId();
  109.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  110.         $childNodes = array();
  111.         $childNodeImages = array();
  112.         $categoryImages = array();
  113.         $products = array();
  114.         $categoryProducts = array();
  115.         $categoryProductImages = array();
  116.         $productListTitles = array();
  117.         $productDescriptions = array();
  118.         $categoryProductPrices = array();
  119.         /* we get parent gallery items */
  120.         $textureItemCollection null;
  121.         if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
  122.             $textureItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($eshop3D->getTextureGallery()->getGalleryId());
  123.         }
  124. //        print('<br>QQW locale: '.$session->get('lang')->getLangKey());
  125.         foreach($rootNodes as $cat) {
  126.             if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
  127.                 $catId $cat->getCategoryId();
  128.                 $productList = array();
  129.                 $childNodes[] = $cat;
  130.                 $childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'category_'.$catId400604048);
  131.                 $cat->setLocale($session->get('lang')->getLangKey());
  132.                 $dem->refresh($cat);
  133. //                print('<br>QQW category: '.$cat->getCategoryName());
  134. //                \Doctrine\Common\Util\Debug::dump($cat);
  135.                 //getImageFromText($text="", $colorType="default", $imagePath, $imageWebPath, $countCharactersInLine = 30, $imageName="image_name", $imageWidth=400, $imageHeight=60, $fontSize=40, $positionY = 40)
  136.                 if($cat->getImage1() != "") {
  137.                     $categoryImagePath $userDirs['web'].'/images/'.$cat->getImage1();  
  138.                 } else {
  139.                     $categoryImagePath '';
  140.                 }
  141.                 $categoryImages[$catId] = $categoryImagePath;
  142.                 /* we get products in the cateory */
  143.                 $productList $dem->getRepository(Product::class)->getProductListByCategory($catId);
  144.                 /* we generate images for product titles */
  145.                 foreach($productList as $product) {
  146.                     $productId $product->getProductId();
  147.                     $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  148.                     $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  149.                     $productListTitles[$productId] = $title;
  150.                     $productDescriptions[$productId] = $description;
  151.                     $products[$productId] = $product;
  152.                 }   
  153. //                print('<br>QQW productList in category: '.$cat->getCategoryName());
  154. //                \Doctrine\Common\Util\Debug::dump($productList);
  155.                 /* we display products from subfolders */
  156.                 if(!empty($eshop->isDisplayProductsFromSubfolders()) && $eshop->isDisplayProductsFromSubfolders() == true) {
  157.   
  158.                     $catChildNodes $cat->getChildren();
  159.                     foreach($catChildNodes as $catChild) {
  160.                          $subCatId $catChild->getCategoryId();
  161.                         $nodeProductList $dem->getRepository(Product::class)->getProductListByCategory($catChild->getCategoryId());
  162.                         //$productList = array_merge($productList, $nodeProductList);
  163.                         $categoryProducts[$catChild->getCategoryId()] = $nodeProductList
  164.                         
  165.                         $productIds = [];
  166.                         foreach($nodeProductList as $product) {
  167.                             $productId $product->getProductId();
  168.                             $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  169.                             $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  170.                             $productListTitles[$productId] = $title;
  171.                             $productDescriptions[$productId] = $description;
  172.                             $products[$productId] = $product;
  173.                             $productIds[] = $productId;
  174.                         }
  175.                         
  176.                        /* we load prices */
  177.             $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  178.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  179.             $targetCurrency $session->get('eshopCurrency');
  180.             
  181.             /* we load currency rated prices */
  182.             $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  183.             /* we get price(s) to display */
  184.             $displayPrice null;
  185.             foreach($productPriceList as $price) {
  186.                 if($price->getProductId() == $product->getProductId()) {
  187.                 /* we get default price level */
  188.                 if($price->getPriceLevelId() == 1) {
  189.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  190.                     $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  191.                 }
  192.                 
  193.                 }
  194.             } 
  195.             
  196.             $categoryProductPrices[$subCatId] = $productPriceList;
  197.             
  198.             //$logger->notice('QQW subCatId: '.,;
  199.             //$logger->notice('QQW subCat '.$catChild->getCategoryName().' prices:', ['subCatPrices' => count($productPriceList)]);        
  200.                         
  201.   
  202.                     }
  203.                     
  204.                     
  205.                     
  206.                     /*
  207.                     print('<br>-------------------QQW DisplayProductsFromSubfolders: ');
  208.                     \Doctrine\Common\Util\Debug::dump($productList);
  209.                     */
  210.                 
  211.                 $categoryProducts[$cat->getCategoryId()] = $productList
  212.                 /* we generate images for product titles */
  213.                 $productIds = [];
  214.                 foreach($productList as $product) {
  215.                     $productId $product->getProductId();
  216.                     $productIds[] = $productId;
  217.                     $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  218.                     $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  219.                     
  220.                     $productListTitles[$productId] = $title;
  221.                     $productDescriptions[$productId] = $description;
  222.                     $products[$productId] = $product;
  223.                 }  
  224.                 
  225.                 /* we load prices */
  226.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  227.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  228.         $targetCurrency $session->get('eshopCurrency');
  229.         
  230.         /* we load currency rated prices */
  231.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  232.         /* we get price(s) to display */
  233.         $displayPrice null;
  234.         foreach($productPriceList as $price) {
  235.             if($price->getProductId() == $product->getProductId()) {
  236.                 /* we get default price level */
  237.                 if($price->getPriceLevelId() == 1) {
  238.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  239.                     $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  240.                 }
  241.                 
  242.             }
  243.         } 
  244.         
  245.         $categoryProductPrices[$cat->getCategoryId()] = $productPriceList;
  246.         
  247.         //$logger->notice('QQW Cat '.$cat->getCategoryName().' prices:', ['catPrices' => count($productPriceList)]);      
  248.             }
  249.           
  250.         } 
  251.         
  252.         /*
  253.         print('<hr>QQW categoryProductPrices: ');
  254.         \Doctrine\Common\Util\Debug::dump($categoryProductPrices); 
  255.         
  256.         $logger->notice('QQW Hallo logger e-shop 3D: ');        
  257.         foreach($productListTitles as $tit){ 
  258.           $logger->notice('tit: '.$tit);  
  259.         }
  260.         */
  261.         /*
  262.         print('<hr>QQW productList: ');
  263.         \Doctrine\Common\Util\Debug::dump($categoryProducts);     
  264.         print('<hr>');
  265.         */
  266.         //die();
  267.         if($_SERVER['HTTP_HOST'] != 'localhost') {
  268.             $urlPattern "http://www.easycommerc.com/";
  269.         } else {
  270.             $urlPattern "http://localhost/alliancemarkets2/web/";
  271.         }
  272.         $debug 1;
  273.         if($request->request->get('header')==='false') {  
  274.             $isHeader false;
  275.         } else {
  276.             $isHeader true;
  277.         }        
  278.         if(!empty($request->request->get('is_footer')) && $request->request->get('footer')=='false') {  
  279.             $isFooter false;
  280.         } else {
  281.             $isFooter true;
  282.         }
  283.         if(!empty($request->get('isStartGuide'))) {   
  284.             $isStartGuide $request->get('isStartGuide');
  285.             //print('isStartGuide: '.$request->get('isStartGuide'));
  286.         } else {
  287.             $isStartGuide false;
  288.             //print('isStartGuide: FALSE');
  289.         }
  290.         if(!empty($request->request->get('debug'))) {   
  291.         //if(!empty($debug)) {    
  292.             /* we render HTML */
  293.             $response $this->render('eshop3D.html.php',
  294.                 array(  'headerData' => $this -> getPageHeader($request),
  295.                         'menu' => $this -> adminMenu($request),
  296.                         'mainMenu' => $this -> adminMainMenu($request),
  297.                         'eshop' => $eshop,
  298.                         'user' => $user,
  299.                         'userDirs' => $userDirs,
  300.                         'childNodes' => $childNodes,
  301.                         'childNodeImages' => $childNodeImages,
  302.                         'categoryImages' => $categoryImages,
  303.                         'productListTitles' => $productListTitles,
  304.                         'productDescriptions' => $productDescriptions,
  305.                         'products' => $products,
  306.                         'categoryProducts' => $categoryProducts,
  307.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),    
  308.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),   
  309.                         'urlPattern' => $urlPattern,    
  310.                         'textureItemCollection' => $textureItemCollection,
  311.                         'isFooter' => $isFooter,     
  312.                         'isHeader' => $isHeader                                                      
  313.                 )
  314.                 );   
  315.         
  316.         } else {
  317.           /* we render virtual reality data */
  318.           $response $this->render('eshop3D/eshop3D.html.twig',
  319.             array(  'headerData' => $this -> getPageHeader($request),
  320.                             'menu' => $this -> adminMenu($request),
  321.                         'mainMenu' => $this -> adminMainMenu($request),
  322.                             'eshop' => $eshop,
  323.                             'user' => $user,
  324.                             'userDirs' => $userDirs,
  325.                             'childNodes' => $childNodes,
  326.                             'childNodeImages' => $childNodeImages,
  327.                             'categoryImages' => $categoryImages,
  328.                             'productListTitles' => $productListTitles,
  329.                             'productDescriptions' => $productDescriptions,
  330.                             'products' => $products,
  331.                             'categoryProducts' => $categoryProducts,
  332.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),    
  333.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request),                
  334.                             'logger' => $logger,
  335.                             'urlPattern' => $urlPattern
  336.                             'textureItemCollection' => $textureItemCollection,
  337.                             'categoryProductPrices' => $categoryProductPrices,
  338.                             'isPackSaleModule' => $isPackSaleModule,
  339.                             'eshop3D' => $eshop3D,
  340.                             'isStartGuide' => $isStartGuide                      
  341.                 )
  342.             );  
  343.             
  344.             /*
  345.             $response = new Response(
  346.               $this->renderView('eshop3D.vrml.php',
  347.                     array(  'headerData' => $this -> getPageHeader($request),
  348.                             'menu' => $this -> adminMenu($request),
  349.                             'eshop' => $eshop,
  350.                             'user' => $user,
  351.                             'userDirs' => $userDirs,
  352.                             'childNodes' => $childNodes,
  353.                             'childNodeImages' => $childNodeImages,
  354.                             'categoryImages' => $categoryImages,
  355.                             'productListTitles' => $productListTitles,
  356.                             'productDescriptions' => $productDescriptions,
  357.                             'products' => $products,
  358.                             'categoryProducts' => $categoryProducts,
  359.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop, $request),    
  360.                             'categoryTopMenu' => $this->categoryTopMenu($eshop, $request),                
  361.                             'logger' => $logger,
  362.                             'urlPattern' => $urlPattern, 
  363.                     )
  364.               
  365.               ), 200
  366.             );
  367.             */
  368.             // $response->headers->set('Content-Type', 'model/vrml');
  369.         }
  370.         return $response;      
  371.          
  372.     }      
  373.     /**
  374.      * @Route("/api/eshop3d/{eshopId}", name="apiEshop3d")
  375.      */
  376.     public function getEshop3d(Request $request$eshopId)
  377.     {
  378.         /* we load session data */
  379.         parent::init($request);
  380.         $session $request->getSession();
  381.         $logger $this->getLogger(null'e-shop 3D');
  382.         //print('<br>QQW eshop ID: '.$eshopId);
  383.         //\Doctrine\Common\Util\Debug::dump($category);
  384.     
  385.         /* we load entity managers */
  386.         $em $this->doctrine->getManager();
  387.         $dem $this->doctrine->getManager('dynamic_em');
  388.         
  389.         /* we get current e-shop */
  390.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  391.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  392.             
  393.         /* we check if eshop exists */
  394.         if($eshop === null) {
  395.             $this->addFlash('error''E-shop with this ID does not exists.');
  396.             return $this->redirectToRoute('eshopHome');
  397.         }
  398.         
  399.         /* we get current 3D eshop */
  400.         $eshop3D $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
  401.         $userDirs $this->getUserFolderPathsFromUserId($user->getUserId());
  402.         
  403.         //isModule Pack Sale
  404.         $module $em->getRepository(Module::class)->getModule(42);
  405.         $isPackSaleModule $em->getRepository(User::class)->userHasModule($user$module);           
  406.         //print('<br>qqw eshop: ');
  407.         //\Doctrine\Common\Util\Debug::dump($eshop);    
  408.         $eshopId $eshop->getEshopId();
  409.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  410.         $childNodes = array();
  411.         $childNodeImages = array();
  412.         $categoryImages = array();
  413.         $products = array();
  414.         $categoryProducts = array();
  415.         $categoryProductImages = array();
  416.         $productListTitles = array();
  417.         $productDescriptions = array();
  418.         $categoryProductPrices = array();
  419.         /* we get parent gallery items */
  420.         $textureItemCollection null;
  421.         if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
  422.             $textureItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($eshop3D->getTextureGallery()->getGalleryId());
  423.         }         
  424.         foreach($rootNodes as $cat) {
  425.             if($cat->getEshopId() == $eshopId && $cat->getIsActive()) {
  426.                 $catId $cat->getCategoryId();
  427.                 $productList = array();
  428.                 $childNodes[] = $cat;
  429.                 $childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'category_'.$catId400604048);
  430.                 //getImageFromText($text="", $colorType="default", $imagePath, $imageWebPath, $countCharactersInLine = 30, $imageName="image_name", $imageWidth=400, $imageHeight=60, $fontSize=40, $positionY = 40)
  431.                 if($cat->getImage1() != "") {
  432.                     $categoryImagePath $userDirs['web'].'/images/'.$cat->getImage1();  
  433.                 } else {
  434.                     $categoryImagePath '';
  435.                 }
  436.                 $categoryImages[$catId] = $categoryImagePath;
  437.                 /* we get products in the cateory */
  438.                 $productList $dem->getRepository(Product::class)->getProductListByCategory($catId);
  439.                 /* we generate images for product titles */
  440.                 foreach($productList as $product) {
  441.                     $productId $product->getProductId();
  442.                     $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  443.                     $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  444.                     $productListTitles[$productId] = $title;
  445.                     $productDescriptions[$productId] = $description;
  446.                     $products[$productId] = $product;
  447.                 }   
  448.                 
  449.                   
  450.                 /*
  451.                 print('<br>QQW productList in category: '.$cat->getCategoryName());
  452.                 \Doctrine\Common\Util\Debug::dump($productList);        
  453.                 */
  454.                 /* we display products from subfolders */
  455.                 if(!empty($eshop->getDisplayProductsFromSubfolders()) && $eshop->getDisplayProductsFromSubfolders() == true) {
  456.   
  457.                     $catChildNodes $cat->getChildren();
  458.                     foreach($catChildNodes as $catChild) {
  459.                          $subCatId $catChild->getCategoryId();
  460.                         $nodeProductList $dem->getRepository(Product::class)->getProductListByCategory($catChild->getCategoryId());
  461.                         //$productList = array_merge($productList, $nodeProductList);
  462.                         $categoryProducts[$catChild->getCategoryId()] = $nodeProductList
  463.                         
  464.                         $productIds = [];
  465.                         foreach($nodeProductList as $product) {
  466.                             $productId $product->getProductId();
  467.                             $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  468.                             $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  469.                             $productListTitles[$productId] = $title;
  470.                             $productDescriptions[$productId] = $description;
  471.                             $products[$productId] = $product;
  472.                             $productIds[] = $productId;
  473.                         }
  474.                         
  475.                        /* we load prices */
  476.             $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  477.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  478.             $targetCurrency $session->get('eshopCurrency');
  479.             
  480.             /* we load currency rated prices */
  481.             $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  482.             /* we get price(s) to display */
  483.             $displayPrice null;
  484.             foreach($productPriceList as $price) {
  485.                 if($price->getProductId() == $product->getProductId()) {
  486.                 /* we get default price level */
  487.                 if($price->getPriceLevelId() == 1) {
  488.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  489.                     $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  490.                 }
  491.                 
  492.                 }
  493.             } 
  494.             
  495.             $categoryProductPrices[$subCatId] = $productPriceList;
  496.             
  497.             //$logger->notice('QQW subCatId: '.,;
  498.             //$logger->notice('QQW subCat '.$catChild->getCategoryName().' prices:', ['subCatPrices' => count($productPriceList)]);        
  499.                         
  500.   
  501.                     }
  502.                     
  503.                     
  504.                     
  505.                     /*
  506.                     print('<br>-------------------QQW DisplayProductsFromSubfolders: ');
  507.                     \Doctrine\Common\Util\Debug::dump($productList);
  508.                     */
  509.                 
  510.                 $categoryProducts[$cat->getCategoryId()] = $productList
  511.                 /* we generate images for product titles */
  512.                 $productIds = [];
  513.                 foreach($productList as $product) {
  514.                     $productId $product->getProductId();
  515.                     $productIds[] = $productId;
  516.                     $title $this->getImageFromText($product->getProductName(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'30'product_'.$productId.'_title'500402530);    
  517.                     $description $this->getImageFromText($product->getProductDescription(), 'orange-black'$userDirs['images'], $userDirs['web'].'/images'50'product_'.$productId.'_description'500271240);
  518.                     
  519.                     $productListTitles[$productId] = $title;
  520.                     $productDescriptions[$productId] = $description;
  521.                     $products[$productId] = $product;
  522.                 }  
  523.                 
  524.                 /* we load prices */
  525.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  526.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  527.         $targetCurrency $session->get('eshopCurrency');
  528.         
  529.         /* we load currency rated prices */
  530.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  531.         /* we get price(s) to display */
  532.         $displayPrice null;
  533.         foreach($productPriceList as $price) {
  534.             if($price->getProductId() == $product->getProductId()) {
  535.                 /* we get default price level */
  536.                 if($price->getPriceLevelId() == 1) {
  537.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  538.                     $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  539.                 }
  540.                 
  541.             }
  542.         } 
  543.         
  544.         $categoryProductPrices[$cat->getCategoryId()] = $productPriceList;
  545.         
  546.         //$logger->notice('QQW Cat '.$cat->getCategoryName().' prices:', ['catPrices' => count($productPriceList)]);      
  547.             }
  548.           
  549.         } 
  550.         
  551.         /*
  552.         print('<hr>QQW categoryProductPrices: ');
  553.         \Doctrine\Common\Util\Debug::dump($categoryProductPrices); 
  554.         
  555.         $logger->notice('QQW Hallo logger e-shop 3D: ');        
  556.         foreach($productListTitles as $tit){ 
  557.           $logger->notice('tit: '.$tit);  
  558.         }
  559.         */
  560.         /*
  561.         print('<hr>QQW productList: ');
  562.         \Doctrine\Common\Util\Debug::dump($categoryProducts);     
  563.         print('<hr>');
  564.         */
  565.         //die();
  566.         if($_SERVER['HTTP_HOST'] != 'localhost') {
  567.             $urlPattern "http://www.easycommerc.com/";
  568.         } else {
  569.             $urlPattern "http://localhost/alliancemarkets2/web/";
  570.         }
  571.         $debug 1;
  572.         if($request->request->get('header')==='false') {  
  573.             $isHeader false;
  574.         } else {
  575.             $isHeader true;
  576.         }        
  577.         if(!empty($request->request->get('is_footer')) && $request->request->get('footer')=='false') {  
  578.             $isFooter false;
  579.         } else {
  580.             $isFooter true;
  581.         }
  582.         
  583.         $limit 300;
  584.         $offset 0;
  585.         $count 0;      
  586.         $pages 10;
  587.         $page 1;
  588.         $system = array('code' => 200'message' => 'OK');
  589.         $metadata = array('count' => $count'limit' => 100'pages' => $pages'page' => $page);
  590.         //die(); 
  591.         $data = array(  'headerData' => $this -> getPageHeader($request),
  592.                         'menu' => $this -> adminMenu($request),
  593.                         'mainMenu' => $this -> adminMainMenu($request),
  594.                         'eshop' => $eshop,
  595.                         'user' => $user,
  596.                         'userDirs' => $userDirs,
  597.                         'childNodes' => $childNodes,
  598.                         'childNodeImages' => $childNodeImages,
  599.                         'categoryImages' => $categoryImages,
  600.                         'productListTitles' => $productListTitles,
  601.                         'productDescriptions' => $productDescriptions,
  602.                         'products' => $products,
  603.                         'categoryProducts' => $categoryProducts,
  604.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),    
  605.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),   
  606.                         'urlPattern' => $urlPattern,    
  607.                         'textureItemCollection' => $textureItemCollection,
  608.                         'isFooter' => $isFooter,     
  609.                         'isHeader' => $isHeader                                                      
  610.                 );
  611.          
  612.         /* we prepare data for view */
  613.         $viewData = array('system' => $system,
  614.                           'data' => $data
  615.                           'metadata' => $metadata,
  616.                 );           
  617.         // we output json
  618.         return new JsonResponse($viewData);
  619.     }
  620.   
  621.     /**
  622.      * @Route("/eshop3d/{eshop3dId}/category/{categoryId}", name="eshop3dCategory")
  623.      */
  624.     public function eshopCategoryAction(Request $request$eshopId$categoryId)
  625.     {
  626.     
  627.         /* we load session data */
  628.         parent::init($request);
  629.         $session $request->getSession();
  630.         //print('<br>QQW eshop ID: '.$eshopId);
  631.         //\Doctrine\Common\Util\Debug::dump($category);   
  632.         /* we load entity managers */
  633.         $em $this->doctrine->getManager();
  634.         $dem $this->doctrine->getManager('dynamic_em');
  635.          
  636.         /* we get current e-shop */
  637.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  638.         /* we check if eshop exists */
  639.         if($eshop === null) {
  640.             $this->addFlash('error''E-shop with tis ID does not exists.');
  641.             return $this->redirectToRoute('eshopHome');
  642.         }        
  643.         
  644.         $category $dem->getRepository(Eshop::class)->getCategory($categoryId);
  645.         $categoryPath $dem->getRepository(Category::class)->getPath($category);
  646.         $childNodes $category->getChildren();
  647.         /*
  648.         print('<br>QQW Category ID: '.$categoryId);
  649.         foreach($categoryPath as $cat) {
  650.             print('<hr>QQW category Path: ');
  651.             \Doctrine\Common\Util\Debug::dump($cat);
  652.         */
  653.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  654.         $productList $dem->getRepository(Product::class)->getProductListByCategory($categoryId);
  655.         /*
  656.         print('<br>QQW productList: ');
  657.         \Doctrine\Common\Util\Debug::dump($productList);        
  658.         */
  659.         /* we display products from subfolders */
  660.         if(!empty($eshop->getDisplayProductsFromSubfolders()) && $eshop->getDisplayProductsFromSubfolders() == true) {
  661.             
  662.             /*
  663.             print('<br>QQW DisplayProductsFromSubfolders: ');
  664.             \Doctrine\Common\Util\Debug::dump($eshop->getDisplayProductsFromSubfolders());
  665.             */
  666.             foreach($childNodes as $cat) {
  667.                 $nodeProductList $dem->getRepository(Product::class)->getProductListByCategory($cat->getCategoryId());
  668.                 $productList array_merge($productList$nodeProductList);
  669.             }
  670.         }
  671.         /* we load product ids into array */
  672.         /* we setup and validate images */
  673.         $productIds = array();
  674.         $productImages = array();
  675.         $productThumbs = array();
  676.         foreach($productList as $product) {
  677.             $pId $product->getProductId();
  678.             $productIds[] = $pId;
  679.             if($product->getImage1() != "") {
  680.                         
  681.                         $imagePath 'users/'.$user->getUserName().'/images/'.$product->getImage1();            
  682.                         $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  683.                         //print('<br>qqw imagePath: '.$imagePath);
  684.                         /* we check if thumbnail exists */
  685.                     if(!is_file($imageThumbPath)) {
  686.                             //print('<br>qqw creating thumb');
  687.                     
  688.                       $imageData getimagesize($imagePath);
  689.                       $thumbWidth $eshop->getImageThumbWidth();
  690.                       $thumbHeight = ($imageData[1]/$imageData[0])*$thumbWidth;
  691.                       if($eshop->getImageThumbHeight() > 0) {
  692.                         $eshopThumbHeight $eshop->getImageThumbHeight();
  693.                       } else {
  694.                         $eshopThumbHeight 200;
  695.                       }
  696.                       /* if the thumb height is bigger than allowed thumb height we generate thumb according to height*/
  697.                       if($thumbHeight $eshopThumbHeight) {
  698.                         $thumbHeight $eshopThumbHeight;
  699.                         $thumbWidth = ($imageData[0]/$imageData[1])*$thumbHeight;
  700.                       }
  701.                       $srcimg $this->GetImage($imagePath);
  702.                       $destimg imagecreatetruecolor($thumbWidth,$thumbHeight);
  703.                       if(is_file($imagePath)) {
  704.                           ImageCopyResized($destimg,$srcimg,0,0,0,0,$thumbWidth,$thumbHeight,ImageSX($srcimg),ImageSY($srcimg));
  705.                           ImageJPEG($destimg,$imageThumbPath100);             
  706.                       }
  707.                         
  708.                     } 
  709.                 $productThumbs[$pId] = $imageThumbPath;
  710.             }
  711.         }
  712.         
  713.         /* we load prices */
  714.         $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  715.         $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  716.         $targetCurrency $session->get('eshopCurrency');
  717.         
  718.         /* we load currency rated prices */
  719.         $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  720.         /* we get price(s) to display */
  721.         $displayPrice null;
  722.         foreach($productPriceList as $price) {
  723.             if($price->getProductId() == $product->getProductId()) {
  724.                 /* we get default price level */
  725.                 if($price->getPriceLevelId() == 1) {
  726.                     $displayPrice round($price->getBruttoValue(),$eshop->getRoundPrice());
  727.                 }
  728.                 
  729.             }
  730.         }
  731.         /* we add product(s) to basket - POST form action */
  732.         if(!empty($request->request->get('basket'))) {
  733.             /* we call method to add to basket */
  734.             $this->addToBasket($request$eshopId$request->request->get('productId'));
  735.         }
  736.         
  737.         $productView $eshop->getProductView();
  738.         
  739.         /*
  740.         print('<br>qqw eshop: '.$eshop->getWireFrameId());
  741.         \Doctrine\Common\Util\Debug::dump($eshop);
  742.         */
  743.     
  744.         /* we render data */
  745.         return $this->render('eshop3DCategory.html.php',
  746.                 array(  'headerData' => $this -> getPageHeader($request),
  747.                         'menu' => $this -> adminMenu($request),
  748.                         'mainMenu' => $this -> adminMainMenu($request),
  749.                         'eshop' => $eshop,
  750.                         'user' => $user,
  751.                         'productView' => $productView,
  752.                         'productList' => $productList,
  753.                         'productPriceList' => $productPriceList,
  754.                         'productThumbs' => $productThumbs,
  755.                         'wireFrame' => $wireFrame,
  756.                         'category' => $category,
  757.                         'childNodes' => $childNodes,
  758.                         'categoryPath' => $categoryPath,
  759.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),
  760.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),
  761.                         'eshopHeader' => $eshopHeader,
  762.                         'eshopFooter' => $eshopFooter,  
  763.                         'homePage' => $homePage,                 
  764.                 )
  765.                 );
  766.     
  767.     }  
  768.     /**
  769.      * @Route("/eshop3dAdmin", name="eshop3dAdmin")
  770.      */
  771.     public function eshop3dAdminAction(Request $request)
  772.     {
  773.         /* we load session data */
  774.         parent::init($request);
  775.         
  776.         $session $request->getSession();
  777.         /* we load entity managers */
  778.         $em $this->doctrine->getManager();
  779.         $dem $this->doctrine->getManager('dynamic_em');     
  780.         
  781.         /* we get current user */
  782.         $currentUserId $session->get('user')->getUserId();
  783.         $user $em->getRepository(User::class)->getUser($currentUserId);
  784.         $userDirs $this->getUserFolderPathsFromUserId($currentUserId);
  785.         /* setting current eshop */
  786.         if(!empty($request->query->get('setCurrent'))) {
  787.             $eshop $em->getRepository(Eshop::class)->getEshop($request->query->get('setCurrent'));
  788.             $em->getRepository(Eshop::class)->setCurrentEshop($currentUserId$request->query->get('setCurrent'));
  789.             $session->set('eshop'$eshop);
  790.             
  791.             $this->addFlash('notice''The eshop '.$eshop->getEshopName().' was set as current one.');
  792.             return $this->redirectToRoute('eshopAdmin');
  793.             
  794.         }
  795.         
  796.         /* we get current website */
  797.         $currentEshop $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);      
  798.       
  799.       /*
  800.         print('<br>qqw currentEshop: ');
  801.         \Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
  802.       */      
  803.       
  804.         /* we load list of eshops for logged user */
  805.         $eshopList $em->getRepository(Eshop::class)->getEshopListByUser($currentUserId);
  806.         /* we prepare array of count(products) */
  807.         $productCountArray = array();
  808.         /*
  809.         foreach($websiteList as $website) {
  810.             $productCountArray[$website->getWebsiteId()] = $dem->getRepository('AppBundle:WebPage')->getWebPageCountByWebsite($website->getWebsiteId());
  811.         } 
  812.         */   
  813.         /*
  814.         $eshopId = $currentEshop->getEshopId();
  815.         $rootNodes = $dem->getRepository(Category::class)->getRootNodes();
  816.         $childNodes = array();
  817.         foreach($rootNodes as $cat) {
  818.             if($cat->getEshopId() == $eshopId) {
  819.                 $childNodes[] = $cat;
  820.                 $childNodeImages[$cat->getCategoryId()] = $this->getImageFromText($cat->getCategoryName(), 'silver-black', $userDirs['images'], $userDirs['web'].'/images');
  821.             }
  822.         } 
  823.         print('<br>qqw Root Nodes: ');
  824.         \Doctrine\Common\Util\Debug::dump($childNodeImages); 
  825.         */ 
  826.         //$childNodeImages[$catId] = $this->getImageFromText($cat->getCategoryName(), 'black-white', $userDirs['images'], $userDirs['web'].'/images');
  827.          
  828.         /* 
  829.         $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.";
  830.         $newText = $this->getImageFromText($text, 'black-white', $userDirs['images'], $userDirs['web'].'/images', 50, 'test_text_image', 500, 27, 12);
  831.         print('<br>QQW image text: <br>'.$newText);
  832.         */
  833.         
  834.         /* we render data */
  835.         return $this->render('eshop3DAdmin.html.twig',
  836.                 array('headerData' => $this -> getPageHeader($request),
  837.                       'eshopList' => $eshopList,
  838.                       'user' => $user,
  839.                       'productCountArray' => $productCountArray,
  840.                       'menu' => $this -> adminMenu($request),
  841.                         'mainMenu' => $this -> adminMainMenu($request),
  842.                 )
  843.                 );
  844.     
  845.     }
  846.     
  847.     public function categoryTreeMenu($eshopRequest $request)
  848.     {    
  849.         
  850.         /* we load session data */
  851.         parent::init($request);
  852.         $session $request->getSession();
  853.         
  854.         /* we load entity managers */
  855.         $em $this->doctrine->getManager();
  856.         $dem $this->doctrine->getManager('dynamic_em');
  857.         
  858.         $userId $eshop->getUserId();
  859.         
  860.         $session->set('eshop'$eshop);
  861.         
  862.         /* we get current e-shop */
  863.         //$eshop = $em->getRepository(Eshop::class)->getCurrentEshop($currentUserId);
  864.       
  865.         $repo $dem->getRepository(Category::class);
  866.          
  867.         $this->dynamicEntityManager $dem;
  868.         $this->currentEshop $eshop;
  869.         $options = array(
  870.                 'decorate' => true,
  871.                 'rootOpen' => '<ul class="tree">',
  872.                 'rootClose' => '</ul>',
  873.                 'childOpen' => function($node) {
  874.         
  875.                     /*
  876.                      print('<br>QQW node: ');
  877.                      \Doctrine\Common\Util\Debug::dump($node);
  878.                      */
  879.         
  880.                     if($node['eshopId'] == $this->currentEshop->getEshopId()) {
  881.                         return '<li class="treeItem">';
  882.                     } else {
  883.                         return '<li class="treeItemHidden">';
  884.                     }
  885.             
  886.                     return '<li class="treeItem">';
  887.                 },
  888.                 'childClose' => '</li>',
  889.                 'nodeDecorator' => function($node) {
  890.                     $url $this->generateUrl('eshop',array('eshopId'=>$this->currentEshop->getEshopId()));
  891.                     return '<a href="'.$url.'/category/'.$node['categoryId'].'" class="treeNodeLink">'.$node['categoryName'].'</a>';
  892.                 }
  893.                 );
  894.          
  895.         $htmlTree $repo->childrenHierarchy(
  896.                 null,
  897.                 false,
  898.                 $options
  899.                 );
  900.          
  901.         return $htmlTree;            
  902.         
  903.     }
  904.     public function categoryTopMenu($eshopRequest $request)
  905.     {    
  906.         /* we load session data */
  907.         parent::init($request);
  908.         $session $request->getSession();
  909.         
  910.         /* we load entity managers */
  911.         $em $this->doctrine->getManager();
  912.         $dem $this->doctrine->getManager('dynamic_em');
  913.         //$categoryList = $dem->getRepository(Eshop::class)->getRootCategoryListByEshop($eshop->getEshopId());
  914.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  915.         $childNodes = array();
  916.         foreach($rootNodes as $cat) {
  917.             if($cat->getEshopId() == $eshop->getEshopId()) {
  918.                 $childNodes[] = $cat;
  919.             }
  920.         }
  921.         
  922.         /*
  923.          print('<br>QQW categoryTopMenu: ');
  924.          \Doctrine\Common\Util\Debug::dump($childNodes);
  925.         */
  926.       return $childNodes;
  927.     }  
  928.     /**
  929.      * @Route("/eshop3d/{eshopId}/basket", name="basket3d")
  930.      */
  931.     public function basket3dAction(Request $request$eshopId)
  932.     {
  933.     
  934.         /* we load session data */
  935.         parent::init($request);
  936.         $session $request->getSession();
  937.         $logger $this->getLogger(null'basket 3D');
  938.         //print('<br>QQW eshop ID: '.$eshopId);
  939.         //\Doctrine\Common\Util\Debug::dump($category);
  940.     
  941.         /* we load entity managers */
  942.         $em $this->doctrine->getManager();
  943.         $dem $this->doctrine->getManager('dynamic_em');
  944.         
  945.         /* we get current e-shop */
  946.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  947.         $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  948.             
  949.         /* we check if eshop exists */
  950.         if($eshop === null) {
  951.             $this->addFlash('error''E-shop with this ID does not exists.');
  952.             return $this->redirectToRoute('eshopHome');
  953.         }
  954.         /* we set iteration to display basket info in 3D template */
  955.         if(empty($session->get('basket3DIteration'))) {
  956.             $session->set('basket3DIteration'1);
  957.         } else {
  958.             $session->set('basket3DIteration', ($session->get('basket3DIteration') + 1));
  959.         }
  960.         $basket3DIteration $session->get('basket3DIteration');
  961.         $targetCurrency $session->get('eshopCurrency');
  962.         $userDirs $this->getUserFolderPathsFromUserId($user->getUserId());
  963.         //print('<br>qqw eshop: ');
  964.         //\Doctrine\Common\Util\Debug::dump($eshop);    
  965.         $eshopId $eshop->getEshopId();
  966.         $rootNodes $dem->getRepository(Category::class)->getRootNodes();
  967.         $childNodes = array();
  968.         $childNodeImages = array();
  969.         $categoryImages = array();
  970.         $products = array();
  971.         $categoryProducts = array();
  972.         $categoryProductImages = array();
  973.         $productListTitles = array();
  974.         $productDescriptions = array();
  975.         if(!empty($session->get('order'))) {
  976.             $order $session->get('order');
  977.         } else {
  978.             $order null;
  979.         }
  980.         if($_SERVER['HTTP_HOST'] != 'localhost') {
  981.             $urlPattern "http://www.easycommerc.com/";
  982.         } else {
  983.             $urlPattern "http://localhost/alliancemarkets2/web/";
  984.         }        
  985.         $debug 1;
  986.         $orderPrice 0;
  987.         if(!empty($order)) {
  988.             $orderPrice $dem->getRepository('AppBundle:Order')->getOrderPrice($order->getOrderId());   
  989.         }
  990.         $basketMessage "Basket message";
  991.         /* we add product(s) to basket - GET action */
  992.         if(!empty($request->get('add2basket'))) {
  993.             /* we call method to add to basket */
  994.             $this->addToBasket($request$eshopId$request->get('productId'));
  995.             $basketMessage "Total amount: ".$orderPrice;
  996.             $basketMessage .= "  |  Adding product id: ".$request->get('productId');
  997.         }        
  998.         if(!empty($request->request->get('debug'))) {   
  999.         //if(!empty($debug)) {    
  1000.             /* we render HTML */
  1001.             $response $this->render('basket3D.html.php',
  1002.                 array(  'headerData' => $this -> getPageHeader($request),
  1003.                         'menu' => $this -> adminMenu($request),
  1004.                         'mainMenu' => $this -> adminMainMenu($request),
  1005.                         'eshop' => $eshop,
  1006.                         'user' => $user,
  1007.                         'userDirs' => $userDirs,
  1008.                         'childNodes' => $childNodes,
  1009.                         'childNodeImages' => $childNodeImages,
  1010.                         'categoryImages' => $categoryImages,
  1011.                         'productListTitles' => $productListTitles,
  1012.                         'productDescriptions' => $productDescriptions,
  1013.                         'products' => $products,
  1014.                         'categoryProducts' => $categoryProducts,
  1015.                         'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),    
  1016.                         'categoryTopMenu' => $this->categoryTopMenu($eshop$request),  
  1017.                         'basket3DIteration' => $basket3DIteration,   
  1018.                         'order' => $order,   
  1019.                         'urlPattern' => $urlPattern,                                                           
  1020.                 )
  1021.                 );   
  1022.         
  1023.         } else {
  1024.             /* we render virtual reality data */
  1025.             $response = new Response(
  1026.               $this->renderView('basket3D.vrml.php',
  1027.                     array(  'headerData' => $this -> getPageHeader($request),
  1028.                             'menu' => $this -> adminMenu($request),
  1029.                         'mainMenu' => $this -> adminMainMenu($request),
  1030.                             'eshop' => $eshop,
  1031.                             'user' => $user,
  1032.                             'userDirs' => $userDirs,
  1033.                             'childNodes' => $childNodes,
  1034.                             'childNodeImages' => $childNodeImages,
  1035.                             'categoryImages' => $categoryImages,
  1036.                             'productListTitles' => $productListTitles,
  1037.                             'productDescriptions' => $productDescriptions,
  1038.                             'products' => $products,
  1039.                             'categoryProducts' => $categoryProducts,
  1040.                             'categoryTreeMenu' => $this->categoryTreeMenu($eshop$request),    
  1041.                             'categoryTopMenu' => $this->categoryTopMenu($eshop$request),                
  1042.                             'logger' => $logger,
  1043.                             'basketMessage' => $basketMessage,
  1044.                             'basket3DIteration' => $basket3DIteration
  1045.                             'order' => $order
  1046.                             'urlPattern' => $urlPattern,                             
  1047.                     )
  1048.               
  1049.               ), 200
  1050.             );
  1051.             $response->headers->set('Content-Type''model/vrml');
  1052.         }
  1053.         return $response;  
  1054.     }    
  1055.     public function addToBasket(Request $request$eshopId$productId)
  1056.     {
  1057.         //print("<br>qqw adding to basket pid: ".$productId);
  1058.         /* we load session data */
  1059.         parent::init($request);
  1060.         $session $request->getSession();
  1061.         //print('<br>QQW eshop ID: '.$eshopId);
  1062.         //\Doctrine\Common\Util\Debug::dump($category);
  1063.     
  1064.         /* we load entity managers */
  1065.         $em $this->doctrine->getManager();
  1066.         $dem $this->doctrine->getManager('dynamic_em');
  1067.             /* we load product */
  1068.             $product $dem->getRepository(Product::class)->getProduct($productId);
  1069.             /* we get price levels */
  1070.             $priceLevelCollection $dem->getRepository('AppBundle:PriceLevel')->getPriceLevelList();
  1071.             /* we get current e-shop */
  1072.             $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);    
  1073.             $eshopCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());        
  1074.             
  1075.             /* if there is no order in basket then we create new order */
  1076.             if(empty($session->get('order'))) {
  1077.                 //print('<br>QQW Creating New Order');
  1078.                 $order = new Order;
  1079.                 $order->setEshopId($eshopId);
  1080.                 $session->set('order'$order);
  1081.                 $session->get('order')->setIp($request->getClientIp());
  1082.             }    
  1083.             /* we set product units */ 
  1084.             $units 1;
  1085.             if(!empty($request->request->get('units'))) {
  1086.                 $unitInt intval($request->request->get('units'));
  1087.                 if($unitInt 0) {
  1088.                   $units $request->request->get('units');  
  1089.                 } else {
  1090.                   $units 1;  
  1091.                 }
  1092.             }   
  1093.             /* we check if we have this order item in basket already */     
  1094.             $isInBasket false;
  1095.             foreach($session->get('order')->getOrderItems() as $orderItem) {
  1096.               if($orderItem->getProductId() == $product->getProductId()) {
  1097.                 //print('<br>qqw item exists in basket');
  1098.                 $orderItem->setOrderItemUnits($orderItem->getOrderItemUnits() + $units); 
  1099.                 $isInBasket true;
  1100.               } 
  1101.             }  
  1102.             
  1103.             if(!$isInBasket) {
  1104.               /* we create order item and load it with product data */
  1105.               //print('<br>qqw product is NOT in basket yet');
  1106.               $orderItem = new OrderItem;
  1107.               $orderItem->setOrderItemTitle($product->getProductName());
  1108.               //print('<br>qqw units: '.$units);
  1109.               $orderItem->setOrderItemUnits($units);
  1110.               $orderItem->setProductId($product->getProductId());
  1111.               //$itemPrice = $units * $request->request->get('productPrice');
  1112.               /* we set price */
  1113.               $displayPrice null;
  1114.               /* product prices */
  1115.                 foreach($priceLevelCollection as $priceLevel) {
  1116.                     /* we check if the price for this product and price level exists */
  1117.                     $productPrice $dem->getRepository('AppBundle:Price')->getPrice(intval($productId), $priceLevel->getPriceLevelId());
  1118.                     if($productPrice == null) {
  1119.                         $priceValue '';
  1120.                         $priceSuffix2 '';
  1121.                     } else {
  1122.                         if(!empty($eshop->getDisplayNettoPrices()) && $eshop->getDisplayNettoPrices()==true) {
  1123.                           $priceValue $productPrice->getNettoValue();
  1124.                           $priceSuffix2 'netto';
  1125.                         } else {
  1126.                           $priceValue $productPrice->getBruttoValue();   
  1127.                           $priceSuffix2 'brutto';                                   
  1128.                         }
  1129.                     }  
  1130.                     $displayPrice $priceValue;
  1131.                 }
  1132.               /*
  1133.               foreach($product->getPrices() as $price) {
  1134.                 $displayPrice = 22;
  1135.                 // we get default price level
  1136.                 if($price->getPriceLevelId() == 1) {
  1137.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  1138.                     $displayPrice = round($price->getNettoValue(),$eshop->getRoundPrice());
  1139.                 }                
  1140.               }
  1141.               */
  1142.               $orderItem->setOrderItemPrice($displayPrice);
  1143.               $orderItem->setCurrencyKey($eshopCurrency->getCurrencyKey());
  1144.               $session->get('order')->addOrderItem($orderItem);
  1145.             }
  1146.             
  1147.             $orderItemId $dem->getRepository('AppBundle:Order')->getMaxOrderItemId($session->get('order'));
  1148.             //$orderItem->setOrderItemId(2);
  1149.             //product.added_to_basket
  1150.             //$this->addFlash('notice', $this->translator->trans('product.added_to_basket').'<a href="/eshop/'.$eshopId.'/basket" class="viewBasket">'.$this->translator->trans('eshop.basket_view').'</a>');
  1151.             /*
  1152.             print('<br>qqw basket items: ');
  1153.             \Doctrine\Common\Util\Debug::dump($session->get('order')->getOrderItems());
  1154.             */
  1155.             
  1156.     }      
  1157.          
  1158.     /**
  1159.      * @Route("/eshop3DEdit/{eshopId}", name="eshop3DEdit")
  1160.      */
  1161.     public function eshop3DEditAction(Request $request$eshopId)
  1162.     {
  1163.     
  1164.         /* we load session data */
  1165.         parent::init($request);
  1166.         $session $request->getSession();
  1167.         
  1168.         /* we check if an user is logged in */
  1169.         if(empty($session->get('user'))) {
  1170.             return $this->redirectToRoute('login');
  1171.         }   
  1172.     
  1173.         /* we load entity managers */
  1174.         $em $this->doctrine->getManager();
  1175.         $dem $this->doctrine->getManager('dynamic_em');
  1176.          
  1177.         $userId $session->get('user')->getUserId();  
  1178.         
  1179.             
  1180.         
  1181.         /* we get current user */
  1182.         $user $em->getRepository(User::class)->getUser($userId);           
  1183.         /* we get current e-shop */
  1184.         $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  1185.         /* we get current 3D eshop */
  1186.         $eshop3D $dem->getRepository(Eshop3D::class)->getEshop3DByEshopId($eshopId);
  1187.         
  1188.         if(empty($eshop3D)) {
  1189.             $eshop3D = new Eshop3D;
  1190.         $eshop3D->setEshop3DName($eshop->getEshopName());
  1191.         $eshop3D->setUserId($userId);
  1192.         /* we persist and save */
  1193.         $dem->persist($eshop3D);
  1194.         $dem->flush();
  1195.         }         
  1196.         /* we get eshop list  */
  1197.         $eshopCollection $dem->getRepository(Eshop::class)->getEshopListByUser($userId);   
  1198.         /* we get free worlds */
  1199.         $freeWorldCollection $dem->getRepository(FreeWorld3D::class)->getFreeWorld3DList();
  1200.         /* we get gallery list  */
  1201.         $galleryCollection $dem->getRepository(Gallery::class)->getGalleryListByUser($userId);
  1202.         $galleryItemCollection null;
  1203.         if(!empty($eshop3D) && !empty($eshop3D->getTextureGallery())) {
  1204.             $galId $eshop3D->getTextureGallery()->getGalleryId();
  1205.             $galleryItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($galId);
  1206.         }           
  1207.         /* we find 3D templates */
  1208.         $rootDir $this->appKernel->getProjectDir();
  1209.         $views $rootDir.'/templates/eshop3D/';
  1210.         $finder = new Finder();
  1211.         $finder->in($views);       
  1212.    
  1213.         /* we build edit form */
  1214.         $formBuilder $this->createFormBuilder();
  1215.         
  1216.         $userDirs $this->getUserFolderPaths($request);
  1217.         $formBuilder->add('eshopName'TextType::class, array(
  1218.                 'required' => true,
  1219.                 'label' => $this->translator->trans('module.eshop_name'),
  1220.                 'attr' => array('class' => 'text_form''size' => 50'value' => $eshop3D->getEshop3DName()),
  1221.                 'label_attr' => array('class' => 'form_field_label')
  1222.         ));
  1223.         $formBuilder->add('eshopLogoUrl'TextType::class, array(
  1224.                 'required' => false,
  1225.                 'label' => $this->translator->trans('system.logo_url'),
  1226.                 'attr' => array('class' => 'text_form''size' => 50'value' => $eshop3D->getEshopLogoUrl()),
  1227.                 'label_attr' => array('class' => 'form_field_label')
  1228.         ));   
  1229.         /*
  1230.         $formBuilder->add('template3DPath', TextType::class, array(
  1231.                 'required' => false,
  1232.                 'label' => $this->translator->trans('module.gallery3D_template'),
  1233.                 'attr' => array('class' => 'text_form', 'size' => 50, 'value' => $gallery->getTemplate3DPath()),
  1234.                 'label_attr' => array('class' => 'form_field_label')
  1235.         ));
  1236.         */           
  1237.         $formBuilder->add('eshopDescription'TextAreaType::class, array(
  1238.                 'required' => false,
  1239.                 'label' => $this->translator->trans('module.eshopLink_description'),
  1240.                 'attr' => array('class' => 'textarea_form''cols' => 77'rows' => 5'value' => $eshop3D->getEshop3DDescription()),
  1241.                 'label_attr' => array('class' => 'form_textarea_label2'),
  1242.                 'data' => $eshop3D->getEshop3DDescription(),
  1243.         ));   
  1244.         /* we add eshop list */
  1245.         $eshops = array();
  1246.         $eshops['-- select --'] = 0;
  1247.         foreach($eshopCollection as $shop)
  1248.         {
  1249.             $shopId $shop->getEshopId();
  1250.             //print('<br>qqw shop: '.$shopId);
  1251.             $shopKey $shop->getEshopName().' (id:'.$shop->getEshopId().')';
  1252.             $eshops[$shopKey] = $shopId;
  1253.              
  1254.         }
  1255.          
  1256.         $selectedEshop 0;
  1257.         if(!empty($eshop3D->getEshop())) {
  1258.             $selectedEshop $eshop3D->getEshop()->getEshopId();
  1259.         }      
  1260.          
  1261.         $formBuilder->add('xmlSourcePath'TextType::class, array(
  1262.                 'required' => false,
  1263.                 'label' => $this->translator->trans('system.xml_source'),
  1264.                 'attr' => array('class' => 'text_form''size' => 50'value' => $eshop3D->getXmlSourcePath()),
  1265.                 'label_attr' => array('class' => 'form_field_label')
  1266.         )); 
  1267.         $formBuilder->add('eshopId'ChoiceType::class, array(
  1268.                 'choices' => $eshops,
  1269.                 'label' => $this->translator->trans('module.eshop_parent'),
  1270.                 'attr' => array('class' => 'selector'),
  1271.                 'label_attr' => array('class' => 'form_field_label'),
  1272.                 'data' => $selectedEshop
  1273.         ));   
  1274.           
  1275.         /* we add gallery list */
  1276.         $galleries = array();
  1277.         $galleries['-- select --'] = 0;
  1278.         foreach($galleryCollection as $gal)
  1279.         {
  1280.             $galId $gal->getGalleryId();
  1281.             //print('<br>qqw dep: '.$depId);
  1282.             $galKey $gal->getGalleryName().' (id:'.$gal->getGalleryId().')';
  1283.             $galleries[$galKey] = $galId;
  1284.              
  1285.         }
  1286.          
  1287.         $selectedGallery 0;
  1288.         if(!empty($eshop3D->getTextureGallery())) {
  1289.             $selectedGallery $eshop3D->getTextureGallery()->getGalleryId();
  1290.         }      
  1291.         $formBuilder->add('textureGalleryId'ChoiceType::class, array(
  1292.                 'choices' => $galleries,
  1293.                 'label' => $this->translator->trans('module.gallery_texture'),
  1294.                 'attr' => array('class' => 'selector'),
  1295.                 'label_attr' => array('class' => 'form_field_label'),
  1296.                 'data' => $selectedGallery
  1297.         )); 
  1298.         /* we add 3D template list */
  1299.         $templates3D = array();
  1300.         foreach ($finder as $file) {
  1301.             $templates3D[$file->getRelativePathname()] = $file->getRelativePathname();
  1302.         }
  1303.          
  1304.         $selectedTemplate3D 0;
  1305.         if(!empty($eshop3D->getTemplate3DPath())) {
  1306.             $selectedTemplate3D $eshop3D->getTemplate3DPath();
  1307.         }      
  1308.         $formBuilder->add('template3DPath'ChoiceType::class, array(
  1309.                 'choices' => $templates3D,
  1310.                 'label' => $this->translator->trans('module.gallery3D_template'),
  1311.                 'attr' => array('class' => 'selector'),
  1312.                 'label_attr' => array('class' => 'form_field_label'),
  1313.                 'data' => $selectedTemplate3D
  1314.         ));     
  1315.         
  1316.         /* we add free world list */
  1317.         $freeWorlds = array();
  1318.         foreach($freeWorldCollection as $freeWorld)
  1319.         {
  1320.             $freeWorldId $freeWorld->getFreeWorld3DId();
  1321.             $freeWorlds[$freeWorld->getFreeWorld3DName()] = $freeWorld->getFreeWorld3DId();
  1322.         }
  1323.         $selectedFreeWorlds = array();
  1324.         foreach($eshop3D->getFreeWorlds() as $freeWorld) {
  1325.             $selectedFreeWorlds[] = $freeWorld->getFreeWorld3DId();
  1326.         }
  1327.          
  1328.         $formBuilder->add('freeWorlds'ChoiceType::class, array(
  1329.                 'choices' => $freeWorlds,
  1330.                 'required' => false,
  1331.                 'mapped' => false,
  1332.                 'multiple' => true,
  1333.                 'expanded' => true,
  1334.                 'label_attr' => array('class' => 'form_field_label'),
  1335.                 'attr' => array('class' => 'form_field_text'),
  1336.                 'data' => $selectedFreeWorlds
  1337.         ));               
  1338.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  1339.                 'attr' => array('class' => 'butt_big')));       
  1340.         
  1341.         $form $formBuilder->getForm();
  1342.         $form->handleRequest($request);
  1343.          
  1344.         if ($request->getMethod() == 'POST') {
  1345.     
  1346.             //$form->bindRequest($request);
  1347.     
  1348.             if ($form->isValid()) {
  1349.                 // save the object to the database
  1350.                 $eshop3D->setEshop3DName($request->request->get('form')['eshopName']);
  1351.                 
  1352.             /* we remove old freeWorld associations */
  1353.             foreach($eshop3D->getFreeWorlds() as $freeWorld) {
  1354.                 $eshop3D->removeFreeWorld($freeWorld);
  1355.             }
  1356.                 
  1357.             /* we load selected freeWorlds */
  1358.             if(!empty($request->request->get('form')['freeWorlds'])) {
  1359.                 foreach($request->request->get('form')['freeWorlds'] as $freeWorldId) {
  1360.                     $addFreeWorld $dem->getRepository(FreeWorld3D::class)->getFreeWorld3D($freeWorldId);
  1361.                     $eshop3D->addFreeWorld($addFreeWorld);
  1362.                 }
  1363.             }                
  1364.                 if(!empty($request->request->get('form')['eshopDescription'])) {
  1365.                     $eshop3D->setEshop3DDescription($request->request->get('form')['eshopDescription']);
  1366.                 }
  1367.                 $eshop3D->setEshopLogoUrl($request->request->get('form')['eshopLogoUrl']);
  1368.                 $eshop3D->setXmlSourcePath($request->request->get('form')['xmlSourcePath']);
  1369.                 $eshop3D->setTemplate3DPath($request->request->get('form')['template3DPath']);
  1370.                 if(!empty($request->request->get('form')['eshopId']) && $request->request->get('form')['eshopId']>0) {
  1371.                     $newEshop $dem->getRepository(Eshop::class)->getEshop($request->request->get('form')['eshopId']);
  1372.                     $eshop3D->setEshop($newEshop);
  1373.                 } 
  1374.                 /*
  1375.                 else {
  1376.                     $newEshop = $dem->getRepository(Eshop::class)->getEshop($eshopId);
  1377.                     $eshop3D->setEshop($newEshop);
  1378.                 }  
  1379.                 */ 
  1380.                 if(!empty($request->request->get('form')['textureGalleryId']) && $request->request->get('form')['textureGalleryId']>0) {
  1381.                     $textureGallery $dem->getRepository(Gallery::class)->getGallery($request->request->get('form')['textureGalleryId']);
  1382.                     $eshop3D->setTextureGallery($textureGallery);
  1383.                 } else {
  1384.                     $eshop3D->setTextureGallery(null);
  1385.                 }                
  1386.                 /* we persist and save */
  1387.                 $dem->persist($eshop3D);
  1388.                 $dem->flush();
  1389.     
  1390.                 $this->addFlash('notice''3D Eshop was updated.');
  1391.     
  1392.                 return $this->redirectToRoute('eshop3DEdit', array('eshopId' => $eshop3D->getEshop()->getEshopId()));
  1393.                  
  1394.             }
  1395.     
  1396.         }
  1397.         /* we render data */
  1398.         return $this->render('eshop3DEdit.html.twig',
  1399.                 array('headerData' => $this -> getPageHeader($request),
  1400.                         'eshop3D' => $eshop3D,
  1401.                         'form' => $formBuilder->getForm()->createView(),
  1402.                         'user' => $user,
  1403.                         'userDirs' => $userDirs,
  1404.                         'galleryItemCollection' => $galleryItemCollection,
  1405.                         'menu' => $this -> adminMenu($request),
  1406.                         'mainMenu' => $this -> adminMainMenu($request),
  1407.                 )
  1408.                 );
  1409.     
  1410.     }    
  1411.     
  1412.     public function adminMenu(Request $request)
  1413.     {
  1414.         $menuItems = array(=> array('link' => 'services3dAdmin''langKey' => 'service.services3d''routeName' => 'services3dAdmin'),
  1415.                 => array('link' => 'eshop3dAdmin''langKey' => 'module.eshop3dAdmin''routeName' => 'eshop3dAdmin')
  1416.         );
  1417.         
  1418.         return $menuItems;
  1419.     
  1420.     }     
  1421. }