src/Controller/Content/CategoryVideoController.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Content;
  3. use App\Dto\SearchOptions;
  4. use App\Service\Client\Content\CategoryService;
  5. use App\Service\Client\Content\VideoListingService;
  6. use App\Service\Search\VideoSearchService;
  7. use Elasticsearch\Common\Exceptions\Missing404Exception;
  8. use Psr\Log\LoggerInterface;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * @Route("/kategorien/videos")
  15.  */
  16. class CategoryVideoController extends AbstractController
  17. {
  18.     protected CategoryService $service;
  19.     protected VideoListingService $videoService;
  20.     protected VideoSearchService $searchService;
  21.     public function __construct(CategoryService $serviceVideoListingService $videoServiceVideoSearchService $searchService)
  22.     {
  23.         $this->service $service;
  24.         $this->videoService $videoService;
  25.         $this->searchService $searchService;
  26.     }
  27.     /**
  28.      * @Route("")
  29.      * @Template()
  30.      * @throws \Psr\Cache\InvalidArgumentException
  31.      * @throws \ReflectionException
  32.      */
  33.     public function index(): array
  34.     {
  35.         return [
  36.             'tree' => $this->service->getTree()
  37.         ];
  38.     }
  39.     /**
  40.      * @Route("/{slug}")
  41.      * @Template()
  42.      * @param string $slug
  43.      * @return array
  44.      */
  45.     public function group(string $slug): array
  46.     {
  47.         $group $this->service->getGroupBySlug($slug);
  48.         if (!$group) {
  49.             throw $this->createNotFoundException();
  50.         }
  51.         return [
  52.             'group' => $group,
  53.         ];
  54.     }
  55.     /**
  56.      * @Route("/{group}/{slug}/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  57.      * @Template()
  58.      * @param string $group
  59.      * @param string $slug
  60.      * @param int $page
  61.      * @param Request $request
  62.      * @return array
  63.      * @throws \Psr\Cache\InvalidArgumentException
  64.      * @throws \ReflectionException
  65.      * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
  66.      * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
  67.      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
  68.      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
  69.      */
  70.     public function category(string $groupstring $slugint $pageRequest $requestLoggerInterface $logger): array
  71.     {
  72.         $searchOptions = new SearchOptions();
  73.         $searchOptions
  74.             ->setPage($page)
  75.             ->setPerPage(30)
  76.             ->applySorting($request->query);
  77.         try {
  78.             $videoSearchResults $this->searchService->findByCategorySlug($group$slug$searchOptions);
  79.         } catch (\Exception $e) {
  80.             $logger->critical($e->getMessage() . PHP_EOL $e->getTraceAsString());
  81.             $videoSearchResults = [];
  82.         }
  83.         $category $this->service->getCategoryBySlug($slug);
  84.         $group $this->service->getGroupBySlug($group);
  85.         if (!$category || !$group) {
  86.             throw $this->createNotFoundException();
  87.         }
  88.         return [
  89.             'tree' => $this->service->getTree(),
  90.             'category' => $category,
  91.             'group' => $group,
  92.             'videos' => $videoSearchResults,
  93.             'page' => $page,
  94.         ];
  95.     }
  96. }