Completed
Push — 2.x ( 359f6e )
by Sullivan
14:45
created

AuditBlockService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 72
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 17 2
A validateBlock() 0 4 1
A buildEditForm() 0 4 1
A getName() 0 4 1
A setDefaultSettings() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata project.
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 Sonata\BlockBundle\Block\BlockContextInterface;
15
use Symfony\Component\HttpFoundation\Response;
16
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
17
18
use Sonata\AdminBundle\Form\FormMapper;
19
use Sonata\AdminBundle\Validator\ErrorElement;
20
21
use Sonata\BlockBundle\Model\BlockInterface;
22
use Sonata\BlockBundle\Block\BaseBlockService;
23
24
use SimpleThings\EntityAudit\AuditReader;
25
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
26
27
/**
28
 *
29
 * @author     Thomas Rabaix <[email protected]>
30
 */
31
class AuditBlockService extends BaseBlockService
32
{
33
    protected $auditReader;
34
35
    /**
36
     * @param string                                                     $name
37
     * @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
38
     * @param \SimpleThings\EntityAudit\AuditReader                      $auditReader
39
     */
40
    public function __construct($name, EngineInterface $templating, AuditReader $auditReader)
41
    {
42
        parent::__construct($name, $templating);
43
44
        $this->auditReader = $auditReader;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function execute(BlockContextInterface $blockContext, Response $response = null)
51
    {
52
        $revisions = array();
53
54
        foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) {
55
            $revisions[] = array(
56
                'revision' => $revision,
57
                '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...
58
            );
59
        }
60
61
        return $this->renderResponse($blockContext->getTemplate(), array(
62
            'block'     => $blockContext->getBlock(),
63
            'settings'  => $blockContext->getSettings(),
64
            'revisions' => $revisions,
65
        ), $response);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
72
    {
73
        // TODO: Implement validateBlock() method.
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
80
    {
81
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function getName()
88
    {
89
        return 'Audit List';
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function setDefaultSettings(OptionsResolverInterface $resolver)
96
    {
97
        $resolver->setDefaults(array(
98
            'limit'    => 10,
99
            'template' => 'SonataDoctrineORMAdminBundle:Block:block_audit.html.twig'
100
        ));
101
    }
102
}
103