1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Block; |
15
|
|
|
|
16
|
|
|
use SimpleThings\EntityAudit\AuditReader; |
17
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
18
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractBlockService; |
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
20
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
21
|
|
|
use Twig\Environment; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Thomas Rabaix <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class AuditBlockService extends AbstractBlockService |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var AuditReader |
30
|
|
|
*/ |
31
|
|
|
protected $auditReader; |
32
|
|
|
|
33
|
|
|
public function __construct(Environment $twig, AuditReader $auditReader) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($twig); |
36
|
|
|
|
37
|
|
|
$this->auditReader = $auditReader; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response |
41
|
|
|
{ |
42
|
|
|
$revisions = []; |
43
|
|
|
|
44
|
|
|
foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) { |
45
|
|
|
$revisions[] = [ |
46
|
|
|
'revision' => $revision, |
47
|
|
|
'entities' => $this->auditReader->findEntitiesChangedAtRevision($revision->getRev()), |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->renderResponse($blockContext->getTemplate(), [ |
52
|
|
|
'block' => $blockContext->getBlock(), |
53
|
|
|
'settings' => $blockContext->getSettings(), |
54
|
|
|
'revisions' => $revisions, |
55
|
|
|
], $response); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
59
|
|
|
{ |
60
|
|
|
$resolver->setDefaults([ |
61
|
|
|
'limit' => 10, |
62
|
|
|
'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig', |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|