From 9ebbe3da56914c408327997cea4eb00db2f88e0c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 26 May 2016 21:38:43 -0400 Subject: Rename task controllers --- app/Controller/TaskStatusController.php | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 app/Controller/TaskStatusController.php (limited to 'app/Controller/TaskStatusController.php') diff --git a/app/Controller/TaskStatusController.php b/app/Controller/TaskStatusController.php new file mode 100644 index 00000000..fca168ec --- /dev/null +++ b/app/Controller/TaskStatusController.php @@ -0,0 +1,62 @@ +changeStatus('close', 'task_status/close', t('Task closed successfully.'), t('Unable to close this task.')); + } + + /** + * Open a task + * + * @access public + */ + public function open() + { + $this->changeStatus('open', 'task_status/open', t('Task opened successfully.'), t('Unable to open this task.')); + } + + /** + * Common method to change status + * + * @access private + * @param string $method + * @param string $template + * @param string $success_message + * @param string $failure_message + */ + private function changeStatus($method, $template, $success_message, $failure_message) + { + $task = $this->getTask(); + + if ($this->request->getStringParam('confirmation') === 'yes') { + $this->checkCSRFParam(); + + if ($this->taskStatus->$method($task['id'])) { + $this->flash->success($success_message); + } else { + $this->flash->failure($failure_message); + } + + return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + return $this->response->html($this->template->render($template, array( + 'task' => $task, + ))); + } +} -- cgit v1.2.3