Completed
Pull Request — 3.x (#1023)
by Wojciech
09:41
created

AuditBlock4Service::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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