src/Pumukit/WebTVBundle/Controller/AnnouncesController.php line 47

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Pumukit\WebTVBundle\Controller;
  4. use Pumukit\CoreBundle\Controller\WebTVControllerInterface;
  5. use Pumukit\SchemaBundle\Services\AnnounceService;
  6. use Pumukit\WebTVBundle\Services\BreadcrumbsService;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. class AnnouncesController extends AbstractController implements WebTVControllerInterface
  13. {
  14.     protected $translator;
  15.     protected $breadcrumbsService;
  16.     protected $columnsObjsAnnounces;
  17.     protected $menuAnnouncesTitle;
  18.     protected $announcesService;
  19.     protected $showLatestWithPudeNew;
  20.     protected $useRecordDateAnnounce;
  21.     public function __construct(
  22.         TranslatorInterface $translator,
  23.         BreadcrumbsService $breadcrumbsService,
  24.         AnnounceService $announcesService,
  25.         int $columnsObjsAnnounces,
  26.         string $menuAnnouncesTitle,
  27.         $showLatestWithPudeNew,
  28.         $useRecordDateAnnounce
  29.     ) {
  30.         $this->translator $translator;
  31.         $this->breadcrumbsService $breadcrumbsService;
  32.         $this->columnsObjsAnnounces $columnsObjsAnnounces;
  33.         $this->menuAnnouncesTitle $menuAnnouncesTitle;
  34.         $this->announcesService $announcesService;
  35.         $this->showLatestWithPudeNew $showLatestWithPudeNew;
  36.         $this->useRecordDateAnnounce $useRecordDateAnnounce;
  37.     }
  38.     /**
  39.      * @Route("/latestuploads", name="pumukit_webtv_announces_latestuploads")
  40.      */
  41.     public function latestUploadsAction(): Response
  42.     {
  43.         $templateTitle $this->translator->trans($this->menuAnnouncesTitle);
  44.         $this->breadcrumbsService->addList($templateTitle'pumukit_webtv_announces_latestuploads');
  45.         return $this->render('@PumukitWebTV/Announces/template.html.twig', [
  46.             'template_title' => $templateTitle,
  47.             'objectByCol' => $this->columnsObjsAnnounces,
  48.             'show_info' => false,
  49.             'show_more' => false,
  50.         ]);
  51.     }
  52.     /**
  53.      * @Route("/latestuploads/pager", name="pumukit_webtv_announces_latestuploads_pager")
  54.      */
  55.     public function latestUploadsPagerAction(Request $request): Response
  56.     {
  57.         $dateRequest $request->query->get('date'0);
  58.         $date \DateTime::createFromFormat('d/m/Y H:i:s'"01/{$dateRequest} 00:00:00");
  59.         if (!$date) {
  60.             throw $this->createNotFoundException();
  61.         }
  62.         [$date$last] = $this->announcesService->getNextLatestUploads($date$this->showLatestWithPudeNew$this->useRecordDateAnnounce);
  63.         $response = new Response();
  64.         $dateHeader '---';
  65.         if (!empty($last)) {
  66.             $response = new Response(
  67.                 $this->renderView(
  68.                     $this->getLatestUploadsPagerTemplate(),
  69.                     [
  70.                         'last' => $last,
  71.                         'date' => $date,
  72.                         'objectByCol' => $this->columnsObjsAnnounces,
  73.                         'show_info' => false,
  74.                         'show_more' => false,
  75.                     ]
  76.                 ),
  77.                 200
  78.             );
  79.             $dateHeader $date->format('m/Y');
  80.             $response->headers->set('X-Date-Month'$date->format('m'));
  81.             $response->headers->set('X-Date-Year'$date->format('Y'));
  82.         }
  83.         $response->headers->set('X-Date'$dateHeader);
  84.         return $response;
  85.     }
  86.     protected function getLatestUploadsPagerTemplate(): string
  87.     {
  88.         return '@PumukitWebTV/Announces/template_pager.html.twig';
  89.     }
  90. }