<?php
namespace App\Controller\Frontend;
use App\Controller\Base\BaseController;
use App\Entity\Feedback;
use App\Form\FeedbackType;
use App\Repository\FeedbackRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class TFeedbackController extends BaseController
{
/**
* @Route("/t/feedback", name="t_feedback")
*/
public function index(): Response
{
return $this->render('t_feedback/index.html.twig', [
'controller_name' => 'TFeedbackController',
]);
}
/**
* @Route("tfeedback/request/{id}", defaults={"id"=null}, name="tfeedback_form", methods={"GET","POST"})
*/
public function form(?string $id = null, Request $request, FeedbackRepository $feedbackRepository)
{
// print_r('ya');exit;
if ($id) {
$feedback = $feedbackRepository->find($id);
} else {
$feedback = new Feedback();
}
if (!$feedback) {
throw new NotFoundHttpException();
}
$form = $this->createForm(FeedbackType::class, $feedback, ['action' => $this->generateUrl('tfeedback_form', ['id' => $feedback->getId()])]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user = $form->getData();
$user->setRating($request->request->get('star'));
$user->setCreatedAt(new \DateTime());
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();
$this->addFlash('notice', 'Berhasil dikirim');
return $this->redirectToRoute('homepage');
// return $this->redirect($request->server->get('HTTP_REFERER'));
}
return $this->render('/frontend/t_feedback/form.html.twig', [
'form' => $form->createView(),
'header_kategori' => $this->getHeaderKategori(),
]);
}
}