Completed
Pull Request — 3.x (#1023)
by Wojciech
01:44
created

AuditBlock4Service::configureSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\AdminBundle\Form\FormMapper;
18
use Sonata\BlockBundle\Block\BlockContextInterface;
19
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
20
use Sonata\BlockBundle\Model\BlockInterface;
21
use Sonata\ClassificationBundle\Model\ContextManagerInterface;
22
use Symfony\Component\HttpFoundation\Response;
23
use Symfony\Component\OptionsResolver\OptionsResolver;
24
use Twig\Environment;
25
26
/**
27
 * @author Thomas Rabaix <[email protected]>
28
 */
29
final class AuditBlock4Service extends AbstractBlockService
30
{
31
    /**
32
     * @var AuditReader
33
     */
34
    protected $auditReader;
35
36
    public function __construct(Environment $environment, AuditReader $auditReader)
37
    {
38
        parent::__construct($environment);
39
40
        $this->auditReader = $auditReader;
41
    }
42
43
    public function execute(BlockContextInterface $blockContext, Response $response = null): Response
44
    {
45
        $revisions = [];
46
47
        foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) {
48
            $revisions[] = [
49
                'revision' => $revision,
50
                'entities' => $this->auditReader->findEntitiesChangedAtRevision($revision->getRev()),
51
            ];
52
        }
53
54
        return $this->renderResponse($blockContext->getTemplate(), [
55
            'block' => $blockContext->getBlock(),
56
            'settings' => $blockContext->getSettings(),
57
            'revisions' => $revisions,
58
        ], $response);
59
    }
60
61
    public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
0 ignored issues
show
Unused Code introduced by
The parameter $formMapper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $block is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
    }
64
65
    public function getName()
66
    {
67
        return 'Audit List';
68
    }
69
70
    public function configureSettings(OptionsResolver $resolver): void
71
    {
72
        $resolver->setDefaults([
73
            'limit' => 10,
74
            'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
75
        ]);
76
    }
77
}
78