1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Controller/Task.php

489 lines
15 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
namespace Controller;
use Model\Project as ProjectModel;
/**
* Task controller
*
* @package controller
* @author Frederic Guillot
*/
class Task extends Base
{
2014-10-22 19:59:09 +02:00
/**
* Public access (display a task)
*
* @access public
*/
public function readonly()
{
$project = $this->project->getByToken($this->request->getStringParam('token'));
// Token verification
if (! $project) {
$this->forbidden(true);
}
2014-11-23 20:13:38 +01:00
$task = $this->taskFinder->getDetails($this->request->getIntegerParam('task_id'));
2014-10-22 19:59:09 +02:00
if (! $task) {
$this->notfound(true);
}
2014-12-22 19:15:38 +01:00
$this->response->html($this->template->layout('task/public', array(
2014-10-22 19:59:09 +02:00
'project' => $project,
'comments' => $this->comment->getAll($task['id']),
'subtasks' => $this->subTask->getAll($task['id']),
'task' => $task,
'columns_list' => $this->board->getColumnsList($task['project_id']),
2014-11-23 20:13:38 +01:00
'colors_list' => $this->color->getList(),
2014-10-22 19:59:09 +02:00
'title' => $task['title'],
'no_layout' => true,
'auto_refresh' => true,
'not_editable' => true,
)));
}
2014-07-20 12:26:15 +02:00
/**
* Show a task
*
* @access public
*/
public function show()
{
$task = $this->getTask();
2014-11-23 20:13:38 +01:00
$subtasks = $this->subTask->getAll($task['id']);
$values = array(
'id' => $task['id'],
'date_started' => $task['date_started'],
'time_estimated' => $task['time_estimated'] ?: '',
'time_spent' => $task['time_spent'] ?: '',
);
$this->dateParser->format($values, array('date_started'));
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/show', array(
2014-10-22 19:59:09 +02:00
'project' => $this->project->getById($task['project_id']),
2014-07-20 12:26:15 +02:00
'files' => $this->file->getAll($task['id']),
'comments' => $this->comment->getAll($task['id']),
2014-11-23 20:13:38 +01:00
'subtasks' => $subtasks,
2014-07-20 12:26:15 +02:00
'task' => $task,
2014-11-23 20:13:38 +01:00
'values' => $values,
'timesheet' => $this->timeTracking->getTaskTimesheet($task, $subtasks),
2014-07-20 12:26:15 +02:00
'columns_list' => $this->board->getColumnsList($task['project_id']),
2014-11-23 20:13:38 +01:00
'colors_list' => $this->color->getList(),
'date_format' => $this->config->get('application_date_format'),
'date_formats' => $this->dateParser->getAvailableFormats(),
2014-12-22 19:15:38 +01:00
'title' => $task['project_name'].' &gt; '.$task['title'],
2014-07-20 12:26:15 +02:00
)));
}
/**
* Display a form to create a new task
*
* @access public
*/
2014-12-22 19:15:38 +01:00
public function create(array $values = array(), array $errors = array())
2014-07-20 12:26:15 +02:00
{
2014-12-22 19:15:38 +01:00
$project = $this->getProject();
2015-01-16 14:23:05 +01:00
$method = $this->request->isAjax() ? 'render' : 'layout';
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
if (empty($values)) {
$values = array(
2015-01-16 14:23:05 +01:00
'swimlane_id' => $this->request->getIntegerParam('swimlane_id'),
2014-07-20 12:26:15 +02:00
'column_id' => $this->request->getIntegerParam('column_id'),
'color_id' => $this->request->getStringParam('color_id'),
'owner_id' => $this->request->getIntegerParam('owner_id'),
'another_task' => $this->request->getIntegerParam('another_task'),
2014-12-22 19:15:38 +01:00
);
}
$this->response->html($this->template->$method('task/new', array(
'ajax' => $this->request->isAjax(),
'errors' => $errors,
'values' => $values + array('project_id' => $project['id']),
2014-07-20 12:26:15 +02:00
'projects_list' => $this->project->getListByStatus(ProjectModel::ACTIVE),
2014-12-22 19:15:38 +01:00
'columns_list' => $this->board->getColumnsList($project['id']),
'users_list' => $this->projectPermission->getMemberList($project['id'], true, false, true),
2014-11-23 20:13:38 +01:00
'colors_list' => $this->color->getList(),
2014-12-22 19:15:38 +01:00
'categories_list' => $this->category->getList($project['id']),
2014-11-23 20:13:38 +01:00
'date_format' => $this->config->get('application_date_format'),
'date_formats' => $this->dateParser->getAvailableFormats(),
2014-12-22 19:15:38 +01:00
'title' => $project['name'].' &gt; '.t('New task')
2014-07-20 12:26:15 +02:00
)));
}
/**
* Validate and save a new task
*
* @access public
*/
public function save()
{
2014-12-22 19:15:38 +01:00
$project = $this->getProject();
2014-07-20 12:26:15 +02:00
$values = $this->request->getValues();
2015-01-16 14:23:05 +01:00
$values['creator_id'] = $this->userSession->getId();
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
list($valid, $errors) = $this->taskValidator->validateCreation($values);
2014-07-20 12:26:15 +02:00
if ($valid) {
2014-12-22 19:15:38 +01:00
if ($this->taskCreation->create($values)) {
2014-07-20 12:26:15 +02:00
$this->session->flash(t('Task created successfully.'));
if (isset($values['another_task']) && $values['another_task'] == 1) {
unset($values['title']);
unset($values['description']);
$this->response->redirect('?controller=task&action=create&'.http_build_query($values));
}
else {
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=board&action=show&project_id='.$project['id']);
2014-07-20 12:26:15 +02:00
}
}
else {
$this->session->flashError(t('Unable to create your task.'));
}
}
2014-12-22 19:15:38 +01:00
$this->create($values, $errors);
2014-07-20 12:26:15 +02:00
}
/**
* Display a form to edit a task
*
* @access public
*/
2015-01-16 14:23:05 +01:00
public function edit(array $values = array(), array $errors = array())
2014-07-20 12:26:15 +02:00
{
$task = $this->getTask();
2014-11-23 20:13:38 +01:00
$ajax = $this->request->isAjax();
2014-07-20 12:26:15 +02:00
2015-01-16 14:23:05 +01:00
if (empty($values)) {
$values = $task;
}
$this->dateParser->format($values, array('date_due'));
2014-07-20 12:26:15 +02:00
$params = array(
2015-01-16 14:23:05 +01:00
'values' => $values,
'errors' => $errors,
2014-11-23 20:13:38 +01:00
'task' => $task,
2014-12-22 19:15:38 +01:00
'users_list' => $this->projectPermission->getMemberList($task['project_id']),
2014-11-23 20:13:38 +01:00
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($task['project_id']),
'date_format' => $this->config->get('application_date_format'),
'date_formats' => $this->dateParser->getAvailableFormats(),
'ajax' => $ajax,
);
if ($ajax) {
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('task/edit', $params));
2014-07-20 12:26:15 +02:00
}
else {
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/edit', $params));
2014-07-20 12:26:15 +02:00
}
}
/**
* Validate and update a task
*
* @access public
*/
public function update()
{
$task = $this->getTask();
$values = $this->request->getValues();
2014-11-23 20:13:38 +01:00
list($valid, $errors) = $this->taskValidator->validateModification($values);
2014-07-20 12:26:15 +02:00
if ($valid) {
2014-12-22 19:15:38 +01:00
if ($this->taskModification->update($values)) {
2014-07-20 12:26:15 +02:00
$this->session->flash(t('Task updated successfully.'));
if ($this->request->getIntegerParam('ajax')) {
$this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']);
}
else {
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']);
2014-07-20 12:26:15 +02:00
}
}
else {
$this->session->flashError(t('Unable to update your task.'));
}
}
2015-01-16 14:23:05 +01:00
$this->edit($values, $errors);
2014-07-20 12:26:15 +02:00
}
2014-11-23 20:13:38 +01:00
/**
* Update time tracking information
*
* @access public
*/
public function time()
{
$task = $this->getTask();
$values = $this->request->getValues();
2014-12-22 19:15:38 +01:00
list($valid,) = $this->taskValidator->validateTimeModification($values);
2014-11-23 20:13:38 +01:00
2014-12-22 19:15:38 +01:00
if ($valid && $this->taskModification->update($values)) {
2014-11-23 20:13:38 +01:00
$this->session->flash(t('Task updated successfully.'));
}
else {
$this->session->flashError(t('Unable to update your task.'));
}
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']);
2014-11-23 20:13:38 +01:00
}
2014-07-20 12:26:15 +02:00
/**
* Hide a task
*
* @access public
*/
public function close()
{
$task = $this->getTask();
2014-10-22 19:59:09 +02:00
if ($this->request->getStringParam('confirmation') === 'yes') {
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
if ($this->taskStatus->close($task['id'])) {
2014-10-22 19:59:09 +02:00
$this->session->flash(t('Task closed successfully.'));
} else {
$this->session->flashError(t('Unable to close this task.'));
}
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']);
2014-10-22 19:59:09 +02:00
}
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/close', array(
2014-07-20 12:26:15 +02:00
'task' => $task,
)));
}
/**
* Open a task
*
* @access public
*/
public function open()
{
$task = $this->getTask();
2014-10-22 19:59:09 +02:00
if ($this->request->getStringParam('confirmation') === 'yes') {
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
if ($this->taskStatus->open($task['id'])) {
2014-10-22 19:59:09 +02:00
$this->session->flash(t('Task opened successfully.'));
} else {
$this->session->flashError(t('Unable to open this task.'));
}
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']);
2014-10-22 19:59:09 +02:00
}
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/open', array(
2014-07-20 12:26:15 +02:00
'task' => $task,
)));
}
/**
* Remove a task
*
* @access public
*/
public function remove()
{
$task = $this->getTask();
2014-11-23 20:13:38 +01:00
if (! $this->taskPermission->canRemoveTask($task)) {
$this->forbidden();
}
2014-10-22 19:59:09 +02:00
if ($this->request->getStringParam('confirmation') === 'yes') {
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$this->checkCSRFParam();
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if ($this->task->remove($task['id'])) {
$this->session->flash(t('Task removed successfully.'));
} else {
$this->session->flashError(t('Unable to remove this task.'));
}
$this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']);
}
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/remove', array(
2014-07-20 12:26:15 +02:00
'task' => $task,
)));
}
/**
2014-10-22 19:59:09 +02:00
* Duplicate a task
2014-07-20 12:26:15 +02:00
*
* @access public
*/
public function duplicate()
{
$task = $this->getTask();
2014-10-22 19:59:09 +02:00
if ($this->request->getStringParam('confirmation') === 'yes') {
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$this->checkCSRFParam();
2014-12-22 19:15:38 +01:00
$task_id = $this->taskDuplication->duplicate($task['id']);
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if ($task_id) {
$this->session->flash(t('Task created successfully.'));
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task_id.'&project_id='.$task['project_id']);
2014-10-22 19:59:09 +02:00
} else {
$this->session->flashError(t('Unable to create this task.'));
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=duplicate&task_id='.$task['id'].'&project_id='.$task['project_id']);
2014-10-22 19:59:09 +02:00
}
}
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/duplicate', array(
2014-10-22 19:59:09 +02:00
'task' => $task,
2014-07-20 12:26:15 +02:00
)));
}
/**
* Edit description form
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function description()
2014-07-20 12:26:15 +02:00
{
$task = $this->getTask();
2014-10-22 19:59:09 +02:00
$ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax');
if ($this->request->isPost()) {
$values = $this->request->getValues();
2014-11-23 20:13:38 +01:00
list($valid, $errors) = $this->taskValidator->validateDescriptionCreation($values);
2014-10-22 19:59:09 +02:00
if ($valid) {
2014-12-22 19:15:38 +01:00
if ($this->taskModification->update($values)) {
2014-10-22 19:59:09 +02:00
$this->session->flash(t('Task updated successfully.'));
}
else {
$this->session->flashError(t('Unable to update your task.'));
}
if ($ajax) {
$this->response->redirect('?controller=board&action=show&project_id='.$task['project_id']);
}
else {
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id']);
2014-10-22 19:59:09 +02:00
}
}
}
else {
$values = $task;
$errors = array();
}
2014-07-20 12:26:15 +02:00
$params = array(
2014-10-22 19:59:09 +02:00
'values' => $values,
'errors' => $errors,
'task' => $task,
'ajax' => $ajax,
);
if ($ajax) {
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('task/edit_description', $params));
2014-07-20 12:26:15 +02:00
}
else {
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/edit_description', $params));
2014-07-20 12:26:15 +02:00
}
}
/**
2014-10-22 19:59:09 +02:00
* Move a task to another project
*
* @access public
*/
public function move()
{
2014-12-22 19:15:38 +01:00
$task = $this->getTask();
$values = $task;
$errors = array();
2015-01-16 14:23:05 +01:00
$projects_list = $this->projectPermission->getMemberProjects($this->userSession->getId());
2014-12-22 19:15:38 +01:00
unset($projects_list[$task['project_id']]);
if ($this->request->isPost()) {
$values = $this->request->getValues();
list($valid, $errors) = $this->taskValidator->validateProjectModification($values);
if ($valid) {
if ($this->taskDuplication->moveToProject($task['id'], $values['project_id'])) {
$this->session->flash(t('Task updated successfully.'));
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$values['project_id']);
2014-12-22 19:15:38 +01:00
}
else {
$this->session->flashError(t('Unable to update your task.'));
}
}
}
$this->response->html($this->taskLayout('task/move_project', array(
'values' => $values,
'errors' => $errors,
'task' => $task,
'projects_list' => $projects_list,
)));
2014-10-22 19:59:09 +02:00
}
/**
* Duplicate a task to another project
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function copy()
2014-07-20 12:26:15 +02:00
{
$task = $this->getTask();
2014-10-22 19:59:09 +02:00
$values = $task;
$errors = array();
2015-01-16 14:23:05 +01:00
$projects_list = $this->projectPermission->getMemberProjects($this->userSession->getId());
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
unset($projects_list[$task['project_id']]);
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if ($this->request->isPost()) {
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$values = $this->request->getValues();
2014-11-23 20:13:38 +01:00
list($valid, $errors) = $this->taskValidator->validateProjectModification($values);
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if ($valid) {
2014-12-22 19:15:38 +01:00
$task_id = $this->taskDuplication->duplicateToProject($task['id'], $values['project_id']);
2014-10-22 19:59:09 +02:00
if ($task_id) {
$this->session->flash(t('Task created successfully.'));
2015-01-16 14:23:05 +01:00
$this->response->redirect('?controller=task&action=show&task_id='.$task_id.'&project_id='.$values['project_id']);
2014-10-22 19:59:09 +02:00
}
else {
$this->session->flashError(t('Unable to create your task.'));
}
2014-07-20 12:26:15 +02:00
}
}
2014-12-22 19:15:38 +01:00
$this->response->html($this->taskLayout('task/duplicate_project', array(
2014-07-20 12:26:15 +02:00
'values' => $values,
'errors' => $errors,
'task' => $task,
2014-10-22 19:59:09 +02:00
'projects_list' => $projects_list,
2014-07-20 12:26:15 +02:00
)));
}
}