1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
<?php
namespace Kanboard\Controller;
/**
* Currency Controller
*
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class CurrencyController extends BaseController
{
/**
* Display all currency rates
*
* @access public
*/
public function show()
{
$this->response->html($this->helper->layout->config('currency/show', array(
'application_currency' => $this->configModel->get('application_currency'),
'rates' => $this->currencyModel->getAll(),
'currencies' => $this->currencyModel->getCurrencies(),
'title' => t('Settings') . ' > ' . t('Currency rates'),
)));
}
/**
* Add or change currency rate
*
* @access public
* @param array $values
* @param array $errors
*/
public function create(array $values = array(), array $errors = array())
{
$this->response->html($this->template->render('currency/create', array(
'values' => $values,
'errors' => $errors,
'currencies' => $this->currencyModel->getCurrencies(),
)));
}
/**
* Validate and save a new currency rate
*
* @access public
*/
public function save()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->currencyValidator->validateCreation($values);
if ($valid) {
if ($this->currencyModel->create($values['currency'], $values['rate'])) {
$this->flash->success(t('The currency rate have been added successfully.'));
$this->response->redirect($this->helper->url->to('CurrencyController', 'show'), true);
return;
} else {
$this->flash->failure(t('Unable to add this currency rate.'));
}
}
$this->create($values, $errors);
}
/**
* Change reference currency
*
* @access public
* @param array $values
* @param array $errors
*/
public function change(array $values = array(), array $errors = array())
{
if (empty($values)) {
$values['application_currency'] = $this->configModel->get('application_currency');
}
$this->response->html($this->template->render('currency/change', array(
'values' => $values,
'errors' => $errors,
'currencies' => $this->currencyModel->getCurrencies(),
)));
}
/**
* Save reference currency
*
* @access public
*/
public function update()
{
$values = $this->request->getValues();
if ($this->configModel->save($values)) {
$this->flash->success(t('Settings saved successfully.'));
} else {
$this->flash->failure(t('Unable to save your settings.'));
}
$this->response->redirect($this->helper->url->to('CurrencyController', 'show'), true);
}
}
|