src/Controller/Content/CategoryImagesetController.php line 39

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\ImagesetListingService;
  6. use App\Service\Search\ImagesetSearchService;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route("/kategorien/bilder")
  13.  */
  14. class CategoryImagesetController extends AbstractController
  15. {
  16.     protected CategoryService $service;
  17.     protected ImagesetListingService $imagesetService;
  18.     protected ImagesetSearchService $searchService;
  19.     public function __construct(CategoryService $serviceImagesetListingService $imagesetServiceImagesetSearchService $searchService)
  20.     {
  21.         $this->service $service;
  22.         $this->imagesetService $imagesetService;
  23.         $this->searchService $searchService;
  24.     }
  25.     /**
  26.      * @Route("")
  27.      * @Template()
  28.      * @throws \Psr\Cache\InvalidArgumentException
  29.      * @throws \ReflectionException
  30.      */
  31.     public function index(): array
  32.     {
  33.         return [
  34.             'tree' => $this->service->getTree()
  35.         ];
  36.     }
  37.     /**
  38.      * @Route("/{slug}")
  39.      * @Template()
  40.      * @param string $slug
  41.      * @return array
  42.      */
  43.     public function group(string $slug): array
  44.     {
  45.         $group $this->service->getGroupBySlug($slug);
  46.         if (!$group) {
  47.             throw $this->createNotFoundException();
  48.         }
  49.         return [
  50.             'group' => $group,
  51.         ];
  52.     }
  53.     /**
  54.      * @Route("/{group}/{slug}/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  55.      * @Template()
  56.      * @param string $group
  57.      * @param string $slug
  58.      * @param int $page
  59.      * @param Request $request
  60.      * @return array
  61.      * @throws \Psr\Cache\InvalidArgumentException
  62.      * @throws \ReflectionException
  63.      * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
  64.      * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
  65.      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
  66.      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
  67.      */
  68.     public function category(string $groupstring $slugint $pageRequest $request): array
  69.     {
  70.         $searchOptions = new SearchOptions();
  71.         $searchOptions
  72.             ->setPage($page)
  73.             ->setPerPage(30)
  74.             ->applySorting($request->query);
  75.         $imagesetSearchResults $this->searchService->findByCategorySlug($group$slug$searchOptions);
  76.         $category $this->service->getCategoryBySlug($slug);
  77.         $group $this->service->getGroupBySlug($group);
  78.         if (!$category || !$group) {
  79.             throw $this->createNotFoundException();
  80.         }
  81.         return [
  82.             'tree' => $this->service->getTree(),
  83.             'category' => $category,
  84.             'group' => $group,
  85.             'imagesets' => $imagesetSearchResults,
  86.             'page' => $page,
  87.         ];
  88.     }
  89. }