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

AuditBlock4Service::buildEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 Symfony\Component\HttpFoundation\Response;
22
use Symfony\Component\OptionsResolver\OptionsResolver;
23
use Twig\Environment;
24
25
/**
26
 * @author Thomas Rabaix <[email protected]>
27
 */
28
final class AuditBlock4Service extends AbstractBlockService
29
{
30
    /**
31
     * @var AuditReader
32
     */
33
    protected $auditReader;
34
35
    public function __construct(Environment $environment, AuditReader $auditReader)
36
    {
37
        parent::__construct($environment);
38
39
        $this->auditReader = $auditReader;
40
    }
41
42
    public function execute(BlockContextInterface $blockContext, Response $response = null): Response
43
    {
44
        $revisions = [];
45
46
        foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) {
47
            $revisions[] = [
48
                'revision' => $revision,
49
                'entities' => $this->auditReader->findEntitiesChangedAtRevision($revision->getRev()),
50
            ];
51
        }
52
53
        return $this->renderResponse($blockContext->getTemplate(), [
54
            'block' => $blockContext->getBlock(),
55
            'settings' => $blockContext->getSettings(),
56
            'revisions' => $revisions,
57
        ], $response);
58
    }
59
60
    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...
61
    {
62
    }
63
64
    public function getName()
65
    {
66
        return 'Audit List';
67
    }
68
69
    public function configureSettings(OptionsResolver $resolver): void
70
    {
71
        $resolver->setDefaults([
72
            'limit' => 10,
73
            'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
74
        ]);
75
    }
76
}
77