diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-03-09 21:38:50 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-03-09 21:38:50 -0400 |
commit | 762fdb9f40fa982a5606cbe01f7a3455d3680caf (patch) | |
tree | ba0956957ad1c5df9d9b0eb0744df8ef3ead0fc6 /app/Controller/Hourlyrate.php | |
parent | c870508923f62e90a81fe39d923d7776dd1e9634 (diff) |
Lowercase filename
Diffstat (limited to 'app/Controller/Hourlyrate.php')
-rw-r--r-- | app/Controller/Hourlyrate.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/app/Controller/Hourlyrate.php b/app/Controller/Hourlyrate.php new file mode 100644 index 00000000..8d96e5ca --- /dev/null +++ b/app/Controller/Hourlyrate.php @@ -0,0 +1,89 @@ +<?php + +namespace Controller; + +/** + * Hourly Rate controller + * + * @package controller + * @author Frederic Guillot + */ +class Hourlyrate extends User +{ + /** + * Display rate and form + * + * @access public + */ + public function index(array $values = array(), array $errors = array()) + { + $user = $this->getUser(); + + $this->response->html($this->layout('hourlyrate/index', array( + 'rates' => $this->hourlyRate->getAllByUser($user['id']), + 'currencies_list' => $this->config->getCurrencies(), + 'values' => $values + array('user_id' => $user['id']), + 'errors' => $errors, + 'user' => $user, + ))); + } + + /** + * Validate and save a new rate + * + * @access public + */ + public function save() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->hourlyRate->validateCreation($values); + + if ($valid) { + + if ($this->hourlyRate->create($values['user_id'], $values['rate'], $values['currency'], $values['date_effective'])) { + $this->session->flash(t('Hourly rate created successfully.')); + $this->response->redirect($this->helper->url('hourlyrate', 'index', array('user_id' => $values['user_id']))); + } + else { + $this->session->flashError(t('Unable to save the hourly rate.')); + } + } + + $this->index($values, $errors); + } + + /** + * Confirmation dialag box to remove a row + * + * @access public + */ + public function confirm() + { + $user = $this->getUser(); + + $this->response->html($this->layout('hourlyrate/remove', array( + 'rate_id' => $this->request->getIntegerParam('rate_id'), + 'user' => $user, + ))); + } + + /** + * Remove a row + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $user = $this->getUser(); + + if ($this->hourlyRate->remove($this->request->getIntegerParam('rate_id'))) { + $this->session->flash(t('Rate removed successfully.')); + } + else { + $this->session->flash(t('Unable to remove this rate.')); + } + + $this->response->redirect($this->helper->url('hourlyrate', 'index', array('user_id' => $user['id']))); + } +} |