src/Controller/IndexController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Room;
  4. use App\Form\RoomType;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Form\FormError;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class IndexController extends AbstractController
  12. {
  13.     public function __construct(
  14.         private EntityManagerInterface $_em
  15.     ) {}
  16.     /**
  17.      * @param Request $request
  18.      * @return Response
  19.      */
  20.     #[Route("/"name"index")]
  21.     public function index(Request $request): Response
  22.     {
  23.         $room = new Room();
  24.         $roomForm $this->createForm(RoomType::class, $room);
  25.         $roomForm->handleRequest($request);
  26.         if ($roomForm->isSubmitted() && $roomForm->isValid()) {
  27.             /** @var Room $data */
  28.             $data $roomForm->getData();
  29.             $result $this->_em->getRepository(Room::class)->findOneBy(["roomId" => $data->getRoomId()]);
  30.             if ($result) {
  31.                 return $this->redirectToRoute("public_room", ["roomId" => $result->getRoomId()]);
  32.             } else {
  33.                 $roomForm->addError(new FormError('The room doesn’t exist'));
  34.             }
  35.         }
  36.         return $this->render('index.html.twig', [
  37.             'page_title' => 'Phasmophobia Randomizer',
  38.             'page_description' => 'Welcome back, we\'ve got some work ready for you!',
  39.             'meta_title' => 'Randomize your Phasmophobia game',
  40.             'meta_description' => 'Randomize your Phasmophobia games among various game modes such as classic, photo safari, night fever from 1 to 4 players. It’s a great way to make your Phasmophobia games more challenging!',
  41.             'roomEnter' => $roomForm->createView()
  42.         ]);
  43.     }
  44.     /**
  45.      * @return Response
  46.      */
  47.     #[Route(path: [
  48.         "en" => "/obs-guide",
  49.         "fr" => "/guide-pour-obs"
  50.     ], name"obs_guide")]
  51.     public function obs_guide(): Response
  52.     {
  53.         return $this->render('game/obs_guide.html.twig', [
  54.             'page_title' => 'Phasmophobia Randomizer',
  55.             'page_description' => 'Implement the randomizer on your lives',
  56.             'meta_title' => 'Phasmophobia Randomizer on OBS for Twitch',
  57.             'meta_description' => 'This guide allows you to integrate the content of your multiplayer games on your Twitch live through OBS.'
  58.         ]);
  59.     }
  60. }