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/Board.php

478 lines
14 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
namespace Controller;
/**
* Board controller
*
* @package controller
* @author Frederic Guillot
*/
class Board extends Base
{
/**
2014-11-23 20:13:38 +01:00
* Move a column down or up
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-11-23 20:13:38 +01:00
public function moveColumn()
2014-07-20 12:26:15 +02:00
{
$this->checkCSRFParam();
2015-01-16 14:23:05 +01:00
$project = $this->getProject();
2014-07-20 12:26:15 +02:00
$column_id = $this->request->getIntegerParam('column_id');
2014-11-23 20:13:38 +01:00
$direction = $this->request->getStringParam('direction');
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
if ($direction === 'up' || $direction === 'down') {
$this->board->{'move'.$direction}($project['id'], $column_id);
}
2014-07-20 12:26:15 +02:00
2014-11-23 20:13:38 +01:00
$this->response->redirect('?controller=board&action=edit&project_id='.$project['id']);
2014-07-20 12:26:15 +02:00
}
/**
* Change a task assignee directly from the board
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function changeAssignee()
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$task = $this->getTask();
2014-07-20 12:26:15 +02:00
$project = $this->project->getById($task['project_id']);
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('board/assignee', array(
2014-12-22 19:15:38 +01:00
'values' => $task,
'users_list' => $this->projectPermission->getMemberList($project['id']),
'project' => $project,
)));
2014-07-20 12:26:15 +02:00
}
/**
* Validate an assignee modification
*
* @access public
*/
2014-10-22 19:59:09 +02:00
public function updateAssignee()
2014-07-20 12:26:15 +02:00
{
$values = $this->request->getValues();
2014-11-23 20:13:38 +01:00
list($valid,) = $this->taskValidator->validateAssigneeModification($values);
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
if ($valid && $this->taskModification->update($values)) {
2014-07-20 12:26:15 +02:00
$this->session->flash(t('Task updated successfully.'));
}
else {
$this->session->flashError(t('Unable to update your task.'));
}
$this->response->redirect('?controller=board&action=show&project_id='.$values['project_id']);
}
2014-10-22 19:59:09 +02:00
/**
* Change a task category directly from the board
*
* @access public
*/
public function changeCategory()
{
$task = $this->getTask();
$project = $this->project->getById($task['project_id']);
2014-12-22 19:15:38 +01:00
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('board/category', array(
2014-10-22 19:59:09 +02:00
'values' => $task,
'categories_list' => $this->category->getList($project['id']),
2014-12-22 19:15:38 +01:00
'project' => $project,
)));
2014-10-22 19:59:09 +02:00
}
/**
* Validate a category modification
*
* @access public
*/
public function updateCategory()
{
$values = $this->request->getValues();
2014-11-23 20:13:38 +01:00
list($valid,) = $this->taskValidator->validateCategoryModification($values);
2014-10-22 19:59:09 +02:00
2014-12-22 19:15:38 +01:00
if ($valid && $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.'));
}
$this->response->redirect('?controller=board&action=show&project_id='.$values['project_id']);
}
2014-07-20 12:26:15 +02:00
/**
* Display the public version of a board
* Access checked by a simple token, no user login, read only, auto-refresh
*
* @access public
*/
public function readonly()
{
$token = $this->request->getStringParam('token');
$project = $this->project->getByToken($token);
// Token verification
2015-04-21 17:56:16 +02:00
if (empty($project)) {
2014-10-22 19:59:09 +02:00
$this->forbidden(true);
2014-07-20 12:26:15 +02:00
}
// Display the board with a specific layout
2014-12-22 19:15:38 +01:00
$this->response->html($this->template->layout('board/public', array(
2014-07-20 12:26:15 +02:00
'project' => $project,
2015-01-16 14:23:05 +01:00
'swimlanes' => $this->board->getBoard($project['id']),
2014-07-20 12:26:15 +02:00
'categories' => $this->category->getList($project['id'], false),
'title' => $project['name'],
2015-04-21 17:56:16 +02:00
'description' => $project['description'],
2014-07-20 12:26:15 +02:00
'no_layout' => true,
2014-10-22 19:59:09 +02:00
'not_editable' => true,
2014-11-23 20:13:38 +01:00
'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'),
2015-01-16 14:23:05 +01:00
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
2014-07-20 12:26:15 +02:00
)));
}
/**
* Redirect the user to the default project
*
* @access public
*/
public function index()
{
2015-01-16 14:23:05 +01:00
$last_seen_project_id = $this->userSession->getLastSeenProjectId();
$favorite_project_id = $this->userSession->getFavoriteProjectId();
2014-10-22 19:59:09 +02:00
$project_id = $last_seen_project_id ?: $favorite_project_id;
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if (! $project_id) {
2015-01-16 14:23:05 +01:00
$projects = $this->projectPermission->getAllowedProjects($this->userSession->getId());
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
if (empty($projects)) {
2014-07-20 12:26:15 +02:00
2015-01-16 14:23:05 +01:00
if ($this->userSession->isAdmin()) {
2014-10-22 19:59:09 +02:00
$this->redirectNoProject();
}
$this->forbidden();
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
$project_id = key($projects);
2014-07-20 12:26:15 +02:00
}
2014-10-22 19:59:09 +02:00
$this->show($project_id);
2014-07-20 12:26:15 +02:00
}
/**
* Show a board for a given project
*
* @access public
2014-10-22 19:59:09 +02:00
* @param integer $project_id Default project id
2014-07-20 12:26:15 +02:00
*/
2014-10-22 19:59:09 +02:00
public function show($project_id = 0)
2014-07-20 12:26:15 +02:00
{
2014-10-22 19:59:09 +02:00
$project = $this->getProject($project_id);
2015-01-16 14:23:05 +01:00
$projects = $this->projectPermission->getAllowedProjects($this->userSession->getId());
2014-07-20 12:26:15 +02:00
2014-10-22 19:59:09 +02:00
$board_selector = $projects;
unset($board_selector[$project['id']]);
2015-01-16 14:23:05 +01:00
$this->userSession->storeLastSeenProjectId($project['id']);
2014-07-20 12:26:15 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->template->layout('board/index', array(
'users' => $this->projectPermission->getMemberList($project['id'], true, true),
2014-07-20 12:26:15 +02:00
'projects' => $projects,
2014-12-22 19:15:38 +01:00
'project' => $project,
2015-01-16 14:23:05 +01:00
'swimlanes' => $this->board->getBoard($project['id']),
2014-10-22 19:59:09 +02:00
'categories' => $this->category->getList($project['id'], true, true),
2014-11-23 20:13:38 +01:00
'title' => $project['name'],
2015-04-21 17:56:16 +02:00
'description' => $project['description'],
2014-10-22 19:59:09 +02:00
'board_selector' => $board_selector,
2014-11-23 20:13:38 +01:00
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
2014-07-20 12:26:15 +02:00
)));
}
/**
* Display a form to edit a board
*
* @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
{
2015-01-16 14:23:05 +01:00
$project = $this->getProject();
2014-10-22 19:59:09 +02:00
$columns = $this->board->getColumns($project['id']);
2014-07-20 12:26:15 +02:00
foreach ($columns as $column) {
$values['title['.$column['id'].']'] = $column['title'];
2015-02-25 17:29:06 +01:00
$values['description['.$column['id'].']'] = $column['description'];
2014-07-20 12:26:15 +02:00
$values['task_limit['.$column['id'].']'] = $column['task_limit'] ?: null;
}
2014-12-22 19:15:38 +01:00
$this->response->html($this->projectLayout('board/edit', array(
2015-01-16 14:23:05 +01:00
'errors' => $errors,
2014-10-22 19:59:09 +02:00
'values' => $values + array('project_id' => $project['id']),
2014-07-20 12:26:15 +02:00
'columns' => $columns,
'project' => $project,
'title' => t('Edit board')
)));
}
/**
2015-02-25 17:29:06 +01:00
* Display a form to edit a board
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2015-02-25 17:29:06 +01:00
public function editColumn(array $values = array(), array $errors = array())
2014-07-20 12:26:15 +02:00
{
2015-01-16 14:23:05 +01:00
$project = $this->getProject();
2015-02-25 17:29:06 +01:00
$column = $this->board->getColumn($this->request->getIntegerParam('column_id'));
2014-07-20 12:26:15 +02:00
2015-02-25 17:29:06 +01:00
$this->response->html($this->projectLayout('board/edit_column', array(
'errors' => $errors,
'values' => $values ?: $column,
'project' => $project,
'column' => $column,
'title' => t('Edit column "%s"', $column['title'])
)));
}
/**
* Validate and update a column
*
* @access public
*/
public function updateColumn()
{
$project = $this->getProject();
$values = $this->request->getValues();
2014-07-20 12:26:15 +02:00
2015-02-25 17:29:06 +01:00
list($valid, $errors) = $this->board->validateModification($values);
2014-07-20 12:26:15 +02:00
if ($valid) {
2015-02-25 17:29:06 +01:00
if ($this->board->updateColumn($values['id'], $values['title'], $values['task_limit'], $values['description'])) {
2014-07-20 12:26:15 +02:00
$this->session->flash(t('Board updated successfully.'));
$this->response->redirect('?controller=board&action=edit&project_id='.$project['id']);
}
else {
$this->session->flashError(t('Unable to update this board.'));
}
}
2015-02-25 17:29:06 +01:00
$this->editcolumn($values, $errors);
2014-07-20 12:26:15 +02:00
}
/**
* Validate and add a new column
*
* @access public
*/
public function add()
{
2015-01-16 14:23:05 +01:00
$project = $this->getProject();
2014-10-22 19:59:09 +02:00
$columns = $this->board->getColumnsList($project['id']);
2014-07-20 12:26:15 +02:00
$data = $this->request->getValues();
$values = array();
foreach ($columns as $column_id => $column_title) {
$values['title['.$column_id.']'] = $column_title;
}
list($valid, $errors) = $this->board->validateCreation($data);
if ($valid) {
2015-02-25 17:29:06 +01:00
if ($this->board->addColumn($project['id'], $data['title'], $data['task_limit'], $data['description'])) {
2014-07-20 12:26:15 +02:00
$this->session->flash(t('Board updated successfully.'));
$this->response->redirect('?controller=board&action=edit&project_id='.$project['id']);
}
else {
$this->session->flashError(t('Unable to update this board.'));
}
}
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
* Remove a column
2014-07-20 12:26:15 +02:00
*
* @access public
*/
2014-11-23 20:13:38 +01:00
public function remove()
2014-07-20 12:26:15 +02:00
{
2015-01-16 14:23:05 +01:00
$project = $this->getProject();
2014-11-23 20:13:38 +01:00
if ($this->request->getStringParam('remove') === 'yes') {
$this->checkCSRFParam();
$column = $this->board->getColumn($this->request->getIntegerParam('column_id'));
2015-04-21 17:56:16 +02:00
if (! empty($column) && $this->board->removeColumn($column['id'])) {
2014-11-23 20:13:38 +01:00
$this->session->flash(t('Column removed successfully.'));
} else {
$this->session->flashError(t('Unable to remove this column.'));
}
$this->response->redirect('?controller=board&action=edit&project_id='.$project['id']);
}
2014-10-22 19:59:09 +02:00
2014-12-22 19:15:38 +01:00
$this->response->html($this->projectLayout('board/remove', array(
2014-07-20 12:26:15 +02:00
'column' => $this->board->getColumn($this->request->getIntegerParam('column_id')),
2014-10-22 19:59:09 +02:00
'project' => $project,
2014-07-20 12:26:15 +02:00
'title' => t('Remove a column from a board')
)));
}
/**
* Save the board (Ajax request made by the drag and drop)
*
* @access public
*/
public function save()
{
2014-10-22 19:59:09 +02:00
$project_id = $this->request->getIntegerParam('project_id');
2014-07-20 12:26:15 +02:00
2015-01-16 14:23:05 +01:00
if (! $project_id || ! $this->request->isAjax()) {
return $this->response->status(403);
}
2014-07-20 12:26:15 +02:00
2015-01-16 14:23:05 +01:00
if (! $this->projectPermission->isUserAllowed($project_id, $this->userSession->getId())) {
$this->response->text('Forbidden', 403);
}
2014-10-22 19:59:09 +02:00
2015-01-16 14:23:05 +01:00
$values = $this->request->getJson();
2014-10-22 19:59:09 +02:00
2015-01-16 14:23:05 +01:00
$result =$this->taskPosition->movePosition(
$project_id,
$values['task_id'],
$values['column_id'],
$values['position'],
$values['swimlane_id']
);
2014-07-20 12:26:15 +02:00
2015-01-16 14:23:05 +01:00
if (! $result) {
return $this->response->status(400);
2014-07-20 12:26:15 +02:00
}
2015-01-16 14:23:05 +01:00
$this->response->html(
$this->template->render('board/show', array(
'project' => $this->project->getById($project_id),
'swimlanes' => $this->board->getBoard($project_id),
'categories' => $this->category->getList($project_id, false),
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
)),
201
);
2014-07-20 12:26:15 +02:00
}
/**
* Check if the board have been changed
*
* @access public
*/
public function check()
{
2015-01-16 14:23:05 +01:00
if (! $this->request->isAjax()) {
return $this->response->status(403);
}
2014-07-20 12:26:15 +02:00
2015-01-16 14:23:05 +01:00
$project_id = $this->request->getIntegerParam('project_id');
$timestamp = $this->request->getIntegerParam('timestamp');
2014-07-20 12:26:15 +02:00
2015-01-16 14:23:05 +01:00
if (! $this->projectPermission->isUserAllowed($project_id, $this->userSession->getId())) {
$this->response->text('Forbidden', 403);
2014-07-20 12:26:15 +02:00
}
2015-01-16 14:23:05 +01:00
if (! $this->project->isModifiedSince($project_id, $timestamp)) {
return $this->response->status(304);
2014-07-20 12:26:15 +02:00
}
2015-01-16 14:23:05 +01:00
$this->response->html(
$this->template->render('board/show', array(
'project' => $this->project->getById($project_id),
'swimlanes' => $this->board->getBoard($project_id),
'categories' => $this->category->getList($project_id, false),
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
))
);
2014-07-20 12:26:15 +02:00
}
2014-12-22 19:15:38 +01:00
/**
2015-02-25 17:29:06 +01:00
* Get links on mouseover
2014-12-22 19:15:38 +01:00
*
* @access public
*/
2015-02-25 17:29:06 +01:00
public function tasklinks()
2014-12-22 19:15:38 +01:00
{
$task = $this->getTask();
2015-02-25 17:29:06 +01:00
$this->response->html($this->template->render('board/tasklinks', array(
'links' => $this->taskLink->getLinks($task['id']),
2015-01-16 14:23:05 +01:00
'task' => $task,
2014-12-22 19:15:38 +01:00
)));
}
/**
2015-02-25 17:29:06 +01:00
* Get subtasks on mouseover
2014-12-22 19:15:38 +01:00
*
* @access public
*/
2015-02-25 17:29:06 +01:00
public function subtasks()
2014-12-22 19:15:38 +01:00
{
$task = $this->getTask();
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('board/subtasks', array(
2015-02-25 17:29:06 +01:00
'subtasks' => $this->subtask->getAll($task['id']),
2015-01-16 14:23:05 +01:00
'task' => $task,
2014-12-22 19:15:38 +01:00
)));
}
/**
* Display all attachments during the task mouseover
*
* @access public
*/
public function attachments()
{
$task = $this->getTask();
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('board/files', array(
2015-04-21 17:56:16 +02:00
'files' => $this->file->getAllDocuments($task['id']),
'images' => $this->file->getAllImages($task['id']),
2015-01-16 14:23:05 +01:00
'task' => $task,
2014-12-22 19:15:38 +01:00
)));
}
/**
* Display comments during a task mouseover
*
* @access public
*/
public function comments()
{
$task = $this->getTask();
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('board/comments', array(
2014-12-22 19:15:38 +01:00
'comments' => $this->comment->getAll($task['id'])
)));
}
/**
2015-02-25 17:29:06 +01:00
* Display task description
2014-12-22 19:15:38 +01:00
*
* @access public
*/
public function description()
{
$task = $this->getTask();
2015-01-16 14:23:05 +01:00
$this->response->html($this->template->render('board/description', array(
2014-12-22 19:15:38 +01:00
'task' => $task
)));
}
2014-07-20 12:26:15 +02:00
}