src/Controller/DesktopController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Document\AppealExecution;
  4. use App\Document\Appeal;
  5. use App\Document\Resource;
  6. use App\Service\AppealExecutionsHelper;
  7. use Doctrine\ODM\MongoDB\DocumentManager;
  8. use Psr\Log\LoggerInterface;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. class DesktopController extends AbstractController
  17. {
  18.     public function __construct(
  19.         private DocumentManager $dm,
  20.         private LoggerInterface $logger,
  21.         private AppealExecutionsHelper $appealExecutionsHelper
  22.     )
  23.     {
  24.     }
  25.     #[Route('/desktop'name'desktop'methods: ['GET',])]
  26.     #[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_PROVIDER')")]
  27.     public function index(Request $request): Response
  28.     {
  29.         return $this->render('desktop/index.html.twig');
  30.     }
  31.     #[Route('/get_executions_count'name'get_executions_count'methods: ['GET',])]
  32.     #[IsGranted('IS_AUTHENTICATED_FULLY')]
  33.     public function getExecutionsCount(Request $request): JsonResponse
  34.     {
  35.         $appealsByResourcesTypeNumber count($this->dm->getRepository(Appeal::class)->getByResourcesType(
  36.             $this->dm->getRepository(Resource::class)->getByUserId($this->getUser()->getId())
  37.         )->toArray());
  38.         $appealExecutionNumber count($this->appealExecutionsHelper->removeBrokenExecutions(
  39.             $this->dm->createQueryBuilder(AppealExecution::class)
  40.                 ->field('resourceOwner.id')->equals($this->getUser()->getId())
  41.                 ->field('status')->equals(AppealExecution::STATUS_CONFIRMATION)
  42.                 ->getQuery()->execute()->toArray())
  43.         );
  44.         $resourceAppealsCount count($this->appealExecutionsHelper->removeBrokenExecutions(
  45.             $this->dm->createQueryBuilder(AppealExecution::class)
  46.                 ->field('resourceOwner.id')->equals($this->getUser()->getId())
  47.                 ->field('status')->equals(AppealExecution::STATUS_BOOKED)
  48.                 ->getQuery()->execute()->toArray())
  49.         );
  50.         $executionAppealsNumber count($this->appealExecutionsHelper->removeBrokenExecutions(
  51.             $this->dm->createQueryBuilder(AppealExecution::class)
  52.                 ->field('appealOwner.id')->equals($this->getUser()->getId())
  53.                 ->field('status')->equals(AppealExecution::STATUS_BOOKED)
  54.                 ->getQuery()->execute()->toArray())
  55.         );
  56.         $executionInWorkNumber count($this->appealExecutionsHelper->removeBrokenExecutions(
  57.             $this->dm->createQueryBuilder(AppealExecution::class)
  58.                 ->field('resourceOwner.id')->equals($this->getUser()->getId())
  59.                 ->field('status')->equals(AppealExecution::STATUS_WORK)
  60.                 ->getQuery()->execute()->toArray())
  61.         );
  62.         return $this->json([
  63.             'sum' => $appealsByResourcesTypeNumber $appealExecutionNumber $resourceAppealsCount +
  64.                 $executionAppealsNumber $executionInWorkNumber,
  65.             'appealsByResourcesTypeNumber' => $appealsByResourcesTypeNumber,
  66.             'appealExecutionNumber' => $appealExecutionNumber,
  67.             'resourceAppealsCount' => $resourceAppealsCount,
  68.             'executionAppealsNumber' => $executionAppealsNumber,
  69.             'executionInWorkNumber' => $executionInWorkNumber
  70.         ]);
  71.     }
  72.     #[Route('/desktop/appeals'name'catalog_appeals'methods: ['GET',])]
  73.     #[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_PROVIDER')")]
  74.     public function appealsCatalog(Request $request): Response
  75.     {
  76.         $userResources $this->dm->getRepository(Resource::class)
  77.             ->getByUserId($this->getUser()->getId());
  78.         $appealsByResourcesType $this->dm->getRepository(Appeal::class)
  79.             ->getByResourcesType($userResources);
  80.         return $this->render('/desktop/appeals-catalog.html.twig', [
  81.             'appeals' => $appealsByResourcesType,
  82.         ]);
  83.     }
  84.     #[Route('/desktop/appeals/confirmation'name'resource_confirmation_list'methods: ['GET',])]
  85.     #[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_PROVIDER')")]
  86.     public function resourcesForConfirmation(Request $request): Response
  87.     {
  88.         $appealExecution $this->appealExecutionsHelper->removeBrokenExecutions(
  89.             $this->dm->createQueryBuilder(AppealExecution::class)
  90.                 ->field('resourceOwner.id')->equals($this->getUser()->getId())
  91.                 ->field('status')->equals(AppealExecution::STATUS_CONFIRMATION)
  92.                 ->getQuery()->execute()
  93.         );
  94.         return $this->render(
  95.             '/desktop/resources-confirmation.html.twig', [
  96.                 'appealExecutions' => $appealExecution,
  97.             ]
  98.         );
  99.     }
  100.     #[Route('desktop/booked-appeals'name'appeals_to_perform'methods: ['GET',])]
  101.     #[IsGranted('IS_AUTHENTICATED_FULLY')]
  102.     public function appealsToPerform(Request $request): Response
  103.     {
  104.         $resourcesAppeals $this->appealExecutionsHelper->removeBrokenExecutions(
  105.             $this->dm->createQueryBuilder(AppealExecution::class)
  106.                 ->field('resourceOwner.id')->equals($this->getUser()->getId())
  107.                 ->field('status')->equals(AppealExecution::STATUS_BOOKED)
  108.                 ->getQuery()->execute()
  109.         );
  110.         return $this->render('desktop/appeals-ready-to-perform.html.twig', [
  111.             'appeal_resource' => $resourcesAppeals,
  112.         ]);
  113.     }
  114.     #[Route('execution/booking-appeals'name'booked_appeals'methods: ['POST''GET'])]
  115.     #[IsGranted('IS_AUTHENTICATED_FULLY')]
  116.     public function bookedAppeals(Request $request): Response
  117.     {
  118.         $executionAppeals $this->appealExecutionsHelper->removeBrokenExecutions(
  119.             $this->dm->createQueryBuilder(AppealExecution::class)
  120.                 ->field('appealOwner.id')->equals($this->getUser()->getId())
  121.                 ->field('status')->equals(AppealExecution::STATUS_BOOKED)
  122.                 ->getQuery()->execute()
  123.         );
  124.         return $this->render('desktop/booked-appeals.html.twig', [
  125.             'executions' => $executionAppeals,
  126.         ]);
  127.     }
  128.     #[Route('desktop/appeals-in-work'name'appeals_in_work'methods: ['GET'])]
  129.     #[IsGranted('IS_AUTHENTICATED_FULLY')]
  130.     public function appealsInWork(Request $request): Response
  131.     {
  132.         return $this->render('desktop/appeals-in-work.html.twig', [
  133.             'executions' => $this->appealExecutionsHelper->removeBrokenExecutions(
  134.                 $this->dm->getRepository(AppealExecution::class)
  135.                 ->getAppeals($this->getUser(), [AppealExecution::STATUS_WORK])
  136.             ),
  137.         ]);
  138.     }
  139. }