src/Controller/MarketplaceController.php line 124

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\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  13. use Symfony\Component\Console\Input\ArrayInput;
  14. use Symfony\Bundle\FrameworkBundle\Console\Application;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use App\Entity\User;
  18. use App\Entity\Server;
  19. use App\Entity\Service;
  20. use App\Entity\Module;
  21. use App\Entity\EshopLink;
  22. use App\Entity\Feed;
  23. use App\Entity\Language;
  24. use App\Entity\Department;
  25. use App\Entity\Product;
  26. use App\Entity\ShoppingWindow;
  27. use Symfony\Contracts\Translation\TranslatorInterface;
  28. class MarketplaceController extends DefaultController
  29. {
  30.     protected ManagerRegistry $doctrine;
  31.     protected TranslatorInterface $translator;
  32.     public function __construct(ManagerRegistry $doctrine,
  33.                                 TranslatorInterface $translator)
  34.     {
  35.         $this->doctrine $doctrine;
  36.         $this->translator $translator;
  37.     }
  38.     /**
  39.      * @Route("/marketplace", name="marketplace")
  40.      */
  41.     public function marketplaceAction(Request $request)
  42.     {
  43.         // we load session data
  44.         parent::init($request);
  45.         $session $request->getSession();
  46.         // we load entity managers
  47.         $em $this->doctrine->getManager();
  48.         
  49.         $hostServer $em->getRepository(Server::class)->getServerFromHost($_SERVER['HTTP_HOST']);
  50.         //$hostServer->getParentSectionId()
  51.         
  52.         //$treeObject = $em->getRepository(Department::class)->getTree();
  53.         $treeObject null
  54.         
  55.         $rootDepartments $em->getRepository(Department::class)->getRootNodes();
  56.         
  57.         // we get root departments 
  58.         if (!empty($hostServer->getParentSectionId()) && $hostServer->getParentSectionId() > 0) {
  59.         
  60.             $customRootDepartment $em->getRepository(Department::class)->getDepartment($hostServer->getParentSectionId());
  61.             $treeObject->createRoot($customRootDepartment);
  62.             $tree $treeObject->fetchTree();
  63.         
  64.             $rootDepartments $tree->getRootNodes();
  65.         } else {
  66.             $rootDepartments $em->getRepository(Department::class)->getRootNodes();
  67.         }
  68.         
  69.         // we add sub departments
  70.         $subDepartments = array();
  71.         foreach($rootDepartments as $dep)
  72.         {
  73.             $depId $dep->getDepartmentId();
  74.             $dep->setLocale($session->get('lang')->getLangKey());
  75.             $em->refresh($dep);
  76.             $subDeps $em->getRepository(Server::class)->getSubDepartments($depId);
  77.             $subDepartments[$depId] = $subDeps;
  78.         }          
  79.         $service $em->getRepository(Service::class)->getService(4);
  80.         /* we load list of departments for marketplace service */
  81.         $departmentArray[] =  $em->getRepository(Server::class)->getDepartment(4);
  82.         $departmentArray[] =  $em->getRepository(Server::class)->getDepartment(9);
  83.          /* we load list of shopping windows */
  84.         $shoppingWindowList $em->getRepository(ShoppingWindow::class)->getShoppingWindowList($departmentArray06);
  85.         foreach($shoppingWindowList as $shoppingWindow)
  86.         {        
  87.             //print('<hr>qqw shoppingWindow: ');
  88.             //\Doctrine\Common\Util\Debug::dump($shoppingWindow);
  89.         }
  90.         //print('<hr>qqw shoppingWindowList: ');
  91.         //\Doctrine\Common\Util\Debug::dump($shoppingWindowList);       
  92.         
  93.         /* we render data */
  94.         return $this->render('marketplace.html.twig',
  95.             array('headerData' => $this -> getPageHeader($request),
  96.                   'rootDepartments' => $rootDepartments,
  97.                   'subDepartments' => $subDepartments,                  
  98.                   'moduleList' => $service->getModules(),
  99.                   'service' => $service,    
  100.                   'shoppingWindowList' => $shoppingWindowList,                                   
  101.                 )
  102.         );        
  103.     }
  104.     /**
  105.      * @Route("/marketplace/department/{departmentId}", name="department")
  106.      */
  107.     public function departmentAction(Request $request$departmentId)
  108.     {
  109.         /* we load session data */
  110.         parent::init($request);
  111.         $session $request->getSession();
  112.         /* we load entity managers */
  113.         $em $this->doctrine->getManager();
  114.         /* we get root departments */
  115.         $department $em->getRepository(Server::class)->getDepartment($departmentId);
  116.         $department->setLocale($session->get('lang')->getLangKey());
  117.         $em->refresh($department);
  118.         $departmentPath $em->getRepository(Department::class)->getPath($department);
  119.         foreach ($departmentPath as $dep) {
  120.             $dep->setLocale($session->get('lang')->getLangKey());
  121.             $em->refresh($dep);
  122.         }
  123.         //print('<br>departmentPath: ');
  124.         //\Doctrine\Common\Util\Debug::dump($departmentPath);
  125.         $childDepartments $department->getChildren();
  126.         //$childDepartments = $em->getRepository(Department::class)->getRootNodes();
  127.         /* we get languages */
  128.         $langCollection $em->getRepository(Language::class)->getLanguageList();
  129.         /* we get e-shop links */
  130.         $eshopLinkList $em->getRepository(EshopLink::class)->getEshopLinkListByDepartment($departmentId);
  131.         //$eshopLink = $em->getRepository(EshopLink::class)->getEshopLink($request->query->get('setCurrent'));
  132.         // we get root departments
  133.         $rootDepartments $em->getRepository(Department::class)->getRootNodes();
  134.         // we add sub departments
  135.         $subDepartments = array();
  136.         foreach($childDepartments as $dep)
  137.         {
  138.             $depId $dep->getDepartmentId();
  139.             $dep->setLocale($session->get('lang')->getLangKey());
  140.             $em->refresh($dep);
  141.             $subDeps $em->getRepository(Server::class)->getSubDepartments($depId);
  142.             $subDepartments[$depId] = $subDeps;
  143.         }    
  144.         $departmentArray = array();
  145.         $departmentArray[] = $department;
  146.         /* we get product list */
  147.         $productPerPage 20;
  148.         $page $request->query->get('page');
  149.         $firstRecord = ($page $productPerPage) - $productPerPage;
  150.         if($firstRecord 1) {
  151.             $firstRecord 0;
  152.         }
  153. //        print('<br>DepartmentArray: ');
  154. //        \Doctrine\Common\Util\Debug::dump($departmentArray);
  155.         $productList $em->getRepository(Product::class)->getProductListByDepartment($departmentArray$firstRecord$productPerPage);
  156.         $productCount $em->getRepository(Product::class)->getProductCountByDepartment($departmentArray);
  157. //        print('<br>productList:');
  158. //        \Doctrine\Common\Util\Debug::dump($productList);
  159.         
  160.         $productIds = array();
  161.         foreach($productList as $product) {
  162.             $pId $product->getProductId();
  163.             $product->setLocale($session->get('lang')->getLangKey());
  164.             $em->refresh($product);
  165.             $productIds[] = $pId;
  166.             /* we setup product names - if empty then we load multilingual values */
  167.             $productName '';
  168.             if(!empty($product->getProductName()) && $product->getProductName() != '') {
  169.                 $productName $product->getProductName();
  170.             } else {
  171.                 //we try to get the product name from multilangual fields 
  172.                 foreach($langCollection as $lang) {
  173.                     $product->setLocale($lang->getLangKey());
  174.                     $em->refresh($product);
  175.                     if(!empty($product->getProductName()) && $product->getProductName() != '') {
  176.                         $productName $product->getProductName();
  177.                     }
  178.                 }
  179.             }
  180.             //print('<br>qqw pname 1: '.$productName);
  181.             $product->setProductName($productName);
  182.             $em->flush();            
  183.         }
  184. //        print('<br>productIds: ');
  185. //        \Doctrine\Common\Util\Debug::dump($productIds);
  186.         /* we load prices */
  187.         $productPriceList $em->getRepository(Product::class)->getProductPriceList($productIds);
  188.         //$defaultCurrency = $em->getRepository('AppBundle:Currency')->getCurrency($eshop->getPreferredCurrencyId());
  189.         //$targetCurrency = $session->get('eshopCurrency');
  190.         
  191.         /* we load currency rated prices */
  192.         //$productPriceList = $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList, $defaultCurrency, $targetCurrency);
  193.         /* we get price(s) to display */
  194. //        print('<br>productPriceList: ');
  195. //        \Doctrine\Common\Util\Debug::dump($productPriceList);
  196.         
  197.         $displayPrice null;
  198.         foreach($productPriceList as $price) {
  199. //            print('<hr>productPrice: ');
  200. //            \Doctrine\Common\Util\Debug::dump($price);
  201.             if($price->getProductId() == $product->getProductId()) {
  202.                 // we get default price level 
  203.                 if($price->getPriceLevelId() == 1) {
  204.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  205.                     $displayPrice round($price->getNettoValue(),2);
  206.                 }
  207.                 
  208.             }
  209.         }
  210.         
  211.         /* we render data */
  212.         return $this->render('marketplaceDepartment.html.twig',
  213.             array('headerData' => $this -> getPageHeader($request),
  214.                   'childDepartments' => $childDepartments,
  215.                   'department' => $department,
  216.                   'departmentPath' => $departmentPath,
  217.                   'eshopLinkList' => $eshopLinkList,
  218.                   'productList' => $productList,
  219.                   'productPriceList' => $productPriceList,
  220.                   'productCount' => $productCount,
  221.                   'subDepartments' => $subDepartments,   
  222.                 )
  223.         );        
  224.     }
  225.     /**
  226.      * @Route("/marketplace/product/{productId}", name="marketplaceProduct")
  227.      */
  228.     public function marketplaceProductAction(Request $request$productId)
  229.     {
  230.         /* we load session data */
  231.         parent::init($request);
  232.         /* we load entity managers */
  233.         $em $this->doctrine->getManager();
  234.         /* we get product */
  235.         $product $em->getRepository(Product::class)->getProduct($productId);
  236.         if(empty($product)) {
  237.             $this->addFlash('error''Product with this ID does not exist.');
  238.             return $this->redirectToRoute('marketplace');     
  239.         }
  240.         if(!empty($request->get('redirect_to_eshop'))) {
  241.             print('<br>redirect_to_eshop ...');
  242.             $clickedCount = (int)$product->getClickedCount();
  243.             $product->setClickedCount($clickedCount 1);
  244.             $em->persist($product);
  245.             $em->flush();
  246.             return $this->redirect($product->getProductLink());
  247.         }
  248.         /*
  249.         $departmentPath = $em->getRepository(Department::class)->getPath($department);
  250.         $childDepartments = $department->getChildren();
  251.         //$childDepartments = $em->getRepository(Department::class)->getRootNodes();
  252.         */
  253.         /*
  254.         print('<br>qqw eshopLinkList: ');
  255.         \Doctrine\Common\Util\Debug::dump($eshopLinkList);
  256.         */
  257.         /* we load prices */
  258.         $productIds = [];
  259.         $productIds[] = $product->getProductId();
  260.         $productPriceList $em->getRepository(Product::class)->getProductPriceList($productIds);
  261.         $displayPrice null;
  262.         foreach($productPriceList as $price) {
  263. //            print('<hr>productPrice: ');
  264. //            \Doctrine\Common\Util\Debug::dump($price);
  265.             if($price->getProductId() == $product->getProductId()) {
  266.                 // we get default price level
  267.                 if($price->getPriceLevelId() == 1) {
  268.                     //$displayPrice = round($price->getBruttoValue(),$eshop->getRoundPrice());
  269.                     $displayPrice round($price->getNettoValue(),2);
  270.                 }
  271.             }
  272.         }
  273.         // increments product view count
  274.         $viewedCount = (int)$product->getViewedCount();
  275.         $product->setViewedCount($viewedCount 1);
  276.         $em->persist($product);
  277.         $em->flush();
  278.     
  279.         /* we render data */
  280.         return $this->render('marketplaceProduct.html.twig',
  281.             array('headerData' => $this -> getPageHeader($request),
  282.                   'product' => $product,
  283.                   'productPriceList' => $productPriceList,
  284.                 )
  285.         );        
  286.     }    
  287.     /**
  288.      * @Route("/marketplaceAdmin", name="marketplaceAdmin")
  289.      */
  290.     public function marketplaceAdminAction(Request $request)
  291.     {
  292.         /* we load session data */
  293.         parent::init($request);
  294.         $session $request->getSession();
  295.         /* we load entity managers */
  296.         $em $this->doctrine->getManager();
  297.         $dem $this->doctrine->getManager('dynamic_em');
  298.         /* we get current user */
  299.         $currentUserId $session->get('user')->getUserId();
  300.         $user $em->getRepository(User::class)->getUser($currentUserId);
  301.         /* eshopLink module */
  302.         $moduleId 19;
  303.         $module $em->getRepository(Module::class)->getModule($moduleId);
  304.         $eshopLinkList null;
  305.         $isEshopLinkModule $em->getRepository(User::class)->userHasModule($user$module);
  306.         if($isEshopLinkModule) {
  307.             /* setting current eshopLink */
  308.             if(!empty($request->query->get('setCurrent'))) {
  309.                 $eshopLink $em->getRepository(EshopLink::class)->getEshopLink($request->query->get('setCurrent'));
  310.                 $em->getRepository(EshopLink::class)->setCurrentEshopLink($currentUserId$request->query->get('setCurrent'));
  311.                 $session->set('eshopLink'$eshopLink);
  312.                 
  313.                 $this->addFlash('notice''The eshop link '.$eshopLink->getEshopLinkName().' was set as current one.');
  314.                 return $this->redirectToRoute('marketplaceAdmin');
  315.                 
  316.             }
  317.             /* we get current e-shop link */
  318.             $currentEshopLink $em->getRepository(EshopLink::class)->getCurrentEshopLink($currentUserId);
  319.           
  320.           /*
  321.             print('<br>qqw currentEshop: ');
  322.             \Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
  323.           */      
  324.           
  325.             /* we load list of eshop links for logged user */
  326.             $eshopLinkList $em->getRepository(EshopLink::class)->getEshopLinkListByUser($currentUserId);
  327.         }
  328.         /* feed module */
  329.         $moduleId 20;
  330.         $module $em->getRepository(Module::class)->getModule($moduleId);
  331.         $feedList null;
  332.         $isFeedModule $em->getRepository(User::class)->userHasModule($user$module);
  333.         if($isFeedModule) {
  334.             /* setting current feed */
  335.             if(!empty($request->query->get('setCurrent'))) {
  336.                 $feed $em->getRepository(Feed::class)->getFeed($request->query->get('setCurrent'));
  337.                 $em->getRepository(Feed::class)->setCurrentFeed($currentUserId$request->query->get('setCurrent'));
  338.                 $session->set('feed'$feed);
  339.                 
  340.                 $this->addFlash('notice''The feed '.$feed->getFeedName().' was set as current one.');
  341.                 return $this->redirectToRoute('marketplaceAdmin');
  342.                 
  343.             }
  344.             /* we get current feed */
  345.             $currentFeed $em->getRepository(Feed::class)->getCurrentFeed($currentUserId);
  346.           
  347.           /*
  348.             print('<br>qqw currentEshop: ');
  349.             \Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
  350.           */      
  351.           
  352.             /* we load list of feeds for logged user */
  353.             $feedList $em->getRepository(Feed::class)->getFeedListByUser($currentUserId);
  354.         }
  355.         /* we load list of modules for marketplace service */
  356.         $service $em->getRepository(Service::class)->getService(4);
  357.         /* we render data */
  358.         return $this->render('marketplaceAdmin.html.twig',
  359.             array('headerData' => $this -> getPageHeader($request),
  360.                   'moduleList' => $service->getModules(),
  361.                   'userModuleList' => $user->getModules(),  
  362.                   'eshopLinkList' => $eshopLinkList,
  363.                   'feedList' => $feedList,
  364.                   'isEshopLinkModule' => $isEshopLinkModule,
  365.                   'isFeedModule' => $isFeedModule,
  366.                   'menu' => $this -> adminMenu($request),
  367.                   'mainMenu' => $this -> adminMainMenu($request),
  368.                     'user' => $user,
  369.                 )
  370.         );        
  371.     }
  372.     /**
  373.      * @Route("/eshopLinkAdmin", name="eshopLinkAdmin")
  374.      */
  375.     public function eshopLinkAdminAction(Request $request)
  376.     {
  377.         /* we load session data */
  378.         parent::init($request);
  379.         $session $request->getSession();
  380.         /* we load entity managers */
  381.         $em $this->doctrine->getManager();
  382.         $dem $this->doctrine->getManager('dynamic_em');
  383.         
  384.         /* we get current user */
  385.         $currentUserId $session->get('user')->getUserId();
  386.         $user $em->getRepository(User::class)->getUser($currentUserId);
  387.         /* setting current eshopLink */
  388.         if(!empty($request->query->get('setCurrent'))) {
  389.             $eshopLink $em->getRepository(EshopLink::class)->getEshopLink($request->query->get('setCurrent'));
  390.             $em->getRepository(EshopLink::class)->setCurrentEshopLink($currentUserId$request->query->get('setCurrent'));
  391.             $session->set('eshopLink'$eshopLink);
  392.             
  393.             $this->addFlash('notice''The eshop link '.$eshopLink->getEshopLinkName().' was set as current one.');
  394.             return $this->redirectToRoute('eshopLinkAdmin');
  395.             
  396.         }
  397.         
  398.         /* we get current e-shop link */
  399.         $currentEshopLink $em->getRepository(EshopLink::class)->getCurrentEshopLink($currentUserId);
  400.       
  401.       /*
  402.         print('<br>qqw currentEshop: ');
  403.         \Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
  404.       */      
  405.       
  406.         /* we load list of eshop links for logged user */
  407.         $eshopLinkList $em->getRepository(EshopLink::class)->getEshopLinkListByUser($currentUserId);
  408.         /* we render data */
  409.         return $this->render('eshopLinkAdmin.html.twig',
  410.             array('headerData' => $this -> getPageHeader($request),
  411.                   'eshopLinkList' => $eshopLinkList,
  412.                   'menu' => $this -> adminMenu($request),
  413.                   'mainMenu' => $this -> adminMainMenu($request),
  414.                   'user' => $user,
  415.                 )
  416.         );        
  417.     }    
  418.     /**
  419.      * @Route("/addproducts", name="eshopLinkNew")
  420.      */
  421.     public function eshopLinkNewAction(Request $request)
  422.     {
  423.         /* we load session data */
  424.         parent::init($request);
  425.          
  426.         $session $request->getSession();
  427.         $em $this->doctrine->getManager();
  428.         $departmentCollection $em->getRepository(Server::class)->getDepartmentList();
  429.         /* we get current user */
  430.         if (!empty($session->get('user'))) {
  431.             $currentUserId $session->get('user')->getUserId();
  432.             $user $em->getRepository(User::class)->getUser($currentUserId);
  433.         } else {
  434.             $user null;
  435.         }
  436.         
  437.         //$user = $em->getRepository(User::class)->getUser($currentUserId);
  438.         
  439.         /* we build login form */
  440.         $eshopLink = new EshopLink;
  441.         $formBuilder $this->createFormBuilder($eshopLink);
  442.         
  443.         $formBuilder->add('eshopLinkName'TextType::class, array(
  444.                 'required' => true,
  445.                 'label' => $this->translator->trans('module.eshopLink_name'),
  446.                 'attr' => array('class' => 'text_form''size' => 62),
  447.                 'label_attr' => array('class' => 'form_field_label'),
  448.         ));    
  449.         $formBuilder->add('eshopLinkNameHelp'TextType::class, array(
  450.                 'required' => false,
  451.                 'mapped' => false,
  452.                 'label' => '',
  453.                 'attr' => array('class' => 'text_form_help''size' => 62'readonly' => true'value' => $this->translator->trans('module.eshopLink_name_help'), 'title' => $this->translator->trans('module.eshopLink_name_help')),
  454.                 'label_attr' => array('class' => 'form_field_label_help'),
  455.         ));
  456.         $formBuilder->add('eshopLinkUrl'TextType::class, array(
  457.                 'required' => true,
  458.                 'label' => $this->translator->trans('system.url'),
  459.                 'attr' => array('class' => 'text_form''size' => 62'title'=>'text help''help_block'=>'text help block'), 
  460.                 'label_attr' => array('class' => 'form_field_label'),
  461.         )); 
  462.         $formBuilder->add('eshopLinkUrlHelp'TextType::class, array(
  463.                 'required' => false,
  464.                 'mapped' => false,
  465.                 'label' => '',
  466.                 'attr' => array('class' => 'text_form_help''size' => 90'readonly' => true'value' => $this->translator->trans('module.eshopLink_url_help'), 'title' => $this->translator->trans('module.eshopLink_url_help')),
  467.                 'label_attr' => array('class' => 'form_field_label_help'),
  468.         ));
  469.         $formBuilder->add('eshopLinkDescription'TextareaType::class, array(
  470.                 'required' => false,
  471.                 'label' => $this->translator->trans('module.eshopLink_description'),
  472.                 'attr' => array('class' => 'textarea_form''cols' => 60'rows' => 5),
  473.                 'label_attr' => array('class' => 'form_textarea_label'),
  474.         ));         
  475.         $formBuilder->add('eshopLinkDescriptionHelp'TextType::class, array(
  476.                 'required' => false,
  477.                 'mapped' => false,
  478.                 'label' => '',
  479.                 'attr' => array('class' => 'text_form_help''size' => 90'readonly' => true'value' => $this->translator->trans('module.eshopLink_description_help'), 'title' => $this->translator->trans('module.eshopLink_description_help')),
  480.                 'label_attr' => array('class' => 'form_field_label_help'),
  481.         ));
  482.         /* we add department list */
  483.         $departments = array();
  484.         //$departments['Root'] = 0;
  485.         foreach($departmentCollection as $dep)
  486.         {
  487.             $depId $dep->getDepartmentId();
  488.             $dep->setLocale($session->get('lang')->getLangKey());
  489.             $em->refresh($dep);    
  490.             //print('<br>qqw department: '.$departmentId);
  491.             $departments[$dep->getDepartmentName()] = $depId;
  492.         }      
  493.         
  494.         $formBuilder->add('department1'ChoiceType::class, array(
  495.                 'choices' => $departments,
  496.                 'attr' => array('class' => 'selector'),
  497.                 'mapped' => false,
  498.                 'label' => $this->translator->trans('marketplace.parent_department'),
  499.                 'label_attr' => array('class' => 'form_field_label')
  500.         ));  
  501.         $formBuilder->add('departmentHelp'TextType::class, array(
  502.                 'required' => false,
  503.                 'mapped' => false,
  504.                 'label' => '',
  505.                 'attr' => array('class' => 'text_form_help''size' => 90'readonly' => true'value' => $this->translator->trans('module.eshopLink_department_help'), 'title' => $this->translator->trans('module.eshopLink_department_help')),
  506.                 'label_attr' => array('class' => 'form_field_label_help'),
  507.         ));
  508.         $formBuilder->add('feedUrl'TextType::class, array(
  509.                 'required' => false,
  510.                 'mapped' => false,
  511.                 'label' => $this->translator->trans('marketplace.feed_url'),
  512.                 'attr' => array('class' => 'text_form''size' => 62),
  513.                 'label_attr' => array('class' => 'form_field_label')
  514.         ));
  515.         $formBuilder->add('feedUrlHelp'TextType::class, array(
  516.                 'required' => false,
  517.                 'mapped' => false,
  518.                 'label' => '',
  519.                 'attr' => array('class' => 'text_form_help''size' => 90'readonly' => true'value' => $this->translator->trans('module.eshopLink_feed_help'), 'title' => $this->translator->trans('module.eshopLink_feed_help')),
  520.                 'label_attr' => array('class' => 'form_field_label_help'),
  521.         ));     
  522.         $formBuilder->add('feedNotes'TextareaType::class, array(
  523.                 'required' => false,
  524.                 'mapped' => false,
  525.                 'label' => $this->translator->trans('system.notes'),
  526.                 'attr' => array('class' => 'textarea_form''cols' => 60'rows' => 2),
  527.                 'label_attr' => array('class' => 'form_textarea_label'),
  528.         ));         
  529.         $formBuilder->add('feedNotesHelp'TextType::class, array(
  530.                 'required' => false,
  531.                 'mapped' => false,
  532.                 'label' => '',
  533.                 'attr' => array('class' => 'text_form_help''size' => 90'readonly' => true'value' => $this->translator->trans('module.eshopLink_feed_notes_help'), 'title' => $this->translator->trans('module.eshopLink_feed_notes_help')),
  534.                 'label_attr' => array('class' => 'form_field_label_help'),
  535.         ));
  536.                   
  537.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  538.                 'attr' => array('class' => 'butt_big')));
  539.         
  540.         $form $formBuilder->getForm();        
  541.         $form->handleRequest($request);
  542.         
  543.         if ($request->getMethod() == 'POST') {
  544.             if ($form->isValid()) {
  545.                 $formData $form->getData();
  546.                 $eshopLink->setEshopLinkName($formData->getEshopLinkName());
  547.                 $eshopLink->setEshopLinkUrl($formData->getEshopLinkUrl());
  548.                 /* we add department */
  549.                 if($form['department1']->getData() !== null and $form['department1']->getData() !== 0) {
  550.                     $department1 $em->getRepository(Server::class)->getDepartment($form['department1']->getData());
  551.                     if(!empty($department1)) {
  552.                         $eshopLink->addDepartment($department1);
  553.                     } 
  554.                 }
  555.                 /* we create feed */
  556.                 $feed = new Feed;
  557.                 $feed->setFeedName($formData->getEshopLinkName()." - Feed");
  558.                 $feed->setFeedUrl($form['feedUrl']->getData());
  559.                 $feed->setNotes($form['feedNotes']->getData());
  560.                 /* we add department */
  561.                 if($form['department1']->getData() !== null and $form['department1']->getData() !== 0) {
  562.                     $department1 $em->getRepository(Server::class)->getDepartment($form['department1']->getData());
  563.                     if(!empty($department1)) {
  564.                         $feed->addDepartment($department1);
  565.                     }
  566.                 }
  567.                 /* we add server language */
  568.                 $eshopLink->addLanguage($session->get('lang'));
  569.                 if(!empty($session->get('user'))) {
  570.                     /* user is logged in - we persist the new eshopLink */
  571.                     $eshopLink->setUserId($session->get('user')->getUserId());
  572.                     $feed->setUserId($session->get('user')->getUserId());
  573.                     /* we set this eshop link as current one */
  574.                     $em->getRepository(EshopLink::class)->unsetCurrentEshopLink($session->get('user')->getUserId());
  575.                     $eshopLink->setEshopLinkCurrent(true);                      
  576.                     /* we persist and save eshopLink */
  577.                     $em->persist($feed);                    
  578.                     $em->persist($eshopLink);
  579. //                    print('<br>qqw Dep: ');
  580. //                    print_r($form['department1']->getData());
  581.                     if($form['department1']->getData() !== null and $form['department1']->getData() !== 0) {
  582.                         $em->persist($department1);
  583.                     }
  584.                     $em->flush();                     
  585.                     $this->addFlash('notice''New Eshop Link and Feed were created.');
  586.                     return $this->redirectToRoute('eshopLinkConfig');
  587.                 } else {
  588.                     /* we store new eshopLink in session and redirect to new account form */
  589.                     $session->set('eshopLink'$eshopLink);
  590.                     $session->set('feed'$feed);                    
  591.                     $this->addFlash('notice''Please add your user account info.');
  592.                     return $this->redirectToRoute('newaccount', array('addModule' => 19'addModule2' => 20));   
  593.                     //$this->redirectToRoute('eshopHomeContact', array('eshopId' => $eshopId))              
  594.                 }
  595.             }
  596.         
  597.         }
  598.     
  599.         /* we render data */
  600.         return $this->render('eshopLinkNew.html.twig',
  601.                 array(  'form' => $formBuilder->getForm()->createView(),
  602.                         'headerData' => $this -> getPageHeader($request),
  603.                         'menu' => $this -> adminMenu($request),
  604.                         'mainMenu' => $this -> adminMainMenu($request),
  605.                         'user' => $user,
  606.                 )
  607.                 );
  608.     
  609.     }  
  610.     /**
  611.      * @Route("/eshopLinkConfig", name="eshopLinkConfig")
  612.      */
  613.     public function eshopLinkConfigAction(Request $request)
  614.     {
  615.         /* we load session data */
  616.         parent::init($request);
  617.         $session $request->getSession();
  618.         
  619.         /* we load entity managers */
  620.         $em $this->doctrine->getManager();
  621.         $dem $this->doctrine->getManager('dynamic_em');
  622.          
  623.         /* we get e-shop link */ 
  624.         $userId $session->get('user')->getUserId();
  625.         $user $em->getRepository(User::class)->getUser($userId);
  626.         
  627.         /* we get current e-shop link */
  628.         $eshopLink $em->getRepository(EshopLink::class)->getCurrentEshopLink($userId);
  629.         /* we get current feed */
  630.         $feed $em->getRepository(Feed::class)->getCurrentFeed($userId);
  631.         
  632.         /* we get languages */
  633.         $langCollection $em->getRepository(Language::class)->getLanguageList();
  634.         /* we get departments */
  635.         $departmentCollection $em->getRepository(Server::class)->getDepartmentList();
  636.         $userDirs $this->getUserFolderPaths($request);
  637.         /* we build edit form */
  638.         $formBuilder $this->createFormBuilder($eshopLink);
  639.         
  640.         /* e-shop link name - multilangual fields */
  641.         foreach($eshopLink->getLanguages() as $lang) {
  642.             $fieldLabel $this->translator->trans('module.eshopLink_name').' ['.$lang->getLangKey().']';
  643.             $eshopLink->setLocale($lang->getLangKey());
  644.             $em->refresh($eshopLink);        
  645.             $fieldValue $eshopLink->getEshopLinkName();
  646.             
  647.             $formBuilder->add('eshopLinkName_'.$lang->getLangKey(), TextType::class, array(
  648.                     'required' => false,
  649.                     'label' => $fieldLabel,
  650.                     'attr' => array('class' => 'text_form''size' => 35'value' => $fieldValue),
  651.                     'label_attr' => array('class' => 'form_field_label'),
  652.                     'mapped' => false,
  653.             ));         
  654.             
  655.         }
  656.         /* e-shop link description - multilangual fields */
  657.         foreach($eshopLink->getLanguages() as $lang) {
  658.             $fieldLabel $this->translator->trans('module.eshopLink_description').' ['.$lang->getLangKey().']';
  659.             $eshopLink->setLocale($lang->getLangKey());
  660.             $em->refresh($eshopLink);        
  661.             $fieldValue $eshopLink->getEshopLinkDescription();
  662.             
  663.             $formBuilder->add('eshopLinkDescription_'.$lang->getLangKey(), TextareaType::class, array(
  664.                     'required' => false,
  665.                     'label' => $fieldLabel,
  666.                     'attr' => array('class' => 'textarea_form''cols' => 69'rows' => 7'value' => $fieldValue),
  667.                     'label_attr' => array('class' => 'form_textarea_label'),
  668.                     'data' => $fieldValue,
  669.                     'mapped' => false,
  670.             ));         
  671.             
  672.         }
  673.         $formBuilder->add('eshopLinkUrl'TextType::class, array(
  674.                 'required' => false,
  675.                 'label' => $this->translator->trans('system.url'),
  676.                 'attr' => array('class' => 'text_form''size' => 50'value' => $eshopLink->getEshopLinkUrl()),
  677.                 'label_attr' => array('class' => 'form_field_label')
  678.         ));
  679.         $formBuilder->add('logoUrl'TextType::class, array(
  680.                 'required' => false,
  681.                 'label' => $this->translator->trans('system.logo_url'),
  682.                 'attr' => array('class' => 'text_form''size' => 50'value' => $eshopLink->getLogoUrl()),
  683.                 'label_attr' => array('class' => 'form_field_label')
  684.         ));        
  685.         /* we add language list */
  686.         $languages = array();
  687.         foreach($langCollection as $lang)
  688.         {
  689.             $langId $lang->getLangId();
  690.             $languages[$lang->getLangName()] = $lang->getLangId();
  691.         }
  692.         $selectedLanguages = array();
  693.         foreach($eshopLink->getLanguages() as $lang) {
  694.             $selectedLanguages[] = $lang->getLangId();
  695.         }
  696.          
  697.         $formBuilder->add('languages'ChoiceType::class, array(
  698.                 'choices' => $languages,
  699.                 'required' => false,
  700.                 'mapped' => false,
  701.                 'multiple' => true,
  702.                 'expanded' => true,
  703.                 'label_attr' => array('class' => 'form_field_label'),
  704.                 'attr' => array('class' => 'form_field_text'),
  705.                 'data' => $selectedLanguages
  706.         ));  
  707.         /* we add department list */
  708.         
  709.         $departments = array();
  710.         foreach($departmentCollection as $dep)
  711.         {
  712.             $depId $dep->getDepartmentId();
  713.             $dep->setLocale($session->get('lang')->getLangKey());
  714.             $em->refresh($dep);
  715.             //print('<br>qqw dep: '.$dep->getDepartmentId());
  716.             //print('<br>qqw cat: '.$catId);
  717.             $depKey $dep->getDepartmentName().' (id:'.$dep->getDepartmentId().')';
  718.             $departments[$depKey] = $depId;
  719.              
  720.         }
  721.          
  722.         $selectedDepartment 0;
  723.         
  724.         // we load current category associations
  725.         foreach($eshopLink->getDepartments() as $dep) {
  726.             //print('<br>qqw sel dep: '.$dep->getDepartmentId());
  727.             $selectedDepartment $dep->getDepartmentId();
  728.         }        
  729.          
  730.         $formBuilder->add('department1'ChoiceType::class, array(
  731.                 'choices' => $departments,
  732.                 'label' => $this->translator->trans('marketplace.department'),
  733.                 'attr' => array('class' => 'selector'),
  734.                 'label_attr' => array('class' => 'form_field_label'),
  735.                 'data' => $selectedDepartment,
  736.                 'mapped' => false,
  737.         ));   
  738.         /*
  739.         $formBuilder->add('feedUrl', TextType::class, array(
  740.                 'required' => false, 
  741.                 'label' => $this->translator->trans('marketplace.feed_url'),
  742.                 'attr' => array('class' => 'text_form', 'size' => 57, 'value' => $eshopLink->getFeedUrl()),
  743.                 'label_attr' => array('class' => 'form_field_label')
  744.         ));
  745.         */            
  746.  
  747.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  748.                 'attr' => array('class' => 'butt_big')));
  749.          
  750.         $form $formBuilder->getForm();
  751.          
  752.         $form->handleRequest($request);
  753.          
  754.         if ($request->getMethod() == 'POST') {
  755.              
  756.             //$form->bindRequest($request);
  757.              
  758.             if ($form->isValid()) {
  759.                 $formData $form->getData();
  760.                 $eshopLink->setEshopLinkUrl($formData->getEshopLinkUrl());
  761.                 $eshopLink->setLogoUrl($formData->getLogoUrl());
  762.                 //$eshopLink->setFeedUrl($request->request->get('form')['feedUrl']);
  763.                 /* multilangual fields */
  764.                 foreach($eshopLink->getLanguages() as $lang) {
  765.                     $eshopLink->setLocale($lang->getLangKey());
  766.                     //$dem->refresh($product);
  767.                     $eshopLink->setEshopLinkName($form['eshopLinkName_'.$lang->getLangKey()]->getData());
  768.                     $eshopLink->setEshopLinkDescription($form['eshopLinkDescription_'.$lang->getLangKey()]->getData());
  769.                     //$dem->persist($product);
  770.                     //$product->setProductDescription($request->request->get('form')['productDescription_'.$lang->getLangKey()]);
  771.                     //$product->setProductShortDescription($request->request->get('form')['productShortDescription_'.$lang->getLangKey()]);
  772.                     $em->persist($eshopLink);                    
  773.                     $em->flush();
  774.                 }
  775.                 /* we remove old language associations */
  776.                 foreach($eshopLink->getLanguages() as $lang) {
  777.                     $eshopLink->removeLanguage($lang);
  778.                 }
  779.                     
  780.                 /* we load eshop languages */
  781.                 if(!empty($form['languages']->getData())) {
  782.                     foreach($form['languages']->getData() as $langId) {
  783.                         $addLang $em->getRepository(Language::class)->getLanguage($langId);
  784.                         $eshopLink->addLanguage($addLang);
  785.                         //$session->get('user')->addService($addService);
  786.                     }
  787.                 }                
  788.                 
  789.                 //print('<br>QQW cat 1: '.$request->request->get('form')['category1']);
  790.                 //Doctrine\Common\Util\Debug::dump($request-equest->get('form')['category1']);
  791.                 
  792.                 /* departments */
  793.                 /* we remove old associations */
  794.                 foreach($eshopLink->getDepartments() as $dep) {
  795.                     $eshopLink->removeDepartment($dep);
  796.                 }
  797.                 
  798.                 if($form['department1']->getData() !== 0) {
  799.                     $department1 $em->getRepository(Server::class)->getDepartment($form['department1']->getData());
  800.                     if(!empty($department1)) {
  801.                         $eshopLink->addDepartment($department1);
  802.                     }
  803.                 }
  804.                 /* we persist and save */
  805.                 foreach($eshopLink->getDepartments() as $dep) {
  806.                     $em->persist($dep);
  807.                 }
  808.                 //we create new feed
  809.                 if(!empty($form['feedUrl']) && empty($feed)) {
  810.                     
  811.                     $feed = new Feed;
  812.                     $feed->setFeedName($eshopLink->getEshopLinkName());
  813.                     $feed->setFeedUrl($form['feedUrl']->getData());
  814.                     /* we add department */
  815.                     if(!empty($department1)) {
  816.                         $feed->addDepartment($department1);
  817.                     }
  818.                     if(!empty($session->get('user'))) {
  819.                         /* user is logged in - we persist the new feed */
  820.                         $feed->setUserId($session->get('user')->getUserId());
  821.                         /* we set this feed as current one */
  822.                         $em->getRepository(Feed::class)->unsetCurrentFeed($session->get('user')->getUserId());
  823.                         $feed->setFeedCurrent(true);                      
  824.                         /* we persist and save feed */
  825.                         $em->persist($feed);
  826.                         $em->flush();                     
  827.                         $this->addFlash('notice''New Feed was created.');
  828.                         return $this->redirectToRoute('feedConfig');                 
  829.                     } else {
  830.                         /* we store new feed in session and redirect to new account form */
  831.                         $session->set('feed'$feed);
  832.                         $this->addFlash('notice''Please add your user account info.');
  833.                         return $this->redirectToRoute('newaccount');                 
  834.                     }                    
  835.                 }
  836.                 $em->persist($eshopLink);
  837.                 $em->flush();
  838.                 $this->addFlash('notice''E-shop Link was updated.');
  839.                 return $this->redirectToRoute('eshopLinkConfig');
  840.                  
  841.             }
  842.              
  843.         }
  844.         /* we render data */
  845.         return $this->render('eshopLinkConfig.html.twig',
  846.             array('headerData' => $this -> getPageHeader($request),
  847.                   'form' => $formBuilder->getForm()->createView(),
  848.                   'eshopLink' => $eshopLink,
  849.                   'userDirs' => $userDirs,
  850.                   'menu' => $this -> adminMenu($request),
  851.                         'mainMenu' => $this -> adminMainMenu($request),
  852.                   'user' => $user,
  853.                 )
  854.         );        
  855.     }  
  856.     /**
  857.      * @Route("/feedNew", name="feedNew")
  858.      */
  859.     public function feedNewAction(Request $request)
  860.     {
  861.         /* we load session data */
  862.         parent::init($request);
  863.          
  864.         $session $request->getSession();
  865.         /* we load entity managers */
  866.         $em $this->doctrine->getManager();
  867.         $dem $this->doctrine->getManager('dynamic_em');
  868.         $userId $session->get('user')->getUserId();
  869.         $user $em->getRepository(User::class)->getUser($userId);
  870.         $departmentCollection $em->getRepository(Server::class)->getDepartmentList();
  871.         
  872.         /* we build login form */
  873.         $feed = new Feed;
  874.         $formBuilder $this->createFormBuilder($feed);
  875.         
  876.         $formBuilder->add('feedName'TextType::class, array(
  877.                 'required' => true,
  878.                 'label' => $this->translator->trans('marketplace.feed_name'),
  879.                 'attr' => array('class' => 'text_form''size' => 33),
  880.                 'label_attr' => array('class' => 'form_field_label'),
  881.         ));     
  882.         $formBuilder->add('feedUrl'TextType::class, array(
  883.                 'required' => true,
  884.                 'label' => $this->translator->trans('system.url'),
  885.                 'attr' => array('class' => 'text_form''size' => 33),
  886.                 'label_attr' => array('class' => 'form_field_label'),
  887.         )); 
  888.         /* we add department list */
  889.         $departments = array();
  890.         //$departments['Root'] = 0;
  891.         foreach($departmentCollection as $dep)
  892.         {
  893.             $depId $dep->getDepartmentId();
  894.             $dep->setLocale($session->get('lang')->getLangKey());
  895.             $em->refresh($dep);
  896.             // print('<br>qqw department: '.$depId);
  897.             $departments[$dep->getDepartmentName()] = $depId;
  898.         }      
  899.         
  900.         $formBuilder->add('department1'ChoiceType::class, array(
  901.                 'choices' => $departments,
  902.                 'attr' => array('class' => 'selector'),
  903.                 'label' => 'Parent department',
  904.                 'mapped' => false,
  905.                 'label_attr' => array('class' => 'form_field_label')
  906.         ));  
  907.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  908.                 'attr' => array('class' => 'butt_big')));
  909.         
  910.         $form $formBuilder->getForm();        
  911.         $form->handleRequest($request);
  912.         
  913.         if ($request->getMethod() == 'POST') {
  914.             if ($form->isValid()) {
  915.                 $formData $form->getData();
  916.         
  917.                 /* we load users entity manager */
  918.                 //$dem = $this->doctrine->getManager('dynamic_em');
  919.                 $feed->setFeedName($formData->getFeedName());
  920.                 $feed->setFeedUrl($formData->getFeedUrl());
  921.                 /* we add department */
  922.                 if($form['department1']->getData() !== 0) {
  923.                     $department1 $em->getRepository(Server::class)->getDepartment($form['department1']->getData());
  924.                     if(!empty($department1)) {
  925.                         $feed->addDepartment($department1);
  926.                     }
  927.                 }
  928.                 if(!empty($session->get('user'))) {
  929.                     /* user is logged in - we persist the new feed */
  930.                     $feed->setUserId($session->get('user')->getUserId());
  931.                     /* we set this feed as current one */
  932.                     $em->getRepository(Feed::class)->unsetCurrentFeed($session->get('user')->getUserId());
  933.                     $feed->setFeedCurrent(true);                      
  934.                     /* we persist and save feed */
  935.                     $em->persist($feed);
  936.                     $em->flush();                     
  937.                     $this->addFlash('notice''New Feed was created.');
  938.                     return $this->redirectToRoute('feedConfig');                 
  939.                 } else {
  940.                     /* we store new feed in session and redirect to new account form */
  941.                     $session->set('feed'$feed);
  942.                     $this->addFlash('notice''Please add your user account info.');
  943.                     return $this->redirectToRoute('newaccount');                 
  944.                 }
  945.             }
  946.         
  947.         }
  948.     
  949.         /* we render data */
  950.         return $this->render('feedNew.html.twig',
  951.                 array(  'form' => $formBuilder->getForm()->createView(),
  952.                         'headerData' => $this -> getPageHeader($request),
  953.                         'menu' => $this -> adminMenu($request),
  954.                         'mainMenu' => $this -> adminMainMenu($request),
  955.                         'user' => $user,
  956.                 )
  957.                 );
  958.     
  959.     }  
  960.     /**
  961.      * @Route("/feedConfig", name="feedConfig")
  962.      */
  963.     public function feedConfigAction(Request $request)
  964.     {
  965.         /* we load session data */
  966.         parent::init($request);
  967.         $session $request->getSession();
  968.         
  969.         /* we load entity managers */
  970.         $em $this->doctrine->getManager();
  971.         $dem $this->doctrine->getManager('dynamic_em');
  972.          
  973.         /* we get feed */ 
  974.         $userId $session->get('user')->getUserId();
  975.         $user $em->getRepository(User::class)->getUser($userId);
  976.         
  977.         /* we get current feed */
  978.         $feed $em->getRepository(Feed::class)->getCurrentFeed($userId);
  979.         /* we get departments */
  980.         $departmentCollection $em->getRepository(Server::class)->getDepartmentList();
  981.         $userDirs $this->getUserFolderPaths($request);
  982.         /* we build edit form */
  983.         $formBuilder $this->createFormBuilder($feed);
  984.         $formBuilder->add('feedName'TextType::class, array(
  985.                 'required' => true,
  986.                 'label' => $this->translator->trans('marketplace.feed_name'),
  987.                 'attr' => array('class' => 'text_form''size' => 50'value' => $feed->getFeedName()),
  988.                 'label_attr' => array('class' => 'form_field_label')
  989.         ));
  990.         $formBuilder->add('feedUrl'TextType::class, array(
  991.                 'required' => true,
  992.                 'label' => $this->translator->trans('system.url'),
  993.                 'attr' => array('class' => 'text_form''size' => 50'value' => $feed->getFeedUrl()),
  994.                 'label_attr' => array('class' => 'form_field_label')
  995.         ));     
  996.         $formBuilder->add('feedType'TextType::class, array(
  997.                 'required' => true,
  998.                 'label' => $this->translator->trans('marketplace.feed_type'),
  999.                 'attr' => array('class' => 'text_form''size' => 50'value' => $feed->getFeedType()),
  1000.                 'label_attr' => array('class' => 'form_field_label')
  1001.         ));             
  1002.         /* we add department list */
  1003.         $departments = array();
  1004.         foreach($departmentCollection as $dep)
  1005.         {
  1006.             $depId $dep->getDepartmentId();
  1007.             $dep->setLocale($session->get('lang')->getLangKey());
  1008.             $em->refresh($dep);
  1009.             //print('<br>qqw dep: '.$dep->getDepartmentId());
  1010.             //print('<br>qqw cat: '.$catId);
  1011.             $depKey $dep->getDepartmentName().' (id:'.$dep->getDepartmentId().')';
  1012.             $departments[$depKey] = $depId;
  1013.              
  1014.         }
  1015.          
  1016.         $selectedDepartment 0;
  1017.         
  1018.         // we load current category associations
  1019.         foreach($feed->getDepartments() as $dep) {
  1020.             //print('<br>qqw sel dep: '.$dep->getDepartmentId());
  1021.             $selectedDepartment $dep->getDepartmentId();
  1022.         }        
  1023.          
  1024.         $formBuilder->add('department1'ChoiceType::class, array(
  1025.                 'choices' => $departments,
  1026.                 'mapped' => false,
  1027.                 'label' => $this->translator->trans('marketplace.department'),
  1028.                 'attr' => array('class' => 'selector'),
  1029.                 'label_attr' => array('class' => 'form_field_label'),
  1030.                 'data' => $selectedDepartment
  1031.         ));   
  1032.         $formBuilder->add('notes'TextareaType::class, array(
  1033.                 'required' => false,
  1034.                 'label' => $this->translator->trans('system.notes'),
  1035.                 'attr' => array('class' => 'textarea_form''cols' => 55'rows' => 5'value' => $feed->getNotes()),
  1036.                 'label_attr' => array('class' => 'form_textarea_label'),
  1037.                 'data' => $feed->getNotes(),
  1038.         ));        
  1039.  
  1040.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  1041.                 'attr' => array('class' => 'butt_big')));
  1042.          
  1043.         $form $formBuilder->getForm();
  1044.          
  1045.         $form->handleRequest($request);
  1046.          
  1047.         if ($request->getMethod() == 'POST') {
  1048.              
  1049.             //$form->bindRequest($request);
  1050.              
  1051.             if ($form->isValid()) {
  1052.                 $formData $form->getData();
  1053.                 $feed->setFeedName($formData->getFeedName());
  1054.                 $feed->setFeedUrl($formData->getFeedUrl());
  1055.                 $feed->setFeedType($formData->getFeedType());
  1056.                 
  1057.                 //print('<br>QQW cat 1: '.$request->request->get('form')['category1']);
  1058.                 //Doctrine\Common\Util\Debug::dump($request->request->get('form')['category1']);
  1059.                 
  1060.                 /* departments */
  1061.                 /* we remove old associations */
  1062.                 foreach($feed->getDepartments() as $dep) {
  1063.                     $feed->removeDepartment($dep);
  1064.                 }
  1065.                 
  1066.                 if($form['department1']->getData() !== 0) {
  1067.                     $department1 $em->getRepository(Server::class)->getDepartment($form['department1']->getData());
  1068.                     if(!empty($department1)) {
  1069.                         $feed->addDepartment($department1);
  1070.                     }
  1071.                 }
  1072.                 /* we persist and save */
  1073.                 foreach($feed->getDepartments() as $dep) {
  1074.                     $em->persist($dep);
  1075.                 }
  1076.                 $em->persist($feed);
  1077.                 $em->flush();
  1078.                 $this->addFlash('notice''Feed was updated.');
  1079.                 return $this->redirectToRoute('feedConfig');
  1080.                  
  1081.             }
  1082.              
  1083.         }
  1084.         /* we render data */
  1085.         return $this->render('feedConfig.html.twig',
  1086.             array('headerData' => $this -> getPageHeader($request),
  1087.                   'form' => $formBuilder->getForm()->createView(),
  1088.                   'feed' => $feed,
  1089.                   'userDirs' => $userDirs,
  1090.                   'menu' => $this -> adminMenu($request),
  1091.                         'mainMenu' => $this -> adminMainMenu($request),
  1092.                   'user' => $user,
  1093.                 )
  1094.         );        
  1095.     }      
  1096.     /**
  1097.      * @Route("/marketplaceProductAdmin", name="marketplaceProductAdmin")
  1098.      */
  1099.     public function marketplaceProductAdminAction(Request $request)
  1100.     {
  1101.         /* we load session data */
  1102.         parent::init($request);
  1103.         $session $request->getSession();
  1104.         /* we load entity managers */
  1105.         $em $this->doctrine->getManager();
  1106.         $dem $this->doctrine->getManager('dynamic_em');
  1107.         
  1108.         /* we get current user */
  1109.         $currentUserId $session->get('user')->getUserId();
  1110.         $user $em->getRepository(User::class)->getUser($currentUserId);
  1111.         /* setting current feed */
  1112.         if(!empty($request->query->get('setCurrent'))) {
  1113.             $feed $em->getRepository(Feed::class)->getFeed($request->query->get('setCurrent'));
  1114.             $em->getRepository(Feed::class)->setCurrentFeed($currentUserId$request->query->get('setCurrent'));
  1115.             $session->set('feed'$feed);
  1116.             
  1117.             $this->addFlash('notice''The feed '.$feed->getFeedName().' was set as current one.');
  1118.             return $this->redirectToRoute('marketplaceProductAdmin');
  1119.             
  1120.         }
  1121.         
  1122.         /* we get current feed */
  1123.         $currentFeed $em->getRepository(Feed::class)->getCurrentFeed($currentUserId);
  1124.       
  1125.       /*
  1126.         print('<br>qqw currentEshop: ');
  1127.         \Doctrine\Common\Util\Debug::dump($currentEshop->getEshopId());
  1128.       */      
  1129.       
  1130.         /* we load list of eshop links for logged user */
  1131.         $feedList $em->getRepository(Feed::class)->getFeedListByUser($currentUserId);
  1132. //        print('<br>qqw feedList: ');
  1133. //        \Doctrine\Common\Util\Debug::dump($feedList);
  1134.         /* we render data */
  1135.         return $this->render('feedAdmin.html.twig',
  1136.             array('headerData' => $this -> getPageHeader($request),
  1137.                   'feedList' => $feedList,
  1138.                   'menu' => $this -> adminMenu($request),
  1139.                     'mainMenu' => $this -> adminMainMenu($request),
  1140.                     'user' => $user,
  1141.                 )
  1142.         );        
  1143.     }
  1144.     /**
  1145.      * @Route("/marketplace/eshop/{eshopId}", name="marketplaceEshop")
  1146.      */
  1147.     public function marketplaceEshopAction(Request $request$eshopId)
  1148.     {
  1149.         /* we load session data */
  1150.         parent::init($request);
  1151.         /* we load entity managers */
  1152.         $em $this->doctrine->getManager();
  1153.         /* we get eshop */
  1154. //        $eshopLink = $em->getRepository(Product::class)->getProduct($eshopId);
  1155.         $eshopLink $em->getRepository(EshopLink::class)->getEshopLink($eshopId);
  1156.         if(empty($eshopLink)) {
  1157.             $this->addFlash('error''eShop with this ID does not exist.');
  1158.             return $this->redirectToRoute('marketplace');
  1159.         }
  1160.         if(!empty($request->get('redirect_to_eshop'))) {
  1161.             print('<br>redirect_to_eshop 22...');
  1162.             $clickedCount = (int)$eshopLink->getClickedCount();
  1163.             $eshopLink->setClickedCount($clickedCount 1);
  1164.             $em->persist($eshopLink);
  1165.             $em->flush();
  1166.             return $this->redirect($eshopLink->getEshopLinkUrl());
  1167. //            die('<br>redirect to shop ...');
  1168.         }
  1169.         /*
  1170.         $departmentPath = $em->getRepository(Department::class)->getPath($department);
  1171.         $childDepartments = $department->getChildren();
  1172.         //$childDepartments = $em->getRepository(Department::class)->getRootNodes();
  1173.         */
  1174.         /*
  1175.         print('<br>qqw eshopLinkList: ');
  1176.         \Doctrine\Common\Util\Debug::dump($eshopLinkList);
  1177.         */
  1178.         // increments product view count
  1179.         $viewedCount = (int)$eshopLink->getClickedCount();
  1180.         $eshopLink->setClickedCount($viewedCount 1);
  1181.         $em->persist($eshopLink);
  1182.         $em->flush();
  1183.         /* we render data */
  1184.         return $this->render('marketplaceEshop.html.twig',
  1185.             array('headerData' => $this -> getPageHeader($request),
  1186.                 'eshopLink' => $eshopLink,
  1187.             )
  1188.         );
  1189.     }
  1190.     public function adminMenu(Request $request)
  1191.     {
  1192.         $menuItems = array(=> array('link' => 'marketplaceAdmin''langKey' => 'marketplace.admin''routeName' => 'marketplaceAdmin'),
  1193.                 => array('link' => 'marketplaceProductListEdit''langKey' => 'marketplace.products''routeName' => 'marketplaceProductListEdit'),
  1194.                 => array('link' => 'marketplaceProductAdmin''langKey' => 'module.marketplaceProductAdmin''routeName' => 'marketplaceProductAdmin'),
  1195.                 => array('link' => 'feedNew''langKey' => 'marketplace.new_feed''routeName' => 'feedNew'),                
  1196.                 => array('link' => 'eshopLinkAdmin''langKey' => 'module.eshopLinkAdmin''routeName' => 'eshopLinkAdmin'),
  1197.                 => array('link' => 'addproducts''langKey' => 'module.eshopLink_new''routeName' => 'eshopLinkNew'),
  1198.         );  
  1199.         
  1200.         return $menuItems;
  1201.     
  1202.     }      
  1203. }