Refactoring/simplification of the pull-request about links
This commit is contained in:
@@ -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,69 +61,23 @@ 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.'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -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'])));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user