src/Controller/DefaultController.php line 35

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use App\Entity\Fileasset;
  8. use App\Entity\Page;
  9. use App\Repository\PageRepository;
  10. use App\Entity\Tag;
  11. use App\Repository\TagRepository;
  12. use App\Entity\TextFragment;
  13. use App\Repository\TextFragmentRepository;
  14. use App\Entity\Product;
  15. use App\Repository\ProductRepository;
  16. use App\Entity\ProductTag;
  17. use App\Form\ProductType;
  18. use App\Form\ProductChildType;
  19. use App\Form\AddToCartType;
  20. use App\Manager\CartManager;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  23. class DefaultController extends AbstractController
  24. {
  25.     
  26.   
  27.     #[Route('/realisaties'name'app_realisations')]
  28.     public function realisaties(TagRepository $tagrep): Response
  29.     {
  30.         
  31.         $realid =  $_ENV['MY_REALISATIONS'];
  32.         
  33.        $tag $tagrep->findOneById($realid);
  34.         
  35.         $tags $tag->getChildren();
  36.         
  37.         
  38.         return $this->render('st/realisaties.html.twig', [
  39.             'tags' => $tags
  40.         ]);
  41.     }
  42.     
  43.     
  44.     
  45.     
  46.         
  47.     #[Route('/start'name'app_start')]
  48.     public function start(): Response
  49.     {
  50.         
  51.        $site =  $_ENV['SITE'];
  52.        $templatePath "st/".$site."/start.html.twig";
  53.            
  54.         return $this->render($templatePath, [
  55.             'controller_name' => 'DefaultController',
  56.             'site' => $site,
  57.         ]);
  58.     }
  59.     
  60.     
  61.     #[Route('/dealers/'name'app_dealers')]
  62.     public function dealers(): Response
  63.     {
  64.         
  65.        $site =  $_ENV['SITE'];
  66.        $templatePath "st/".$site."/dealers.html.twig";
  67.            
  68.         return $this->render($templatePath, [
  69.             'controller_name' => 'DefaultController',
  70.             'site' => $site,
  71.         ]);
  72.     }
  73.     
  74.     
  75.     
  76.     #[Route('/'name'app_default')]
  77.     public function index(): Response
  78.     {
  79.         $site =  $_ENV['SITE'];
  80.         $templatePath 'st/' $site '/index.html.twig';
  81.            
  82.         return $this->render($templatePath, [
  83.             'controller_name' => 'DefaultController',
  84.         ]);
  85.     }
  86.     
  87.   
  88.     
  89.     
  90.     #[Route('/promo/'name'promo'methods: ['GET'])]
  91.     public function promo(ProductRepository $productsrep,TagRepository $tagRepository): Response
  92.     {
  93.        $products $productsrep->findPromos(null);
  94.        
  95.        $id 1;
  96.        $group $tagRepository->findOneBy(array('id' =>$id));
  97.        
  98.        
  99.        
  100.         return $this->render('st/promo.html.twig', [
  101.             'products' => $products,
  102.             'group' => $group,
  103.             
  104.         ]);
  105.     }
  106.     
  107.     #[Route('/products/'name'products'methods: ['GET'])]
  108.     public function products(ProductRepository $productsrep,TagRepository $tagRepository): Response
  109.     {
  110.        $products $productsrep->findAll();
  111.        
  112.        $id 1;
  113.        $group $tagRepository->findOneBy(array('id' =>$id));
  114.        
  115.        
  116.        $site =  $_ENV['SITE'];
  117.        $template "st/".$site."/products.html.twig";
  118.        
  119.  
  120.        
  121.         return $this->render($template, [
  122.             'products' => $products,
  123.             'group' => $group,
  124.             'site' => $site,
  125.             
  126.         ]);
  127.     }
  128.     
  129.      
  130.     
  131.     #[Route('/tagmenu/{parent}'name'tag_menu')]
  132.     public function tagmenu(TagRepository $tagRepository,Tag $parent): Response
  133.     {
  134.         return $this->render('st/tagmenu.html.twig', [
  135.             'tags' => $tagRepository->findBy(array('Parent' => $parent), array('id' => 'DESC'))
  136.         ]);
  137.     }
  138.     
  139.     
  140.     #[Route('/blocks/{parent}'name'tag_blocks')]
  141.     public function tagblocks(TagRepository $tagRepository,Tag $parent): Response
  142.     {
  143.         
  144.         return $this->render('st/tagblocks.html.twig', [
  145.             'tags' => $tagRepository->findBy(array('Parent' => $parent), array('id' => 'DESC'))
  146.         ]);
  147.         
  148.     }
  149.     
  150.     
  151.     #[Route('/checkboxes/{parent}'name'tag_checkboxes')]
  152.     public function checkboxes(TagRepository $tagRepository,Tag $parent): Response
  153.     {
  154.         
  155.         return $this->render('st/tagcheckboxes.html.twig', [
  156.             'tags' => $tagRepository->findBy(array('Parent' => $parent), array('id' => 'DESC'))
  157.         ]);
  158.         
  159.     }
  160.     
  161.     
  162.     
  163.     
  164.     
  165.     
  166.     #[Route('/fg/{id}'name'fragment')]
  167.     
  168.     public function fg(TextFragmentRepository $textfragmentRepository$id): Response
  169.     {
  170.         
  171.         $fragment $textfragmentRepository->findOneBy(array('id' =>$id));
  172.         if($fragment == null){
  173.           $data "empty fragment with id "$id;
  174.         }else{
  175.             $data $fragment->getText();
  176.             
  177.         }
  178.         
  179.         $response = new Response();
  180.         $response->setContent($data);
  181.         
  182.         return $response;
  183.         
  184.         
  185.     }
  186.      
  187.     #[Route('/nl/{name}'name'pagenl'defaults: ['name' => null])]
  188.     #[Route('/fr/{name}'name'pagefr'defaults: ['name' => null])]
  189.     #[Route('/en/{name}'name'pageen'defaults: ['name' => null])]
  190.     public function page(PageRepository $PageRepository,$name=null): Response
  191.     {
  192.      
  193.         
  194.         $site =  $_ENV['SITE'];
  195.         $page $PageRepository->findOneBy(array('Name' =>$name));
  196.         
  197.         
  198.         
  199.         if($page){
  200.             $template "st/".$site."/".$page->getTemplate().".html.twig";
  201.             
  202.         }else{
  203.             $template "st/".$site."/404.html.twig";
  204.         }
  205.         
  206.         return $this->render($template, [
  207.             'site' => $site,
  208.            
  209.             
  210.         ]);
  211.         
  212.     }
  213.     
  214.     
  215.    
  216.     
  217.     
  218.     
  219.     #[Route('/group/{name}/{id}'name'group'defaults: ['name' => null])]
  220.     
  221.     public function group(TagRepository $tagRepository,Tag $id): Response
  222.     {
  223.          
  224.             
  225.         $site =  $_ENV['SITE'];
  226.         $template "st/".$site."/group.html.twig";
  227.         
  228.         $group $tagRepository->findOneBy(array('id' =>$id));
  229.         
  230.         
  231.         
  232.         return $this->render($template, [
  233.             'group' => $group,
  234.             'site' => $site,
  235.             
  236.         ]);
  237.         
  238.         
  239.     } 
  240.     
  241.    
  242.     
  243.      
  244.     
  245.  
  246.     #[Route('/detail/{id}'name'product_detail'defaults: ['name' => null])]
  247.     public function detail(Product $productRequest $requestCartManager $cartManager): Response
  248.     {
  249.         $form $this->createForm(AddToCartType::class);
  250.         
  251.         $form->handleRequest($request);
  252.         
  253.         if ($form->isSubmitted() && $form->isValid()) {
  254.             $item $form->getData();
  255.             $item->setProduct($product);
  256.             
  257.             $cart $cartManager->getCurrentCart();
  258.             $cart
  259.             ->addOrderItem($item)
  260.             ->setUpdatedAt(new \DateTime());
  261.             
  262.             $cartManager->save($cart);
  263.             
  264.             //return $this->redirectToRoute('product_detail', ['id' => $product->getId()]);
  265.             return $this->redirectToRoute('cart');
  266.             
  267.         }
  268.         
  269.             
  270.        $site =  $_ENV['SITE'];
  271.        $template "st/".$site."/product.html.twig";
  272.        
  273.        
  274.         return $this->render($template, [
  275.             'product' => $product,
  276.             'form' => $form->createView(),
  277.             'site' => $site,
  278.         ]);
  279.     }
  280.     
  281.     
  282.     
  283.     
  284.     
  285.     /**
  286.      * @Route("/publicdownload/{id}", name="fileasset_publicdownload", methods={"GET"})
  287.      */
  288.     public function publicdownload(Fileasset $fileasset): Response
  289.     {
  290.         
  291.        
  292.         
  293.         // $fileasset = $em->getRepository('DavidAppBundle:FileAsset')->find($id);
  294.         
  295.         $filename $fileasset->getFilename();
  296.         $folder $this->getParameter('upload_directory');
  297.         
  298.         if($fileasset->isPublic() == true){
  299.             $path $folder.$fileasset->getFilename();
  300.             return new BinaryFileResponse($path);
  301.             
  302.         }
  303.         
  304.     }
  305.     
  306.     
  307.    
  308.     
  309.     
  310.     
  311. }