|
4 | 4 |
|
5 | 5 | namespace App\Controller;
|
6 | 6 |
|
| 7 | +use App\DTO\ModlogFilterDto; |
| 8 | +use App\Entity\Magazine; |
| 9 | +use App\Form\ModlogFilterType; |
7 | 10 | use App\Repository\MagazineLogRepository;
|
| 11 | +use Symfony\Bridge\Doctrine\Attribute\MapEntity; |
8 | 12 | use Symfony\Component\HttpFoundation\Request;
|
9 | 13 | use Symfony\Component\HttpFoundation\Response;
|
10 | 14 |
|
11 | 15 | class ModlogController extends AbstractController
|
12 | 16 | {
|
13 |
| - public function __invoke(MagazineLogRepository $repository, Request $request): Response |
| 17 | + public function __construct( |
| 18 | + private readonly MagazineLogRepository $magazineLogRepository, |
| 19 | + ) { |
| 20 | + } |
| 21 | + |
| 22 | + public function instance(Request $request): Response |
14 | 23 | {
|
| 24 | + $dto = new ModlogFilterDto(); |
| 25 | + $dto->magazine = null; |
| 26 | + $form = $this->createForm(ModlogFilterType::class, $dto, ['method' => 'GET']); |
| 27 | + $form->handleRequest($request); |
| 28 | + if ($form->isSubmitted() && $form->isValid()) { |
| 29 | + /** @var ModlogFilterDto $dto */ |
| 30 | + $dto = $form->getData(); |
| 31 | + |
| 32 | + if (null !== $dto->magazine) { |
| 33 | + return $this->redirectToRoute('magazine_modlog', ['name' => $dto->magazine->name]); |
| 34 | + } |
| 35 | + $logs = $this->magazineLogRepository->findByCustom($this->getPageNb($request), types: $dto->types); |
| 36 | + } else { |
| 37 | + $logs = $this->magazineLogRepository->findByCustom($this->getPageNb($request)); |
| 38 | + } |
| 39 | + |
| 40 | + return $this->render( |
| 41 | + 'modlog/front.html.twig', |
| 42 | + [ |
| 43 | + 'logs' => $logs, |
| 44 | + 'form' => $form, |
| 45 | + ] |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + public function magazine(#[MapEntity] ?Magazine $magazine, Request $request): Response |
| 50 | + { |
| 51 | + $dto = new ModlogFilterDto(); |
| 52 | + $dto->magazine = $magazine; |
| 53 | + $form = $this->createForm(ModlogFilterType::class, $dto, ['method' => 'GET']); |
| 54 | + $form->handleRequest($request); |
| 55 | + if ($form->isSubmitted() && $form->isValid()) { |
| 56 | + /** @var ModlogFilterDto $dto */ |
| 57 | + $dto = $form->getData(); |
| 58 | + if (null === $dto->magazine) { |
| 59 | + return $this->redirectToRoute('modlog'); |
| 60 | + } elseif ($dto->magazine?->name !== $magazine->name) { |
| 61 | + return $this->redirectToRoute('magazine_modlog', ['name' => $dto->magazine->name]); |
| 62 | + } |
| 63 | + $logs = $this->magazineLogRepository->findByCustom($this->getPageNb($request), types: $dto->types, magazine: $magazine); |
| 64 | + } else { |
| 65 | + $logs = $this->magazineLogRepository->findByCustom($this->getPageNb($request), magazine: $magazine); |
| 66 | + } |
| 67 | + |
15 | 68 | return $this->render(
|
16 | 69 | 'modlog/front.html.twig',
|
17 | 70 | [
|
18 |
| - 'logs' => $repository->listAll($this->getPageNb($request)), |
| 71 | + 'magazine' => $magazine, |
| 72 | + 'logs' => $logs, |
| 73 | + 'form' => $form, |
19 | 74 | ]
|
20 | 75 | );
|
21 | 76 | }
|
|
0 commit comments