src/Controller/PublicController.php line 214

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Entity\Company;
  5. use App\Entity\Session;
  6. use App\Entity\UserTag;
  7. use App\Entity\ElCourse;
  8. use App\Service\EsCache;
  9. use App\Entity\Container;
  10. use App\Entity\CompanyTag;
  11. use App\Entity\Conference;
  12. use App\Entity\ElCourseTag;
  13. use App\Entity\SpecialTitle;
  14. use App\Entity\VideoGallery;
  15. use App\Entity\AcademicTitle;
  16. use App\Entity\ConferenceTag;
  17. use App\Entity\CommonCategory;
  18. use App\Entity\CreditCategory;
  19. use App\Entity\VideoGalleryTag;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Component\HttpFoundation\JsonResponse;
  25. use Symfony\Component\Serializer\SerializerInterface;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. class PublicController extends AbstractController
  28. {
  29.     /**
  30.      * @Route("/public-api/get-all", methods={"GET"}, name="api_pub_public_get_all")
  31.      * @param Request $request
  32.      * @return JsonResponse
  33.      */
  34.     public function getAll(Request $requestEntityManagerInterface $_emEsCache $esCacheSerializerInterface $serializer): JsonResponse
  35.     {
  36.         $locale $request->query->get('locale');
  37.         $containerId null;
  38.         if (!$esCache->getIsPublicClient()) {
  39.             $containerId $esCache->getContainer()->getId();
  40.         }
  41.         $clientId $esCache->getClient()->getId();
  42.         /*
  43.         $result = $esCache->setAndGet('PUBLIC_RESULT_'.$clientId);
  44.         if (empty($result)) {
  45.             $containerIds = $esCache->getClientContainerIds();
  46.             $entities = [
  47.                 'conferences' => ['class' => Conference::class, 'arg' => $containerIds, 'groups' => ['Conference:PRead'], 'rows' => 8],
  48.                 'videoGalleries' => ['class' => VideoGallery::class, 'arg' => $containerIds, 'groups' => ['VideoGallery:PRead'], 'rows' => 8],
  49.                 'courses' => ['class' => ElCourse::class, 'arg' => $containerIds, 'groups' => ['ElCourse:PRead'], 'rows' => 8],
  50.                 'attendees' => ['class' => User::class, 'arg' => $clientId, 'groups' => ['User:PRead'], 'rows' => 12],
  51.                 'containers' => ['class' => Container::class, 'arg' => $clientId, 'groups' => ['Container:PRead'], 'rows' => 8]
  52.             ];
  53.             $result = [];
  54.             foreach ($entities as $key => $entity) {
  55.                 $data = $_em->getRepository($entity['class'])
  56.                     ->getQbForPublicPage($entity['arg'])
  57.                     ->setMaxResults($entity['rows'])
  58.                     ->getQuery()
  59.                     ->getResult()
  60.                 ;
  61.                 $result[$key] = $serializer->normalize($data, null, ['groups' => $entity['groups']]);
  62.             }
  63.             $esCache->delete('PUBLIC_RESULT_'.$clientId);
  64.             $result = $esCache->setAndGet('PUBLIC_RESULT_'.$clientId, $result);
  65.         }
  66.         */
  67.         $containerIds $esCache->getIsPublicClient() ? $esCache->getClientContainerIds() : [$containerId];
  68.         $entities = [
  69.             'conferences' => ['class' => Conference::class, 'arg' => ['containerIds' => $containerIds'locale' => $locale], 'groups' => ['Conference:PRead'], 'rows' => 8],
  70.             'sessions' => ['class' => Session::class, 'arg' => ['containerIds' => $containerIds'locale' => $locale], 'groups' => ['Session:PRead'], 'rows' => 8],
  71.             'videoGalleries' => ['class' => VideoGallery::class, 'arg' => ['containerIds' => $containerIds'locale' => $locale], 'groups' => ['VideoGallery:PRead''TZ:Read'], 'rows' => 8],
  72.             'courses' => ['class' => ElCourse::class, 'arg' => ['containerIds' => $containerIds'locale' => $locale], 'groups' => ['ElCourse:PRead'], 'rows' => 8],
  73.             'attendees' => ['class' => User::class, 'arg' => ['clientId' => $clientId'locale' => $locale], 'groups' => ['User:PRead'], 'rows' => 12],
  74.             'containers' => ['class' => Container::class, 'arg' => ['clientId' => $clientId'locale' => $locale], 'groups' => ['Container:PRead'], 'rows' => 8]
  75.         ];
  76.         $result = [];
  77.         foreach ($entities as $key => $entity) {
  78.             $data $_em->getRepository($entity['class'])
  79.                 ->getQbForPublicPage($entity['arg'])
  80.                 ->setMaxResults($entity['rows'])
  81.                 ->getQuery()
  82.                 ->getResult()
  83.             ;
  84.             $result[$key] = $serializer->normalize($datanull, ['groups' => $entity['groups']]);
  85.         }
  86.         return new JsonResponse($result);
  87.     }
  88.     /**
  89.      * @Route("/public-api/iconference", methods={"GET"}, name="api_pub_public_get_i_conference")
  90.      * @param Request $request
  91.      * @return Response
  92.      */
  93.     public function getIConference(Request $requestEntityManagerInterface $_emEsCache $esCache): Response
  94.     {
  95.         $locale $request->query->get('locale');
  96.         $containerId null;
  97.         if (!$esCache->getIsPublicClient()) {
  98.             $containerId $esCache->getContainer()->getId();
  99.         }
  100.         $client $esCache->getClient();
  101.         $containerIds $esCache->getIsPublicClient() ? $esCache->getClientContainerIds() : [$containerId];
  102.         $data $_em->getRepository(Conference::class)
  103.             ->getQbForPublicPage(['containerIds' => $containerIds'locale' => $locale])
  104.             ->setMaxResults(6)
  105.             ->getQuery()
  106.             ->getResult()
  107.         ;
  108.         foreach ($data as $d) {
  109.             $tr $d->getTranslations();
  110.             if (empty($d->getTitle())) {
  111.                 $d->setTitle($tr->first()->getTitle());
  112.             }
  113.             if (empty($d->getDescription())) {
  114.                 $d->setDescription($tr->first()->getDescription());
  115.             }
  116.             $cc $d->getConferenceCategory();
  117.             if ($cc) {
  118.                 if (empty($cc->getName())) {
  119.                     $trcc $cc->getTranslations();
  120.                     $cc->setName($trcc->first()->getName());
  121.                 }
  122.             }
  123.         }
  124.         return $this->render('public_iframe/iConference.html.twig', [
  125.             'data' => $data,
  126.             'client' => $client,
  127.             'tr' => $this->getITrans($locale),
  128.             'designConfiguration' => $this->getDesignConfiguration($_em$client->getId(), $containerId)
  129.         ]);
  130.     }
  131.     /**
  132.      * @Route("/public-api/icourse", methods={"GET"}, name="api_pub_public_get_i_course")
  133.      * @param Request $request
  134.      * @return Response
  135.      */
  136.     public function getICourse(Request $requestEntityManagerInterface $_emEsCache $esCache): Response
  137.     {
  138.         $locale $request->query->get('locale');
  139.         $containerId null;
  140.         if (!$esCache->getIsPublicClient()) {
  141.             $containerId $esCache->getContainer()->getId();
  142.         }
  143.         $client $esCache->getClient();
  144.         $containerIds $esCache->getIsPublicClient() ? $esCache->getClientContainerIds() : [$containerId];
  145.         $data $_em->getRepository(ElCourse::class)
  146.             ->getQbForPublicPage(['containerIds' => $containerIds'locale' => $locale])
  147.             ->setMaxResults(6)
  148.             ->getQuery()
  149.             ->getResult()
  150.         ;
  151.         foreach ($data as $d) {
  152.             $tr $d->getTranslations();
  153.             if (empty($d->getName())) {
  154.                 $d->setName($tr->first()->getName());
  155.             }
  156.             if (empty($d->getDescription())) {
  157.                 $d->setDescription($tr->first()->getDescription());
  158.             }
  159.             $cc $d->getElCourseCategory();
  160.             if ($cc) {
  161.                 if (empty($cc->getName())) {
  162.                     $trcc $cc->getTranslations();
  163.                     $cc->setName($trcc->first()->getName());
  164.                 }
  165.             }
  166.         }
  167.         return $this->render('public_iframe/iCourse.html.twig', [
  168.             'data' => $data,
  169.             'client' => $client,
  170.             'tr' => $this->getITrans($locale),
  171.             'designConfiguration' => $this->getDesignConfiguration($_em$client->getId(), $containerId)
  172.         ]);
  173.     }
  174.     /**
  175.      * @Route("/public-api/iattendee", methods={"GET"}, name="api_pub_public_get_i_attendee")
  176.      * @param Request $request
  177.      * @return Response
  178.      */
  179.     public function getIAttendee(Request $requestEntityManagerInterface $_emEsCache $esCache): Response
  180.     {
  181.         $locale $request->query->get('locale');
  182.         $client $esCache->getClient();
  183.         $data $_em->getRepository(User::class)
  184.             ->getQbForPublicPage(['clientId' => $client->getId(), 'locale' => $locale])
  185.             ->setMaxResults(8)
  186.             ->getQuery()
  187.             ->getResult()
  188.         ;
  189.         return $this->render('public_iframe/iAttendee.html.twig', [
  190.             'data' => $data,
  191.             'client' => $client,
  192.             'tr' => $this->getITrans($locale),
  193.             'designConfiguration' => $this->getDesignConfiguration($_em$client->getId())
  194.         ]);
  195.     }
  196.     /**
  197.      * @Route("/public-api/icontainer", methods={"GET"}, name="api_pub_public_get_i_container")
  198.      * @param Request $request
  199.      * @return Response
  200.      */
  201.     public function getIContainer(Request $requestEntityManagerInterface $_emEsCache $esCache): Response
  202.     {
  203.         $locale $request->query->get('locale');
  204.         $client $esCache->getClient();
  205.         $data $_em->getRepository(Container::class)
  206.             ->getQbForPublicPage(['clientId' => $client->getId(), 'locale' => $locale])
  207.             ->setMaxResults(6)
  208.             ->getQuery()
  209.             ->getResult()
  210.         ;
  211.         return $this->render('public_iframe/iContainer.html.twig', [
  212.             'data' => $data,
  213.             'client' => $client,
  214.             'tr' => $this->getITrans($locale),
  215.             'designConfiguration' => $this->getDesignConfiguration($_em$client->getId())
  216.         ]);
  217.     }
  218.     private function getITrans($locale null)
  219.     {
  220.         $default = [
  221.             'liveNow' => 'Live Now',
  222.             'more' => 'More',
  223.             'btnRegistration' => 'Registration',
  224.             'speakerAndModerator' => 'Speaker & Moderator',
  225.             'organiser' => 'Organiser',
  226.             'new' => 'New',
  227.             'duration' => 'Duration',
  228.             'exam' => 'Exams',
  229.             'task' => 'Tasks',
  230.             'speakers' => 'Speakers',
  231.             'btnConnect' => 'Connect',
  232.         ];
  233.         $tr = [];
  234.         switch ($locale) {
  235.             case 'de':
  236.                 $tr = [
  237.                     'liveNow' => 'Jetzt Live',
  238.                     'more' => 'Mehr',
  239.                     'btnRegistration' => 'Registration',
  240.                     'speakerAndModerator' => 'Sprecher & Moderator',
  241.                     'organiser' => 'Organisator',
  242.                     'new' => 'Neu',
  243.                     'duration' => 'Dauer',
  244.                     'exam' => 'Test',
  245.                     'task' => 'Aufgabe',
  246.                     'speakers' => 'Speakers',
  247.                     'btnConnect' => 'Connect',
  248.                 ];
  249.                 break;
  250.         }
  251.         return array_merge($default$tr);
  252.     }
  253.     private function getDesignConfiguration($_em$clientId$containerId null)
  254.     {
  255.         $mainContainer null;
  256.         if (!$containerId) {
  257.             $mainContainer $_em->getRepository(Container::class)
  258.                 ->findOneBy(['client' => $clientId'isMainContainer' => true]);
  259.         } else {
  260.             $mainContainer $_em->getRepository(Container::class)
  261.                 ->find($containerId);
  262.         }
  263.         if ($mainContainer) {
  264.             return $mainContainer->getDesignConfiguration();
  265.         }
  266.         return null;
  267.     }
  268.     /**
  269.      * @Route(
  270.      *      path="/public-api/credit-categories/get",
  271.      *      name="api_pub_credit_categories_get_for_public_page_collection",
  272.      *      methods={"GET"},
  273.      *      defaults={
  274.      *          "_api_resource_class"=CreditCategory::class,
  275.      *          "_api_collection_operation_name"="get_for_public_page"
  276.      *      }
  277.      * )
  278.      */
  279.     public function getPublicCreditCategory($data)
  280.     {
  281.         return $data;
  282.     }
  283.     /**
  284.      * @Route(
  285.      *      path="/public-api/conference-tags/get",
  286.      *      name="api_pub_conference_tags_get_for_public_page_collection",
  287.      *      methods={"GET"},
  288.      *      defaults={
  289.      *          "_api_resource_class"=ConferenceTag::class,
  290.      *          "_api_collection_operation_name"="get_for_public_page"
  291.      *      }
  292.      * )
  293.      */
  294.     public function getPublicConferenceTag($data)
  295.     {
  296.         return $data;
  297.     }
  298.     /**
  299.      * @Route(
  300.      *      path="/public-api/common-categories/get",
  301.      *      name="api_pub_common_categories_tags_get_for_public_page_collection",
  302.      *      methods={"GET"},
  303.      *      defaults={
  304.      *          "_api_resource_class"=CommonCategory::class,
  305.      *          "_api_collection_operation_name"="get_for_public_page"
  306.      *      }
  307.      * )
  308.      */
  309.     public function getPublicCommonCategory($data)
  310.     {
  311.         return $data;
  312.     }
  313.     /**
  314.      * @Route(
  315.      *      path="/public-api/special-titles/get",
  316.      *      name="api_pub_special_titles_get_for_public_page_collection",
  317.      *      methods={"GET"},
  318.      *      defaults={
  319.      *          "_api_resource_class"=SpecialTitle::class,
  320.      *          "_api_collection_operation_name"="get_for_public_page"
  321.      *      }
  322.      * )
  323.      */
  324.     public function getPublicSpecialTitle($data)
  325.     {
  326.         return $data;
  327.     }
  328.     /**
  329.      * @Route(
  330.      *      path="/public-api/academic-titles/get",
  331.      *      name="api_pub_academic_titles_get_for_public_page_collection",
  332.      *      methods={"GET"},
  333.      *      defaults={
  334.      *          "_api_resource_class"=AcademicTitle::class,
  335.      *          "_api_collection_operation_name"="get_for_public_page"
  336.      *      }
  337.      * )
  338.      */
  339.     public function getPublicAcademicTitle($data)
  340.     {
  341.         return $data;
  342.     }
  343.     /**
  344.      * @Route(
  345.      *      path="/public-api/user-tags/get",
  346.      *      name="api_pub_user_tags_get_for_public_page_collection",
  347.      *      methods={"GET"},
  348.      *      defaults={
  349.      *          "_api_resource_class"=UserTag::class,
  350.      *          "_api_collection_operation_name"="get_for_public_page"
  351.      *      }
  352.      * )
  353.      */
  354.     public function getPublicUserTag($data)
  355.     {
  356.         return $data;
  357.     }
  358.     /**
  359.      * @Route(
  360.      *      path="/public-api/companies/get",
  361.      *      name="api_pub_companies_get_for_public_page_collection",
  362.      *      methods={"GET"},
  363.      *      defaults={
  364.      *          "_api_resource_class"=Company::class,
  365.      *          "_api_collection_operation_name"="get_for_public_page"
  366.      *      }
  367.      * )
  368.      */
  369.     public function getPublicCompany($data)
  370.     {
  371.         return $data;
  372.     }
  373.     /**
  374.      * @Route(
  375.      *      path="/public-api/company-tags/get",
  376.      *      name="api_pub_company_tags_get_for_public_page_collection",
  377.      *      methods={"GET"},
  378.      *      defaults={
  379.      *          "_api_resource_class"=CompanyTag::class,
  380.      *          "_api_collection_operation_name"="get_for_public_page"
  381.      *      }
  382.      * )
  383.      */
  384.     public function getPublicCompanyTag($data)
  385.     {
  386.         return $data;
  387.     }
  388.     /**
  389.      * @Route(
  390.      *      path="/public-api/el-course-tags/get",
  391.      *      name="api_pub_el_course_tags_get_for_public_page_collection",
  392.      *      methods={"GET"},
  393.      *      defaults={
  394.      *          "_api_resource_class"=ElCourseTag::class,
  395.      *          "_api_collection_operation_name"="get_for_public_page"
  396.      *      }
  397.      * )
  398.      */
  399.     public function getPublicElCourseTag($data)
  400.     {
  401.         return $data;
  402.     }
  403.     /**
  404.      * @Route(
  405.      *      path="/public-api/video-gallery-tags/get",
  406.      *      name="api_pub_video_gallery_tags_get_for_public_page_collection",
  407.      *      methods={"GET"},
  408.      *      defaults={
  409.      *          "_api_resource_class"=VideoGalleryTag::class,
  410.      *          "_api_collection_operation_name"="get_for_public_page"
  411.      *      }
  412.      * )
  413.      */
  414.     public function getPublicVideoGalleryTag($data)
  415.     {
  416.         return $data;
  417.     }
  418. }