src/Controller/ConferenceController.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Service\EsSocket;
  5. use App\Entity\Conference;
  6. use App\Handler\ConferenceHandler;
  7. use App\Entity\Model\ConfigurationType;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  13. class ConferenceController extends AbstractController
  14. {
  15.     public function __construct(
  16.         private ConferenceHandler $handler
  17.     ) {
  18.     }
  19.     /**
  20.      * @Route(
  21.      *      path="/api/conferences/clone",
  22.      *      name="api_conferences_clone_collection",
  23.      *      methods={"POST"},
  24.      *      defaults={
  25.      *          "_api_resource_class"=Conference::class,
  26.      *          "_api_collection_operation_name"="post_clone"
  27.      *      }
  28.      * )
  29.      */
  30.     public function clone($data): Conference
  31.     {
  32.         return $this->handler->clone($data);
  33.     }
  34.     /**
  35.      * @Route(
  36.      *      path="/public-api/conferences/get",
  37.      *      name="api_pub_conferences_get_for_public_page_collection",
  38.      *      methods={"GET"},
  39.      *      defaults={
  40.      *          "_api_resource_class"=Conference::class,
  41.      *          "_api_collection_operation_name"="get_for_public_page"
  42.      *      }
  43.      * )
  44.      * @Security("is_granted('PUBLIC_ACCESS')")
  45.      */
  46.     public function getForPublicPage($data)
  47.     {
  48.         return $data;
  49.     }
  50.     /**
  51.      * @Route(
  52.      *      path="/public-api/conferences/get-count",
  53.      *      name="api_pub_conferences_get_for_public_page_collection_count",
  54.      *      methods={"GET"},
  55.      *      defaults={
  56.      *          "_api_resource_class"=Conference::class,
  57.      *          "_api_collection_operation_name"="get_for_public_page_count"
  58.      *      }
  59.      * )
  60.      * @Security("is_granted('PUBLIC_ACCESS')")
  61.      */
  62.     public function getForPublicPageCount($data)
  63.     {
  64.         return $data;
  65.     }
  66.     /**
  67.      * @Route(
  68.      *      path="/public-api/conferences/get/{id}",
  69.      *      name="api_pub_conferences_get_for_public_page_item",
  70.      *      methods={"GET"},
  71.      *      defaults={
  72.      *          "_api_resource_class"=Conference::class,
  73.      *          "_api_item_operation_name"="get_for_public_item_page"
  74.      *      }
  75.      * )
  76.      * @Security("is_granted('PUBLIC_ACCESS')")
  77.      */
  78.     public function getForPublicItemPage($data)
  79.     {
  80.         return $data;
  81.     }
  82.     /**
  83.      * @Route(
  84.      *      path="/api/conferences/certificate-prepare",
  85.      *      name="api_conferences_certificate_prepare",
  86.      *      methods={"POST"},
  87.      *      defaults={
  88.      *          "_api_resource_class"=Conference::class,
  89.      *          "_api_collection_operation_name"="post_certificate_prepare"
  90.      *      }
  91.      * )
  92.      */
  93.     public function certificatePrepare($data): Conference
  94.     {
  95.         return $this->handler->certificatePrepareRequest($data);
  96.     }
  97.     /**
  98.      * @Route(
  99.      *      path="/api/conferences/certificate-send",
  100.      *      name="api_conferences_certificate_send",
  101.      *      methods={"POST"},
  102.      *      defaults={
  103.      *          "_api_resource_class"=Conference::class,
  104.      *          "_api_collection_operation_name"="post_certificate_send"
  105.      *      }
  106.      * )
  107.      */
  108.     public function certificateSend($data): Conference
  109.     {
  110.         return $this->handler->certificateSendRequest($data);
  111.     }
  112.     /**
  113.      * @Route(
  114.      *      path="/api/conferences/{id}/register",
  115.      *      name="api_conferences_register",
  116.      *      methods={"PATCH"},
  117.      *      defaults={
  118.      *          "_api_resource_class"=Conference::class,
  119.      *          "_api_item_operation_name"="patch_register"
  120.      *      }
  121.      * )
  122.      */
  123.     public function register($dataEsSocket $esSocket): Conference
  124.     {
  125.         if (!$data->getIsRegisterEnable()) {
  126.             return $data;
  127.         }
  128.         if ($data->getAvailableSeats() > 0) {
  129.             $user $this->getUser();
  130.             $data->addRegisteredUser($user);
  131.             $esSocket->emit(
  132.                 'backend-command',
  133.                 [
  134.                     'type' => 'conference_register',
  135.                     'payload' => ['conferenceId' => $data->getId(), 'availableSeats' => $data->getAvailableSeats(), 'containerId' => $data->getContainer()->getId()]
  136.                 ]
  137.             );
  138.         } else {
  139.             throw new BadRequestHttpException(
  140.                 'validation.conference.register:seatsNotAvailable'
  141.             );
  142.         }
  143.         return $data;
  144.     }
  145.     /**
  146.      * @Route(
  147.      *      path="/api/conferences/{id}/unregister",
  148.      *      name="api_conferences_unregister",
  149.      *      methods={"PATCH"},
  150.      *      defaults={
  151.      *          "_api_resource_class"=Conference::class,
  152.      *          "_api_item_operation_name"="patch_unregister"
  153.      *      }
  154.      * )
  155.      */
  156.     public function unregister($dataEsSocket $esSocketEntityManagerInterface $_em): Conference
  157.     {
  158.         if (!$data->getIsRegisterEnable()) {
  159.             return $data;
  160.         }
  161.         $user $this->getUser();
  162.         if ($data->getUnregisterUserId()) {
  163.             $user $_em->getRepository(User::class)
  164.                 ->find($data->getUnregisterUserId());
  165.             if (!$user) {
  166.                 throw new BadRequestHttpException(
  167.                     'validation.conference.unregister:userNotRegistered'
  168.                 );
  169.             }
  170.         }
  171.         if ($data->hasRegisteredUser($user)) {
  172.             $data->removeRegisteredUser($user);
  173.             $esSocket->emit(
  174.                 'backend-command',
  175.                 [
  176.                     'type' => 'conference_register',
  177.                     'payload' => ['conferenceId' => $data->getId(), 'availableSeats' => $data->getAvailableSeats(), 'containerId' => $data->getContainer()->getId()]
  178.                 ]
  179.             );
  180.         } else {
  181.             throw new BadRequestHttpException(
  182.                 'validation.conference.unregister:userNotRegistered'
  183.             );
  184.         }
  185.         return $data;
  186.     }
  187. }