diff --git a/src/Controller/TagController.php b/src/Controller/TagController.php new file mode 100644 index 00000000..8f26644b --- /dev/null +++ b/src/Controller/TagController.php @@ -0,0 +1,52 @@ + '\d+'])] + public function index(BookRepository $bookRepository, PaginatorInterface $paginator, int $page = 1): Response + { + $tags = $bookRepository->getAllTags(); + + $pagination = $paginator->paginate($tags, $page, 18); + + return $this->render('group/index.html.twig', [ + 'pagination' => $pagination, + 'page' => $page, + 'type' => 'tags', + ]); + } + + #[Route('/{slug}/{page}', name: 'app_tags_detail', requirements: ['page' => '\d+'])] + public function detail(string $slug, BookRepository $bookRepository, PaginatorInterface $paginator, int $page = 1): Response + { + $tags = $bookRepository->getAllTags(); + + $slug = urldecode($slug); + dump($slug); + $tag = $tags[$slug] ?? null; + + if (null === $tag) { + return $this->redirectToRoute('app_tags'); + } + + $pagination = $paginator->paginate( + $bookRepository->getByTagQuery($tag['item']), + $page, + 18 + ); + + return $this->render('author/detail.html.twig', [ + 'pagination' => $pagination, + 'author' => $tag, + ]); + } +} diff --git a/src/EventSubscriber/DisplayModeSubscriber.php b/src/EventSubscriber/DisplayModeSubscriber.php index 2a72d160..5f91a1a4 100644 --- a/src/EventSubscriber/DisplayModeSubscriber.php +++ b/src/EventSubscriber/DisplayModeSubscriber.php @@ -10,7 +10,7 @@ class DisplayModeSubscriber implements EventSubscriberInterface { - private string $displayMode; + private string $displayMode='gallery'; public function onKernelRequest(RequestEvent $event): void { diff --git a/src/Menu/MenuBuilder.php b/src/Menu/MenuBuilder.php index 5f2df47d..57c0bc00 100644 --- a/src/Menu/MenuBuilder.php +++ b/src/Menu/MenuBuilder.php @@ -36,6 +36,7 @@ public function createMainMenu(array $options): ItemInterface $menu->addChild('Not read', ['route' => 'app_read', 'routeParameters' => ['read' => 0], ...$this->defaultAttr])->setExtra('icon', 'journal'); $menu->addChild('Series', ['route' => 'app_serie', ...$this->defaultAttr])->setExtra('icon', 'list'); $menu->addChild('Authors', ['route' => 'app_authors', ...$this->defaultAttr])->setExtra('icon', 'people-fill'); + $menu->addChild('Tags', ['route' => 'app_tags', ...$this->defaultAttr])->setExtra('icon', 'tags-fill'); $menu->addChild('Unverified', ['route' => 'app_unverified', ...$this->defaultAttr])->setExtra('icon', 'question-circle-fill'); $menu->addChild('setting_divider', ['label' => 'Others'])->setExtra('divider', true); $menu->addChild('Settings', ['route' => 'admin', ...$this->defaultAttr])->setExtra('icon', 'gear-fill'); diff --git a/src/Repository/BookRepository.php b/src/Repository/BookRepository.php index 317a4b52..98803927 100644 --- a/src/Repository/BookRepository.php +++ b/src/Repository/BookRepository.php @@ -73,6 +73,15 @@ public function getByAuthorQuery(string $author): Query ->getQuery(); } + public function getByTagQuery(string $tag): Query + { + return $this->createQueryBuilder('b') + ->select('b') + ->where('JSON_CONTAINS(b.tags, :tag)=1') + ->setParameter('tag', json_encode([$tag])) + ->getQuery(); + } + public function getBySerieQuery(string $serieSlug): Query { return $this->createQueryBuilder('b') diff --git a/templates/group/index.html.twig b/templates/group/index.html.twig index 29505a07..e91c9348 100644 --- a/templates/group/index.html.twig +++ b/templates/group/index.html.twig @@ -13,7 +13,7 @@