resources added f1
This commit is contained in:
71
Controller/ColumnController.php
Normal file
71
Controller/ColumnController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user