|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use RunOpenCode\Bundle\ExchangeRate\Form\Type\NewType; |
|
6
|
|
|
use RunOpenCode\ExchangeRate\Contract\RepositoryInterface; |
|
7
|
|
|
use RunOpenCode\Bundle\ExchangeRate\Model\Rate; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
|
|
11
|
|
|
class ExchangeRateController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
protected $repository; |
|
14
|
|
|
|
|
15
|
|
|
protected $baseCurrency; |
|
16
|
|
|
|
|
17
|
|
|
protected $settings; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(RepositoryInterface $repository, $baseCurrency, $settings) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->repository = $repository; |
|
22
|
|
|
$this->baseCurrency = $baseCurrency; |
|
23
|
|
|
$this->settings = $settings; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function indexAction() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->render($this->settings['list'], array( |
|
29
|
|
|
'base_template' => $this->settings['base_template'], |
|
30
|
|
|
'rates' => $this->repository->all(), |
|
31
|
|
|
'date_format' => $this->settings['date_format'], |
|
32
|
|
|
'date_time_format' => $this->settings['date_time_format'] |
|
33
|
|
|
)); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function newAction(Request $request) |
|
37
|
|
|
{ |
|
38
|
|
|
$form = $this->createForm(NewType::class, $this->getNewRate()); |
|
39
|
|
|
|
|
40
|
|
|
$form->handleRequest($request); |
|
41
|
|
|
|
|
42
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
43
|
|
|
|
|
44
|
|
|
$this->repository->save(array( |
|
45
|
|
|
$form->getData() |
|
46
|
|
|
)); |
|
47
|
|
|
|
|
48
|
|
|
$this->get('session')->getFlashBag()->add('success', 'run_open_code.exchange_rate.flash.new.success'); |
|
49
|
|
|
$this->redirectToRoute('roc_exchange_rate_list'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $this->render($this->settings['new'], array( |
|
53
|
|
|
'base_template' => $this->settings['base_template'], |
|
54
|
|
|
'form' => $form->createView() |
|
55
|
|
|
)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function getNewRate() |
|
59
|
|
|
{ |
|
60
|
|
|
$rate = new Rate(null, null, $this->baseCurrency, null, null, $this->baseCurrency, null, null); |
|
61
|
|
|
$rate->setBaseCurrencyCode($this->baseCurrency); |
|
62
|
|
|
|
|
63
|
|
|
return $rate; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|