|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Block\Service; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
8
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
|
9
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractBlockService; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Twig\Environment; |
|
12
|
|
|
use VideoGamesRecords\CoreBundle\ValueObject\ProofRequestStatus; |
|
13
|
|
|
|
|
14
|
|
|
class ProofRequestBlockService extends AbstractBlockService |
|
15
|
|
|
{ |
|
16
|
|
|
public function __construct(Environment $templating, private readonly EntityManagerInterface $em) |
|
17
|
|
|
{ |
|
18
|
|
|
parent::__construct($templating); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getName(): string |
|
25
|
|
|
{ |
|
26
|
|
|
return 'Proof Request Block'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param BlockContextInterface $blockContext |
|
31
|
|
|
* @param Response|null $response |
|
32
|
|
|
* @return Response |
|
33
|
|
|
*/ |
|
34
|
|
|
public function execute( |
|
35
|
|
|
BlockContextInterface $blockContext, |
|
36
|
|
|
?Response $response = null |
|
37
|
|
|
): Response { |
|
38
|
|
|
$settings = $blockContext->getSettings(); |
|
39
|
|
|
|
|
40
|
|
|
// Requête pour récupérer les demandes de preuve en cours |
|
41
|
|
|
$proofRequestsQuery = $this->em->createQueryBuilder() |
|
42
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\ProofRequest', 'pr') |
|
43
|
|
|
->select('pr') |
|
44
|
|
|
->addSelect('pc', 'p', 'c', 'g', 'game') |
|
45
|
|
|
->leftJoin('pr.playerChart', 'pc') |
|
46
|
|
|
->leftJoin('pc.player', 'p') |
|
47
|
|
|
->leftJoin('pc.chart', 'c') |
|
48
|
|
|
->leftJoin('c.group', 'g') |
|
49
|
|
|
->leftJoin('g.game', 'game') |
|
50
|
|
|
->leftJoin('pr.playerRequesting', 'requesting') |
|
51
|
|
|
->leftJoin('pr.playerResponding', 'responding') |
|
52
|
|
|
->where('pr.status = :status') |
|
53
|
|
|
->setParameter('status', ProofRequestStatus::IN_PROGRESS) |
|
54
|
|
|
->orderBy('pr.createdAt', 'DESC'); |
|
55
|
|
|
|
|
56
|
|
|
$proofRequests = $proofRequestsQuery->getQuery()->getResult(); |
|
57
|
|
|
|
|
58
|
|
|
// Nombre total de demandes en cours |
|
59
|
|
|
$totalRequestsQuery = $this->em->createQueryBuilder() |
|
60
|
|
|
->from('VideoGamesRecords\CoreBundle\Entity\ProofRequest', 'pr') |
|
61
|
|
|
->select('COUNT(pr.id)') |
|
62
|
|
|
->where('pr.status = :status') |
|
63
|
|
|
->setParameter('status', ProofRequestStatus::IN_PROGRESS); |
|
64
|
|
|
|
|
65
|
|
|
$totalRequests = (int)$totalRequestsQuery->getQuery()->getSingleScalarResult(); |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
return $this->renderResponse( |
|
69
|
|
|
'@VideoGamesRecordsCore/Admin/Block/proof_requests.html.twig', |
|
70
|
|
|
[ |
|
71
|
|
|
'block' => $blockContext->getBlock(), |
|
72
|
|
|
'settings' => $settings, |
|
73
|
|
|
'proofRequests' => $proofRequests, |
|
74
|
|
|
'totalRequests' => $totalRequests |
|
75
|
|
|
], |
|
76
|
|
|
$response |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|