|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kunstmaan\TranslatorBundle\Toolbar; |
|
4
|
|
|
|
|
5
|
|
|
use Kunstmaan\AdminBundle\Helper\Toolbar\AbstractDataCollector; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
8
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
9
|
|
|
|
|
10
|
|
|
class TranslatorDataCollector extends AbstractDataCollector |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var DataCollectorTranslator |
|
14
|
|
|
*/ |
|
15
|
|
|
private $translator; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var UrlGeneratorInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
private $urlGenerator; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* TranslatorDataCollector constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param DataCollectorTranslator $translator |
|
26
|
|
|
* @param UrlGeneratorInterface $urlGenerator |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(DataCollectorTranslator $translator, UrlGeneratorInterface $urlGenerator) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->translator = $translator; |
|
31
|
|
|
$this->urlGenerator = $urlGenerator; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return array |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
|
|
public function getAccessRoles() |
|
38
|
|
|
{ |
|
39
|
|
|
return ['ROLE_ADMIN']; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return array |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
public function collectData() |
|
46
|
|
|
{ |
|
47
|
|
|
$route = $this->urlGenerator->generate('KunstmaanTranslatorBundle_settings_translations'); |
|
48
|
|
|
|
|
49
|
|
|
$options = [ |
|
50
|
|
|
'filter_columnname' => [ |
|
51
|
|
|
'keyword' |
|
52
|
|
|
], |
|
53
|
|
|
'filter_uniquefilterid' => [ |
|
54
|
|
|
1 |
|
55
|
|
|
], |
|
56
|
|
|
'filter_comparator_1' => 'equals', |
|
57
|
|
|
'filter' => 'filter', |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
$translations = []; |
|
61
|
|
|
|
|
62
|
|
|
foreach ($this->translator->getCollectedMessages() as $message) { |
|
63
|
|
|
if ($message['state'] !== DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK && !empty($message['id'])) { |
|
64
|
|
|
$options['filter_value_1'] = $message['id']; |
|
65
|
|
|
$translations[$message['id']] = [ |
|
66
|
|
|
'id' => $message['id'], |
|
67
|
|
|
'message' => $message['translation'], |
|
68
|
|
|
'route' => $this->urlGenerator->generate('KunstmaanTranslatorBundle_settings_translations', $options) |
|
69
|
|
|
]; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$data = [ |
|
74
|
|
|
'route' => $route, |
|
75
|
|
|
'translations' => $translations |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
return ['data' => $data]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param Request $request |
|
83
|
|
|
* @param Response $response |
|
84
|
|
|
* @param \Exception|null $exception |
|
85
|
|
|
*/ |
|
86
|
|
View Code Duplication |
public function collect(Request $request, Response $response, \Exception $exception = null) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
if (!$this->showDataCollection($request, $response) || !$this->isEnabled()) { |
|
89
|
|
|
$this->data = false; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
else { |
|
92
|
|
|
$this->data = $this->collectData(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Gets the data for template |
|
98
|
|
|
* |
|
99
|
|
|
* @return array The request events |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getTemplateData() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->data; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getName() |
|
110
|
|
|
{ |
|
111
|
|
|
return 'kuma_translation'; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return bool |
|
116
|
|
|
*/ |
|
117
|
|
|
public function isEnabled() |
|
118
|
|
|
{ |
|
119
|
|
|
return true; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function reset() |
|
123
|
|
|
{ |
|
124
|
|
|
$this->data = []; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.