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\ElasticsearchDSL\Aggregation\TermsAggregation; |
16
|
|
|
use ONGR\ElasticsearchBundle\Service\Repository; |
17
|
|
|
use ONGR\FilterManagerBundle\Filter\ViewData; |
18
|
|
|
use ONGR\FilterManagerBundle\Search\SearchResponse; |
19
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Controller used for displaying translations. |
25
|
|
|
*/ |
26
|
|
|
class ListController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var Repository |
30
|
|
|
*/ |
31
|
|
|
private $repository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Injects elasticsearch repository for listing actions. |
35
|
|
|
* |
36
|
|
|
* @param Repository $repository Elasticsearch repository. |
37
|
|
|
*/ |
38
|
|
|
public function __construct(Repository $repository) |
39
|
|
|
{ |
40
|
|
|
$this->repository = $repository; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Renders view with filter manager response. |
45
|
|
|
* |
46
|
|
|
* @param Request $request Request. |
47
|
|
|
* |
48
|
|
|
* @return Response |
49
|
|
|
*/ |
50
|
|
|
public function listAction(Request $request) |
51
|
|
|
{ |
52
|
|
|
/** @var SearchResponse $fmr */ |
53
|
|
|
$fmr = $this->get('ongr_translations.filter_manager')->handleRequest($request); |
54
|
|
|
|
55
|
|
|
return $this->render( |
56
|
|
|
'ONGRTranslationsBundle:List:list.html.twig', |
57
|
|
|
[ |
58
|
|
|
'data' => iterator_to_array($fmr->getResult()), |
59
|
|
|
'locales' => $this->buildLocalesList($fmr->getFilters()['locale']), |
|
|
|
|
60
|
|
|
'filters_manager' => $fmr, |
61
|
|
|
] |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Creates locales list. |
67
|
|
|
* |
68
|
|
|
* @param ViewData\ChoicesAwareViewData $filter |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
private function buildLocalesList($filter) |
73
|
|
|
{ |
74
|
|
|
$locales = $this->container->getParameter('ongr_translations.managed_locales'); |
75
|
|
|
$list = []; |
76
|
|
|
foreach ($locales as $locale) { |
77
|
|
|
$list[$locale] = true; |
78
|
|
|
} |
79
|
|
|
ksort($list); |
80
|
|
|
$activeLocales = []; |
81
|
|
|
|
82
|
|
|
if ($filter->getState()->isActive()) { |
83
|
|
|
foreach ($filter->getChoices() as $choice) { |
84
|
|
|
$activeLocales[$choice->getLabel()] = $choice->isActive(); |
85
|
|
|
} |
86
|
|
|
$list = array_merge($list, $activeLocales); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $list; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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.