72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Kanboard\Plugin\OrganonTweaks\Controller;
|
||
|
|
|
||
|
|
use Kanboard\Controller\BaseController;
|
||
|
|
use Kanboard\Core\Controller\AccessForbiddenException;
|
||
|
|
use Kanboard\Model\TaskModel;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove an empty board column straight from its header menu.
|
||
|
|
*/
|
||
|
|
class ColumnController extends BaseController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Confirmation dialog.
|
||
|
|
*/
|
||
|
|
public function confirm()
|
||
|
|
{
|
||
|
|
$project = $this->getProject();
|
||
|
|
$column_id = $this->request->getIntegerParam('column_id');
|
||
|
|
$this->checkAccess($project['id'], $column_id);
|
||
|
|
|
||
|
|
$this->response->html($this->template->render('organonTweaks:board/remove_column', array(
|
||
|
|
'project' => $project,
|
||
|
|
'column' => $this->columnModel->getColumnTitleById($column_id),
|
||
|
|
'column_id' => $column_id,
|
||
|
|
)));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the column and return to the board.
|
||
|
|
*/
|
||
|
|
public function remove()
|
||
|
|
{
|
||
|
|
$project = $this->getProject();
|
||
|
|
$values = $this->request->getValues();
|
||
|
|
$column_id = isset($values['column_id']) ? (int) $values['column_id'] : 0;
|
||
|
|
|
||
|
|
$this->checkAccess($project['id'], $column_id);
|
||
|
|
|
||
|
|
if ($this->columnModel->remove($column_id)) {
|
||
|
|
$this->flash->success(t('Column removed successfully.'));
|
||
|
|
} else {
|
||
|
|
$this->flash->failure(t('Unable to remove this column.'));
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Allow only users who can manage columns, and only for a column with no tasks at all
|
||
|
|
* (open or closed) -- ColumnModel::remove() is a bare delete, so a non-empty column
|
||
|
|
* would orphan its tasks.
|
||
|
|
*/
|
||
|
|
private function checkAccess($project_id, $column_id)
|
||
|
|
{
|
||
|
|
if (! $this->helper->user->hasProjectAccess('ColumnController', 'remove', $project_id)) {
|
||
|
|
throw new AccessForbiddenException();
|
||
|
|
}
|
||
|
|
|
||
|
|
$count = $this->taskFinderModel->countByColumnId(
|
||
|
|
$project_id,
|
||
|
|
$column_id,
|
||
|
|
array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)
|
||
|
|
);
|
||
|
|
|
||
|
|
if ($count > 0) {
|
||
|
|
throw new AccessForbiddenException();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|