summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/Base.php6
-rw-r--r--app/Controller/Hourlyrate.php89
-rw-r--r--app/Controller/Subtask.php20
-rw-r--r--app/Controller/Timetable.php39
-rw-r--r--app/Controller/Timetableday.php88
-rw-r--r--app/Controller/Timetableextra.php16
-rw-r--r--app/Controller/Timetableoff.php107
-rw-r--r--app/Controller/Timetableweek.php99
-rw-r--r--app/Controller/User.php8
9 files changed, 467 insertions, 5 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index d949048d..ec202c06 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -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
@@ -56,6 +57,11 @@ use Symfony\Component\EventDispatcher\Event;
* @property \Model\TaskPosition $taskPosition
* @property \Model\TaskPermission $taskPermission
* @property \Model\TaskStatus $taskStatus
+ * @property \Model\Timetable $timetable
+ * @property \Model\TimetableDay $timetableDay
+ * @property \Model\TimetableWeek $timetableWeek
+ * @property \Model\TimetableExtra $timetableExtra
+ * @property \Model\TimetableOff $timetableOff
* @property \Model\TaskValidator $taskValidator
* @property \Model\TaskLink $taskLink
* @property \Model\CommentHistory $commentHistory
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'])));
+ }
+}
diff --git a/app/Controller/Subtask.php b/app/Controller/Subtask.php
index c7ec00d1..385785a1 100644
--- a/app/Controller/Subtask.php
+++ b/app/Controller/Subtask.php
@@ -185,7 +185,7 @@ class Subtask extends Base
if ($redirect === 'board') {
$this->session['has_subtask_inprogress'] = $this->subtask->hasSubtaskInProgress($this->userSession->getId());
-
+
$this->response->html($this->template->render('board/subtasks', array(
'subtasks' => $this->subtask->getAll($task['id']),
'task' => $task,
@@ -259,4 +259,22 @@ class Subtask extends Base
$this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])));
}
}
+
+ /**
+ * Move subtask position
+ *
+ * @access public
+ */
+ public function movePosition()
+ {
+ $this->checkCSRFParam();
+ $project_id = $this->request->getIntegerParam('project_id');
+ $task_id = $this->request->getIntegerParam('task_id');
+ $subtask_id = $this->request->getIntegerParam('subtask_id');
+ $direction = $this->request->getStringParam('direction');
+ $method = $direction === 'up' ? 'moveUp' : 'moveDown';
+
+ $this->subtask->$method($task_id, $subtask_id);
+ $this->response->redirect($this->helper->url('task', 'show', array('project_id' => $project_id, 'task_id' => $task_id)).'#subtasks');
+ }
}
diff --git a/app/Controller/Timetable.php b/app/Controller/Timetable.php
new file mode 100644
index 00000000..65edb44c
--- /dev/null
+++ b/app/Controller/Timetable.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Controller;
+
+use DateTime;
+
+/**
+ * Timetable controller
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Timetable extends User
+{
+ /**
+ * Display timetable for the user
+ *
+ * @access public
+ */
+ public function index()
+ {
+ $user = $this->getUser();
+ $from = $this->request->getStringParam('from', date('Y-m-d'));
+ $to = $this->request->getStringParam('to', date('Y-m-d', strtotime('next week')));
+ $timetable = $this->timetable->calculate($user['id'], new DateTime($from), new DateTime($to));
+
+ $this->response->html($this->layout('timetable/index', array(
+ 'user' => $user,
+ 'timetable' => $timetable,
+ 'values' => array(
+ 'from' => $from,
+ 'to' => $to,
+ 'controller' => 'timetable',
+ 'action' => 'index',
+ 'user_id' => $user['id'],
+ ),
+ )));
+ }
+}
diff --git a/app/Controller/Timetableday.php b/app/Controller/Timetableday.php
new file mode 100644
index 00000000..eea44ae1
--- /dev/null
+++ b/app/Controller/Timetableday.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Controller;
+
+/**
+ * Day Timetable controller
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Timetableday extends User
+{
+ /**
+ * Display timetable for the user
+ *
+ * @access public
+ */
+ public function index(array $values = array(), array $errors = array())
+ {
+ $user = $this->getUser();
+
+ $this->response->html($this->layout('timetable_day/index', array(
+ 'timetable' => $this->timetableDay->getByUser($user['id']),
+ 'values' => $values + array('user_id' => $user['id']),
+ 'errors' => $errors,
+ 'user' => $user,
+ )));
+ }
+
+ /**
+ * Validate and save
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->timetableDay->validateCreation($values);
+
+ if ($valid) {
+
+ if ($this->timetableDay->create($values['user_id'], $values['start'], $values['end'])) {
+ $this->session->flash(t('Time slot created successfully.'));
+ $this->response->redirect($this->helper->url('timetableday', 'index', array('user_id' => $values['user_id'])));
+ }
+ else {
+ $this->session->flashError(t('Unable to save this time slot.'));
+ }
+ }
+
+ $this->index($values, $errors);
+ }
+
+ /**
+ * Confirmation dialag box to remove a row
+ *
+ * @access public
+ */
+ public function confirm()
+ {
+ $user = $this->getUser();
+
+ $this->response->html($this->layout('timetable_day/remove', array(
+ 'slot_id' => $this->request->getIntegerParam('slot_id'),
+ 'user' => $user,
+ )));
+ }
+
+ /**
+ * Remove a row
+ *
+ * @access public
+ */
+ public function remove()
+ {
+ $this->checkCSRFParam();
+ $user = $this->getUser();
+
+ if ($this->timetableDay->remove($this->request->getIntegerParam('slot_id'))) {
+ $this->session->flash(t('Time slot removed successfully.'));
+ }
+ else {
+ $this->session->flash(t('Unable to remove this time slot.'));
+ }
+
+ $this->response->redirect($this->helper->url('timetableday', 'index', array('user_id' => $user['id'])));
+ }
+}
diff --git a/app/Controller/Timetableextra.php b/app/Controller/Timetableextra.php
new file mode 100644
index 00000000..c362bd1a
--- /dev/null
+++ b/app/Controller/Timetableextra.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Controller;
+
+/**
+ * Over-time Timetable controller
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Timetableextra extends TimetableOff
+{
+ protected $model = 'timetableExtra';
+ protected $controller_url = 'timetableextra';
+ protected $template_dir = 'timetable_extra';
+}
diff --git a/app/Controller/Timetableoff.php b/app/Controller/Timetableoff.php
new file mode 100644
index 00000000..19a6fab1
--- /dev/null
+++ b/app/Controller/Timetableoff.php
@@ -0,0 +1,107 @@
+<?php
+
+namespace Controller;
+
+/**
+ * Time-off Timetable controller
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Timetableoff extends User
+{
+ protected $model = 'timetableOff';
+ protected $controller_url = 'timetableoff';
+ protected $template_dir = 'timetable_off';
+
+ /**
+ * Display timetable for the user
+ *
+ * @access public
+ */
+ public function index(array $values = array(), array $errors = array())
+ {
+ $user = $this->getUser();
+
+ $paginator = $this->paginator
+ ->setUrl($this->controller_url, 'index', array('user_id' => $user['id']))
+ ->setMax(10)
+ ->setOrder('date')
+ ->setDirection('desc')
+ ->setQuery($this->{$this->model}->getUserQuery($user['id']))
+ ->calculate();
+
+ $this->response->html($this->layout($this->template_dir.'/index', array(
+ 'values' => $values + array('user_id' => $user['id']),
+ 'errors' => $errors,
+ 'paginator' => $paginator,
+ 'user' => $user,
+ )));
+ }
+
+ /**
+ * Validate and save
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->{$this->model}->validateCreation($values);
+
+ if ($valid) {
+
+ if ($this->{$this->model}->create(
+ $values['user_id'],
+ $values['date'],
+ isset($values['all_day']) && $values['all_day'] == 1,
+ $values['start'],
+ $values['end'],
+ $values['comment'])) {
+
+ $this->session->flash(t('Time slot created successfully.'));
+ $this->response->redirect($this->helper->url($this->controller_url, 'index', array('user_id' => $values['user_id'])));
+ }
+ else {
+ $this->session->flashError(t('Unable to save this time slot.'));
+ }
+ }
+
+ $this->index($values, $errors);
+ }
+
+ /**
+ * Confirmation dialag box to remove a row
+ *
+ * @access public
+ */
+ public function confirm()
+ {
+ $user = $this->getUser();
+
+ $this->response->html($this->layout($this->template_dir.'/remove', array(
+ 'slot_id' => $this->request->getIntegerParam('slot_id'),
+ 'user' => $user,
+ )));
+ }
+
+ /**
+ * Remove a row
+ *
+ * @access public
+ */
+ public function remove()
+ {
+ $this->checkCSRFParam();
+ $user = $this->getUser();
+
+ if ($this->{$this->model}->remove($this->request->getIntegerParam('slot_id'))) {
+ $this->session->flash(t('Time slot removed successfully.'));
+ }
+ else {
+ $this->session->flash(t('Unable to remove this time slot.'));
+ }
+
+ $this->response->redirect($this->helper->url($this->controller_url, 'index', array('user_id' => $user['id'])));
+ }
+}
diff --git a/app/Controller/Timetableweek.php b/app/Controller/Timetableweek.php
new file mode 100644
index 00000000..829f4402
--- /dev/null
+++ b/app/Controller/Timetableweek.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace Controller;
+
+/**
+ * Week Timetable controller
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Timetableweek extends User
+{
+ /**
+ * Display timetable for the user
+ *
+ * @access public
+ */
+ public function index(array $values = array(), array $errors = array())
+ {
+ $user = $this->getUser();
+
+ if (empty($values)) {
+
+ $day = $this->timetableDay->getByUser($user['id']);
+
+ $values = array(
+ 'user_id' => $user['id'],
+ 'start' => isset($day[0]['start']) ? $day[0]['start'] : null,
+ 'end' => isset($day[0]['end']) ? $day[0]['end'] : null,
+ );
+ }
+
+ $this->response->html($this->layout('timetable_week/index', array(
+ 'timetable' => $this->timetableWeek->getByUser($user['id']),
+ 'values' => $values,
+ 'errors' => $errors,
+ 'user' => $user,
+ )));
+ }
+
+ /**
+ * Validate and save
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->timetableWeek->validateCreation($values);
+
+ if ($valid) {
+
+ if ($this->timetableWeek->create($values['user_id'], $values['day'], $values['start'], $values['end'])) {
+ $this->session->flash(t('Time slot created successfully.'));
+ $this->response->redirect($this->helper->url('timetableweek', 'index', array('user_id' => $values['user_id'])));
+ }
+ else {
+ $this->session->flashError(t('Unable to save this time slot.'));
+ }
+ }
+
+ $this->index($values, $errors);
+ }
+
+ /**
+ * Confirmation dialag box to remove a row
+ *
+ * @access public
+ */
+ public function confirm()
+ {
+ $user = $this->getUser();
+
+ $this->response->html($this->layout('timetable_week/remove', array(
+ 'slot_id' => $this->request->getIntegerParam('slot_id'),
+ 'user' => $user,
+ )));
+ }
+
+ /**
+ * Remove a row
+ *
+ * @access public
+ */
+ public function remove()
+ {
+ $this->checkCSRFParam();
+ $user = $this->getUser();
+
+ if ($this->timetableWeek->remove($this->request->getIntegerParam('slot_id'))) {
+ $this->session->flash(t('Time slot removed successfully.'));
+ }
+ else {
+ $this->session->flash(t('Unable to remove this time slot.'));
+ }
+
+ $this->response->redirect($this->helper->url('timetableweek', 'index', array('user_id' => $user['id'])));
+ }
+}
diff --git a/app/Controller/User.php b/app/Controller/User.php
index decdb646..46d0214d 100644
--- a/app/Controller/User.php
+++ b/app/Controller/User.php
@@ -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'));