<?php
declare(strict_types=1);
namespace Hitso\Bundle\TicketsBundle\Controller\Front;
use Hitso\Bundle\CommonBundle\Controller\Controller;
use Hitso\Bundle\SeoBundle\Entity\SeoPage;
use Hitso\Bundle\TicketsBundle\Entity\Status;
use Hitso\Bundle\TicketsBundle\Entity\Ticket;
use Hitso\Bundle\TicketsBundle\Manager\ContactManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
/**
* @Route("/contact", name="hitso_tickets_front_")
*/
class TicketController extends Controller
{
/**
* @var ContactManager
*/
protected $contactManager;
public function __construct(ContactManager $contactManager)
{
$this->contactManager = $contactManager;
}
/**
* @Route("/", name="index")
*/
public function indexAction(Breadcrumbs $breadcrumbs, Request $request): Response
{
$breadcrumbs->addRouteItem('Contact', 'hitso_tickets_front_index');
/** @var Ticket $ticket */
$ticket = $this->contactManager->initResource();
$form = $this->contactManager->initForm($ticket);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$status = $this->getDoctrine()->getRepository(Status::class)->find(Status::CREATED);
$ticket->setStatus($status);
$this->contactManager->createResource($ticket);
return $this->redirectToAction('confirm');
}
$content = $this->getManagerForClass(SeoPage::class)->getRepository()->findOneBy(['route' => 'hitso_tickets_front_index']);
if ($content) {
$this->updateSeoPage($content);
}
return $this->displayTemplate('index', [
'form' => $form->createView(),
]);
}
/**
* @Route("/confirm", name="confirm")
*/
public function confirmAction(Breadcrumbs $breadcrumbs)
{
$breadcrumbs->addRouteItem('Contact', 'hitso_tickets_front_index');
$breadcrumbs->addRouteItem('Confirmation', 'hitso_tickets_front_confirm');
return $this->displayTemplate('confirm');
}
}