1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[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 ONGR\TranslationsBundle\Controller; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Result\Result; |
15
|
|
|
use ONGR\ElasticsearchBundle\Service\Repository; |
16
|
|
|
use ONGR\FilterManagerBundle\Filter\ViewData; |
17
|
|
|
use ONGR\FilterManagerBundle\Search\SearchResponse; |
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Controller used for displaying translations. |
24
|
|
|
*/ |
25
|
|
|
class ListController extends Controller |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var Repository |
29
|
|
|
*/ |
30
|
|
|
private $repository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Injects elasticsearch repository for listing actions. |
34
|
|
|
* |
35
|
|
|
* @param Repository $repository Elasticsearch repository. |
36
|
|
|
*/ |
37
|
|
|
public function __construct(Repository $repository) |
38
|
|
|
{ |
39
|
|
|
$this->repository = $repository; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Renders view with filter manager response. |
44
|
|
|
* |
45
|
|
|
* @param Request $request Request. |
46
|
|
|
* |
47
|
|
|
* @return Response |
48
|
|
|
*/ |
49
|
|
|
public function listAction(Request $request) |
50
|
|
|
{ |
51
|
|
|
/** @var SearchResponse $fmr */ |
52
|
|
|
$fmr = $this->get('ongr_translations.filter_manager')->handleRequest($request); |
53
|
|
|
return $this->render( |
54
|
|
|
'ONGRTranslationsBundle:List:list.html.twig', |
55
|
|
|
[ |
56
|
|
|
'data' => iterator_to_array($fmr->getResult()), |
57
|
|
|
'locales' => $this->buildLocalesList($fmr->getFilters()['locale']), |
|
|
|
|
58
|
|
|
'filters_manager' => $fmr, |
59
|
|
|
] |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Creates locales list. |
65
|
|
|
* |
66
|
|
|
* @param ViewData\ChoicesAwareViewData $filter |
67
|
|
|
* |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
|
private function buildLocalesList($filter) |
71
|
|
|
{ |
72
|
|
|
$list = []; |
73
|
|
|
|
74
|
|
|
foreach ($this->getParameter('ongr_translations.managed_locales') as $value) { |
75
|
|
|
$list[$value] = true; |
76
|
|
|
} |
77
|
|
|
ksort($list); |
78
|
|
|
$activeLocales = []; |
79
|
|
|
|
80
|
|
|
if ($filter->getState()->isActive()) { |
81
|
|
|
foreach ($filter->getChoices() as $choice) { |
82
|
|
|
$activeLocales[$choice->getLabel()] = $choice->isActive(); |
83
|
|
|
} |
84
|
|
|
$list = array_merge($list, $activeLocales); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $list; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Renders out a page with all the info about a translation |
92
|
|
|
* |
93
|
|
|
* @param Request $request |
94
|
|
|
* @param String $translation |
95
|
|
|
* @param String $domain |
96
|
|
|
* |
97
|
|
|
* @return Response |
98
|
|
|
*/ |
99
|
|
|
public function translationAction(Request $request, $translation, $domain) |
100
|
|
|
{ |
101
|
|
|
$cache = $this->get('es.cache_engine'); |
102
|
|
|
$params = []; |
103
|
|
|
if ($cache->contains('translations_edit')) { |
104
|
|
|
$params = $cache->fetch('translations_edit'); |
105
|
|
|
$cache->delete('translations_edit'); |
106
|
|
|
} |
107
|
|
|
$fmr = $this->get('ongr_translations.filter_manager')->handleRequest($request); |
108
|
|
|
$translation = $this->repository->findOneBy(['key' => $translation, 'domain' => $domain]); |
109
|
|
|
$params['translation'] = $translation; |
110
|
|
|
$params['locales'] = $this->buildLocalesList($fmr->getFilters()['locale']); |
111
|
|
|
|
112
|
|
|
return $this->render( |
113
|
|
|
'ONGRTranslationsBundle:List:translation.html.twig', |
114
|
|
|
$params |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.