diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-03-28 18:00:18 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-03-28 18:00:18 -0400 |
commit | 9bfab51e00608b6e008aa71f6df74104b28fc662 (patch) | |
tree | c390346c8ed384c78bf85bbdd950d70bd9a9ab51 /app/Controller | |
parent | eb6853c163e9059bbbc89a1a741d4a25c8e04153 (diff) |
Add currency rates for budget calculation
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/Currency.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/app/Controller/Currency.php b/app/Controller/Currency.php new file mode 100644 index 00000000..fac34a30 --- /dev/null +++ b/app/Controller/Currency.php @@ -0,0 +1,89 @@ +<?php + +namespace Controller; + +/** + * Currency controller + * + * @package controller + * @author Frederic Guillot + */ +class Currency extends Base +{ + /** + * Common layout for config views + * + * @access private + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + private function layout($template, array $params) + { + $params['board_selector'] = $this->projectPermission->getAllowedProjects($this->userSession->getId()); + $params['config_content_for_layout'] = $this->template->render($template, $params); + + return $this->template->layout('config/layout', $params); + } + + /** + * Display all currency rates and form + * + * @access public + */ + public function index(array $values = array(), array $errors = array()) + { + $this->response->html($this->layout('currency/index', array( + 'config_values' => array('application_currency' => $this->config->get('application_currency')), + 'values' => $values, + 'errors' => $errors, + 'rates' => $this->currency->getAll(), + 'currencies' => $this->config->getCurrencies(), + 'title' => t('Settings').' > '.t('Currency rates'), + ))); + } + + /** + * Validate and save a new currency rate + * + * @access public + */ + public function create() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->currency->validate($values); + + if ($valid) { + + if ($this->currency->create($values['currency'], $values['rate'])) { + $this->session->flash(t('The currency rate have been added successfully.')); + $this->response->redirect($this->helper->url('currency', 'index')); + } + else { + $this->session->flashError(t('Unable to add this currency rate.')); + } + } + + $this->index($values, $errors); + } + + /** + * Save reference currency + * + * @access public + */ + public function reference() + { + $values = $this->request->getValues(); + + if ($this->config->save($values)) { + $this->config->reload(); + $this->session->flash(t('Settings saved successfully.')); + } + else { + $this->session->flashError(t('Unable to save your settings.')); + } + + $this->response->redirect($this->helper->url('currency', 'index')); + } +} |