1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\Controller; |
4
|
|
|
|
5
|
|
|
use RunOpenCode\Bundle\ExchangeRate\Form\FilterType; |
6
|
|
|
use RunOpenCode\Bundle\ExchangeRate\Security\AccessVoter; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8
|
|
|
use Symfony\Component\Form\Form; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ListController |
13
|
|
|
* |
14
|
|
|
* @package RunOpenCode\Bundle\ExchangeRate\Controller |
15
|
|
|
*/ |
16
|
|
|
class ListController extends Controller |
17
|
|
|
{ |
18
|
|
|
public function indexAction(Request $request) |
19
|
|
|
{ |
20
|
|
|
if (!$this->isGranted(AccessVoter::VIEW)) { |
21
|
|
|
throw $this->createAccessDeniedException(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$filterForm = $this->getFilterForm($request); |
25
|
|
|
|
26
|
|
|
return $this->render('@ExchangeRate/list.html.twig', [ |
27
|
|
|
'rates' => $this->getRates($filterForm), |
28
|
|
|
'form' => $filterForm->createView(), |
29
|
|
|
]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get rates for list view. Process filters if submitted. |
34
|
|
|
* |
35
|
|
|
* @param Form $filterForm |
36
|
|
|
* |
37
|
|
|
* @return \RunOpenCode\ExchangeRate\Contract\RateInterface[] |
38
|
|
|
*/ |
39
|
|
|
protected function getRates(Form $filterForm) |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var \RunOpenCode\ExchangeRate\Contract\RepositoryInterface $repository |
43
|
|
|
*/ |
44
|
|
|
$repository = $this->get('runopencode.exchange_rate.repository'); |
45
|
|
|
|
46
|
|
|
if ($filterForm->isSubmitted() && $filterForm->isValid()) { |
47
|
|
|
return $repository->all($filterForm->getData()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $repository->all(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get filter form |
55
|
|
|
* |
56
|
|
|
* @param Request $request |
57
|
|
|
* |
58
|
|
|
* @return Form |
59
|
|
|
*/ |
60
|
|
|
protected function getFilterForm(Request $request) |
61
|
|
|
{ |
62
|
|
|
$filter = $this->createForm($this->getFilterFormType()); |
63
|
|
|
|
64
|
|
|
$filter->handleRequest($request); |
65
|
|
|
|
66
|
|
|
return $filter; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get FQCN of FilterType form. |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
protected function getFilterFormType() |
75
|
|
|
{ |
76
|
|
|
return FilterType::class; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|