src/Controller/DefaultController.php line 32
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Fileasset;
use App\Entity\Page;
use App\Repository\PageRepository;
use App\Entity\Tag;
use App\Repository\TagRepository;
use App\Entity\TextFragment;
use App\Repository\TextFragmentRepository;
use App\Entity\Product;
use App\Repository\ProductRepository;
use App\Entity\ProductTag;
use App\Form\ProductType;
use App\Form\ProductChildType;
use App\Form\AddToCartType;
use App\Manager\CartManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class DefaultController extends AbstractController
{
private EntityManagerInterface $entityManager;
#[Route('/realisaties', name: 'app_realisations')]
public function realisaties(TagRepository $tagrep): Response
{
$realid = $_ENV['MY_REALISATIONS'];
$tag = $tagrep->findOneById($realid);
$tags = $tag->getChildren();
return $this->render('st/realisaties.html.twig', [
'tags' => $tags
]);
}
#[Route('/start', name: 'app_start')]
public function start(): Response
{
$site = $_ENV['SITE'];
$templatePath = "st/".$site."/start.html.twig";
return $this->render($templatePath, [
'controller_name' => 'DefaultController',
'site' => $site,
]);
}
#[Route('/dealers/', name: 'app_dealers')]
public function dealers(): Response
{
$site = $_ENV['SITE'];
$templatePath = "st/".$site."/dealers.html.twig";
return $this->render($templatePath, [
'controller_name' => 'DefaultController',
'site' => $site,
]);
}
#[Route('/', name: 'app_default')]
public function index(): Response
{
$fullDomain = $_SERVER['HTTP_HOST'];
$domainParts = explode('.', $fullDomain);
if (count($domainParts) > 1 && $domainParts[0] === 'www') {
array_shift($domainParts);
}
array_pop($domainParts);
$domain = implode('.', $domainParts);
$templatePath = 'st/' . $domain . '/index.html.twig';
return $this->render($templatePath, [
'controller_name' => 'DefaultController',
]);
}
#[Route('/promo/', name: 'promo', methods: ['GET'])]
public function promo(ProductRepository $productsrep,TagRepository $tagRepository): Response
{
$products = $productsrep->findPromos(null);
$id = 1;
$group = $tagRepository->findOneBy(array('id' =>$id));
return $this->render('st/promo.html.twig', [
'products' => $products,
'group' => $group,
]);
}
#[Route('/products/', name: 'products', methods: ['GET'])]
public function products(ProductRepository $productsrep,TagRepository $tagRepository): Response
{
$products = $productsrep->findAll();
$id = 1;
$group = $tagRepository->findOneBy(array('id' =>$id));
$site = $_ENV['SITE'];
$template = "st/".$site."/products.html.twig";
return $this->render($template, [
'products' => $products,
'group' => $group,
'site' => $site,
]);
}
#[Route('/tagmenu/{parent}', name: 'tag_menu')]
public function tagmenu(TagRepository $tagRepository,Tag $parent): Response
{
return $this->render('st/tagmenu.html.twig', [
'tags' => $tagRepository->findBy(array('Parent' => $parent), array('id' => 'DESC'))
]);
}
#[Route('/blocks/{parent}', name: 'tag_blocks')]
public function tagblocks(TagRepository $tagRepository,Tag $parent): Response
{
return $this->render('st/tagblocks.html.twig', [
'tags' => $tagRepository->findBy(array('Parent' => $parent), array('id' => 'DESC'))
]);
}
#[Route('/checkboxes/{parent}', name: 'tag_checkboxes')]
public function checkboxes(TagRepository $tagRepository,Tag $parent): Response
{
return $this->render('st/tagcheckboxes.html.twig', [
'tags' => $tagRepository->findBy(array('Parent' => $parent), array('id' => 'DESC'))
]);
}
#[Route('/fg/{id}', name: 'fragment')]
public function fg(TextFragmentRepository $textfragmentRepository, $id): Response
{
$fragment = $textfragmentRepository->findOneBy(array('id' =>$id));
if($fragment == null){
$data = "empty fragment with id ". $id;
}else{
$data = $fragment->getText();
}
$response = new Response();
$response->setContent($data);
return $response;
}
#[Route('/nl/{name}', name: 'pagenl', defaults: ['name' => null])]
#[Route('/fr/{name}', name: 'pagefr', defaults: ['name' => null])]
#[Route('/en/{name}', name: 'pageen', defaults: ['name' => null])]
public function page(PageRepository $PageRepository,$name=null): Response
{
$site = $_ENV['SITE'];
$page = $PageRepository->findOneBy(array('Name' =>$name));
if($page){
$template = "st/".$site."/".$page->getTemplate().".html.twig";
}else{
$template = "st/".$site."/404.html.twig";
}
return $this->render($template, [
'site' => $site,
]);
}
#[Route('/group/{name}/{id}', name: 'group', defaults: ['name' => null])]
public function group(TagRepository $tagRepository,Tag $id): Response
{
$site = $_ENV['SITE'];
$template = "st/".$site."/group.html.twig";
$group = $tagRepository->findOneBy(array('id' =>$id));
return $this->render($template, [
'group' => $group,
'site' => $site,
]);
}
#[Route('/detail/{id}', name: 'product_detail', defaults: ['name' => null])]
public function detail(Product $product, Request $request, CartManager $cartManager): Response
{
$form = $this->createForm(AddToCartType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$item = $form->getData();
$item->setProduct($product);
$cart = $cartManager->getCurrentCart();
$cart
->addOrderItem($item)
->setUpdatedAt(new \DateTime());
$cartManager->save($cart);
//return $this->redirectToRoute('product_detail', ['id' => $product->getId()]);
return $this->redirectToRoute('cart');
}
$site = $_ENV['SITE'];
$template = "st/".$site."/product.html.twig";
return $this->render($template, [
'product' => $product,
'form' => $form->createView(),
'site' => $site,
]);
}
/**
* @Route("/publicdownload/{id}", name="fileasset_publicdownload", methods={"GET"})
*/
public function publicdownload(Fileasset $fileasset): Response
{
// $fileasset = $em->getRepository('DavidAppBundle:FileAsset')->find($id);
$filename = $fileasset->getFilename();
$folder = $this->getParameter('upload_directory');
if($fileasset->isPublic() == true){
$path = $folder.$fileasset->getFilename();
return new BinaryFileResponse($path);
}
}
}