summaryrefslogtreecommitdiff
path: root/app/Controller/Tasklink.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-02-14 16:11:13 -0500
committerFrederic Guillot <fred@kanboard.net>2015-02-14 16:11:13 -0500
commitf7e4c3928aba9cb7f5222cb4af67846312bbb435 (patch)
tree78f5854a0bdc538c977bad718a11d605a4caaca6 /app/Controller/Tasklink.php
parent364382b1b58db8bf1bd2c8866e21c869a7a5d6d0 (diff)
Refactoring/simplification of the pull-request about links
Diffstat (limited to 'app/Controller/Tasklink.php')
-rw-r--r--app/Controller/Tasklink.php74
1 files changed, 15 insertions, 59 deletions
diff --git a/app/Controller/Tasklink.php b/app/Controller/Tasklink.php
index d76de8fe..61b7fab8 100644
--- a/app/Controller/Tasklink.php
+++ b/app/Controller/Tasklink.php
@@ -2,12 +2,12 @@
namespace Controller;
-use Model\Task AS TaskModel;
/**
* TaskLink controller
*
* @package controller
* @author Olivier Maridat
+ * @author Frederic Guillot
*/
class Tasklink extends Base
{
@@ -20,9 +20,11 @@ class Tasklink extends Base
private function getTaskLink()
{
$link = $this->taskLink->getById($this->request->getIntegerParam('link_id'));
+
if (! $link) {
$this->notfound();
}
+
return $link;
}
@@ -38,16 +40,15 @@ class Tasklink extends Base
if (empty($values)) {
$values = array(
'task_id' => $task['id'],
- 'another_link' => $this->request->getIntegerParam('another_link', 0)
);
}
- $this->response->html($this->taskLayout('tasklink/edit', array(
+ $this->response->html($this->taskLayout('tasklink/create', array(
'values' => $values,
'errors' => $errors,
- 'link_list' => $this->link->getLinkLabelList($task['project_id']),
- 'task_list' => $this->taskFinder->getList($task['project_id'], TaskModel::STATUS_OPEN, $task['id']),
'task' => $task,
+ 'labels' => $this->link->getList(0, false),
+ 'title' => t('Add a new link')
)));
}
@@ -60,19 +61,17 @@ class Tasklink extends Base
{
$task = $this->getTask();
$values = $this->request->getValues();
+
list($valid, $errors) = $this->taskLink->validateCreation($values);
if ($valid) {
- if ($this->taskLink->create($values)) {
+
+ if ($this->taskLink->create($values['task_id'], $values['opposite_task_id'], $values['link_id'])) {
$this->session->flash(t('Link added successfully.'));
- if (isset($values['another_link']) && $values['another_link'] == 1) {
- $this->response->redirect('?controller=tasklink&action=create&task_id='.$task['id'].'&project_id='.$task['project_id'].'&another_link=1');
- }
-
- $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#links');
+ $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links');
}
else {
- $this->session->flashError(t('Unable to add the link.'));
+ $this->session->flashError(t('Unable to create your link.'));
}
}
@@ -80,50 +79,6 @@ class Tasklink extends Base
}
/**
- * Edit form
- *
- * @access public
- */
- public function edit(array $values = array(), array $errors = array())
- {
- $task = $this->getTask();
- $taskLink = $this->getTaskLink();
-
- $this->response->html($this->taskLayout('tasklink/edit', array(
- 'values' => empty($values) ? $taskLink : $values,
- 'errors' => $errors,
- 'link_list' => $this->link->getLinkLabelList($task['project_id'], false),
- 'task_list' => $this->taskFinder->getList($task['project_id'], TaskModel::STATUS_OPEN, $task['id']),
- 'link' => $taskLink,
- 'task' => $task,
- 'edit' => true,
- )));
- }
-
- /**
- * Update and validate a link
- *
- * @access public
- */
- public function update()
- {
- $task = $this->getTask();
- $values = $this->request->getValues();
- list($valid, $errors) = $this->taskLink->validateModification($values);
-
- if ($valid) {
- if ($this->taskLink->update($values)) {
- $this->session->flash(t('Link updated successfully.'));
- $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#links');
- }
- else {
- $this->session->flashError(t('Unable to update the link.'));
- }
- }
- $this->edit($values, $errors);
- }
-
- /**
* Confirmation dialog before removing a link
*
* @access public
@@ -132,6 +87,7 @@ class Tasklink extends Base
{
$task = $this->getTask();
$link = $this->getTaskLink();
+
$this->response->html($this->taskLayout('tasklink/remove', array(
'link' => $link,
'task' => $task,
@@ -147,14 +103,14 @@ class Tasklink extends Base
{
$this->checkCSRFParam();
$task = $this->getTask();
-
+
if ($this->taskLink->remove($this->request->getIntegerParam('link_id'))) {
$this->session->flash(t('Link removed successfully.'));
- $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#links');
}
else {
$this->session->flashError(t('Unable to remove this link.'));
}
- $this->confirm();
+
+ $this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])));
}
}