src/Admin/Controller/RevisionController.php line 127

Open in your IDE?
  1. <?php
  2. namespace App\Admin\Controller;
  3. use App\Application\Controller\AbstractController;
  4. use App\Application\Manager\GenericManager;
  5. use App\Application\Messenger\ErrorResponseBuilder;
  6. use App\Application\Service\BubbleNotificationService;
  7. use App\Domain\Entity\PointOfInterest;
  8. use App\Domain\Entity\PointOfInterestGps;
  9. use App\Infrastructure\Repository\AwardRepository;
  10. use App\Infrastructure\Repository\PointOfInterestGpsRepository;
  11. use App\Infrastructure\Repository\PointOfInterestRepository;
  12. use App\Query\PointOfInterest\GetCommentsOverviewQuery;
  13. use App\Query\PointOfInterest\GetJSONRevisionsLogQuery;
  14. use App\Query\PointOfInterest\GetRevisionsQuery;
  15. use Exception;
  16. use JsonException;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Messenger\MessageBusInterface;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. /**
  21.  * Class LocaleController
  22.  *
  23.  * @package App\Admin\Controller
  24.  */
  25. class RevisionController extends AbstractController
  26. {
  27.     public function __construct(
  28.         ErrorResponseBuilder $errorResponseBuilder,
  29.         MessageBusInterface $commandBus,
  30.         MessageBusInterface $queryBus,
  31.         private readonly BubbleNotificationService $bubbleNotificationService,
  32.         private readonly AwardRepository $awardsRepository,
  33.         private readonly PointOfInterestGpsRepository $pointOfInterestGpsRepository,
  34.         private readonly PointOfInterestRepository $pointOfInterestRepository,
  35.         private readonly GenericManager $genericManager,
  36.     ) {
  37.         parent::__construct($errorResponseBuilder$commandBus$queryBus);
  38.     }
  39.     #[Route('/revisions/add'name'revision_add')]
  40.     public function add(): Response
  41.     {
  42.         return $this->render('admin/revision/add.html.twig', [
  43.             'notifications' => $this->bubbleNotificationService->getNotifications(),
  44.             'location' => 'revision_add',
  45.         ]);
  46.     }
  47.     /**
  48.      * @throws JsonException
  49.      */
  50.     #[Route('/point_of_interest/{uuid}/logs'name'poi_logs')]
  51.     public function logs(PointOfInterest $pointOfInterest): Response
  52.     {
  53.         $revisionLogsQuery = new GetJSONRevisionsLogQuery($pointOfInterest);
  54.         $revisionsLogs $this->executeQuery($revisionLogsQuery);
  55.         return $this->render('admin/revision/logs.html.twig', [
  56.             'revisionsLogs' => json_encode($revisionsLogsJSON_THROW_ON_ERROR),
  57.             'notifications' => $this->bubbleNotificationService->getNotifications(),
  58.             'location' => 'revision',
  59.             'pointOfInterest' => $pointOfInterest,
  60.         ]);
  61.     }
  62.     /**
  63.      * @throws JsonException
  64.      */
  65.     #[Route('/revisions/debug-gps'name'debug_gps')]
  66.     public function poiGps(): Response
  67.     {
  68.         /** @var PointOfInterestGps[] $pointOfInterestGPSs */
  69.         $pointOfInterestGPSs $this->pointOfInterestGpsRepository->findBy(['isSolved' => false]);
  70.         $toDelete array_filter(
  71.             $pointOfInterestGPSs,
  72.             static fn (PointOfInterestGps $gps) => $gps->revision1->isDeleted() || $gps->revision2->isDeleted(),
  73.         );
  74.         $this->genericManager->removeAll($toDelete);
  75.         if (count($toDelete)) {
  76.             $pointOfInterestGPSs $this->pointOfInterestGpsRepository->findBy(['isSolved' => false]);
  77.         }
  78.         /** @var PointOfInterestGps|null $pointOfInterestGps */
  79.         $pointOfInterestGps = empty($pointOfInterestGPSs) ? null $pointOfInterestGPSs[array_rand(
  80.             $pointOfInterestGPSs,
  81.         )];
  82.         return $this->render('admin/revision/debug-gps.html.twig', [
  83.             'revisions' => json_encode([
  84.                 $pointOfInterestGps?->revision1->uuid,
  85.                 $pointOfInterestGps?->revision2->uuid,
  86.             ], JSON_THROW_ON_ERROR),
  87.             'notifications' => $this->bubbleNotificationService->getNotifications(),
  88.             'location' => 'revision_gps',
  89.         ]);
  90.     }
  91.     /**
  92.      * @throws JsonException
  93.      * @throws Exception
  94.      */
  95.     #[Route('/point_of_interest/certification'name'poi_certification_edit')]
  96.     public function certificationDetail(): Response
  97.     {
  98.         $pointOfInterest $this->pointOfInterestRepository->findOldestPoiWithLastRevisionNotMain();
  99.         if (!$pointOfInterest) return $this->redirectToRoute('revision_index');
  100.         return $this->handleEdit($pointOfInteresttrue);
  101.     }
  102.     /**
  103.      * @throws JsonException
  104.      */
  105.     #[Route('/point_of_interest/{uuid}'name'poi_edit')]
  106.     public function edit(PointOfInterest $pointOfInterest): Response
  107.     {
  108.         return $this->handleEdit($pointOfInterestfalse);
  109.     }
  110.     #[Route('/point_of_interest'name'revision_index')]
  111.     public function index(): Response
  112.     {
  113.         return $this->render('admin/revision/index.html.twig', [
  114.             'notifications' => $this->bubbleNotificationService->getNotifications(),
  115.             'location' => 'revision',
  116.         ]);
  117.     }
  118.     /**
  119.      * @throws JsonException
  120.      */
  121.     private function handleEdit(PointOfInterest $pointOfInterestbool $certificationMode): Response
  122.     {
  123.         $revisionQuery = new GetRevisionsQuery($pointOfInterest);
  124.         $revisions $this->executeQuery($revisionQuery);
  125.         $commentQuery = new GetCommentsOverviewQuery($pointOfInterest);
  126.         $commentsOverview $this->executeQuery($commentQuery);
  127.         $pointOfInterestAwards $this->awardsRepository->findByPointOfInterest($pointOfInterest);
  128.         $pointOfInterestAwards array_map(static fn ($award) => "/api/awards/$award->uuid"$pointOfInterestAwards);
  129.         return $this->render('admin/revision/edit.html.twig', [
  130.             'totalComments' => $commentsOverview['total'],
  131.             'currentMainNumber' => $revisions['currentMainNumber'],
  132.             'newComments' => $commentsOverview['new'],
  133.             'pointOfInterest' => $pointOfInterest->uuid,
  134.             'revisions' => json_encode($revisions['revisions'], JSON_THROW_ON_ERROR),
  135.             'revisionUuid' => $revisions['revisions'][0]['uuid'],
  136.             'revisionId' => $revisions['revisions'][0]['id'],
  137.             'notifications' => $this->bubbleNotificationService->getNotifications(),
  138.             'location' => $certificationMode 'revision_certification' 'revision',
  139.             'pointOfInterestAwards' => json_encode($pointOfInterestAwardsJSON_THROW_ON_ERROR),
  140.             'certificationMode' => $certificationMode 0,
  141.         ]);
  142.     }
  143. }