Completed
Push — 3.x-dev-kit ( 4fe8f1 )
by
unknown
11:30 queued 08:33
created

AuditBlockService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrineORMAdminBundle\Block;
13
14
use SimpleThings\EntityAudit\AuditReader;
15
use Sonata\AdminBundle\Form\FormMapper;
16
use Sonata\BlockBundle\Block\BaseBlockService;
17
use Sonata\BlockBundle\Block\BlockContextInterface;
18
use Sonata\BlockBundle\Model\BlockInterface;
19
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\OptionsResolver\OptionsResolver;
22
23
/**
24
 * @author     Thomas Rabaix <[email protected]>
25
 */
26
class AuditBlockService extends BaseBlockService
27
{
28
    /**
29
     * @var AuditReader
30
     */
31
    protected $auditReader;
32
33
    /**
34
     * @param string          $name
35
     * @param EngineInterface $templating
36
     * @param AuditReader     $auditReader
37
     */
38
    public function __construct($name, EngineInterface $templating, AuditReader $auditReader)
39
    {
40
        parent::__construct($name, $templating);
41
42
        $this->auditReader = $auditReader;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function execute(BlockContextInterface $blockContext, Response $response = null)
49
    {
50
        $revisions = array();
51
52
        foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) {
53
            $revisions[] = array(
54
                'revision' => $revision,
55
                'entities' => $this->auditReader->findEntitesChangedAtRevision($revision->getRev()),
0 ignored issues
show
Deprecated Code introduced by
The method SimpleThings\EntityAudit...itesChangedAtRevision() has been deprecated with message: this function name is misspelled.
Suggest using findEntitiesChangedAtRevision instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
56
            );
57
        }
58
59
        return $this->renderResponse($blockContext->getTemplate(), array(
60
            'block' => $blockContext->getBlock(),
61
            'settings' => $blockContext->getSettings(),
62
            'revisions' => $revisions,
63
        ), $response);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
70
    {
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getName()
77
    {
78
        return 'Audit List';
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function configureSettings(OptionsResolver $resolver)
85
    {
86
        $resolver->setDefaults(array(
87
            'limit' => 10,
88
            'template' => 'SonataDoctrineORMAdminBundle:Block:block_audit.html.twig',
89
        ));
90
    }
91
}
92