Add user cost
This commit is contained in:
@@ -34,6 +34,7 @@ use Symfony\Component\EventDispatcher\Event;
|
||||
* @property \Model\Config $config
|
||||
* @property \Model\DateParser $dateParser
|
||||
* @property \Model\File $file
|
||||
* @property \Model\HourlyRate $hourlyRate
|
||||
* @property \Model\LastLogin $lastLogin
|
||||
* @property \Model\Notification $notification
|
||||
* @property \Model\Project $project
|
||||
|
||||
89
app/Controller/HourlyRate.php
Normal file
89
app/Controller/HourlyRate.php
Normal file
@@ -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'])));
|
||||
}
|
||||
}
|
||||
@@ -69,12 +69,12 @@ class User extends Base
|
||||
/**
|
||||
* Common layout for user views
|
||||
*
|
||||
* @access private
|
||||
* @access protected
|
||||
* @param string $template Template name
|
||||
* @param array $params Template parameters
|
||||
* @return string
|
||||
*/
|
||||
private function layout($template, array $params)
|
||||
protected function layout($template, array $params)
|
||||
{
|
||||
$content = $this->template->render($template, $params);
|
||||
$params['user_content_for_layout'] = $content;
|
||||
@@ -90,10 +90,10 @@ class User extends Base
|
||||
/**
|
||||
* Common method to get the user
|
||||
*
|
||||
* @access private
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
private function getUser()
|
||||
protected function getUser()
|
||||
{
|
||||
$user = $this->user->getById($this->request->getIntegerParam('user_id'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user