<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\Order;
use App\Form\OrderFormType;
use App\Service\OrderService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse as RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class DefaultController
* @package App\Controller
*/
class DefaultController extends AbstractController
{
/**
* @var RequestStack
*/
private $request;
/**
* @var OrderService
*/
private $orderService;
/**
* DefaultController constructor.
*
* @param RequestStack $request
* @param OrderService $orderService
*/
public function __construct(
RequestStack $request,
OrderService $orderService
) {
$this->request = $request->getCurrentRequest();
$this->orderService = $orderService;
}
/**
* @Route("/", name="index")
* @Template()
*
* @return array|RedirectResponse
*/
public function index()
{
$addOrder = $this->orderService->doDisplayOrder();
$response = [];
if ($addOrder) {
$order = new Order();
$form = $this->createForm(OrderFormType::class, $order, ['submit' => true]);
$form->handleRequest($this->request);
$response['form'] = $form->createView();
if ($form->isSubmitted() && $form->isValid()) {
return $this->redirectToRoute('dashboard');
}
}
return $response;
}
/**
* @Route("privacy-statement", name="privacy_statement")
*/
public function privacyStatement(): Response
{
return $this->render('security/privacy-statement.html.twig');
}
/**
* @Route("cgu", name="cgu")
*/
public function cgu(): Response
{
return $this->render('security/cgufront.html.twig');
}
}