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()), |
|
|
|
|
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
|
|
|
|
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.