100 lines
3.6 KiB
PHP
100 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Kanboard\Plugin\QualKard\Controller;
|
|
|
|
use Kanboard\Controller\BaseController;
|
|
use Kanboard\Core\Controller\AccessForbiddenException;
|
|
use Kanboard\Plugin\QualKard\Helper\QualKardHelper;
|
|
|
|
/**
|
|
* QualKard board actions, posted from the project Integrations page: set up the study board, reset
|
|
* all cards, or disable. Project-manager gated (the restructure is destructive).
|
|
*/
|
|
class QualKardController extends BaseController
|
|
{
|
|
/**
|
|
* Turn this project into a study board: rename the first 7 columns to the standard names (create
|
|
* or delete to reach exactly 7), move every card to Drafts, store the column roles, reset all
|
|
* cards to unread + armed-inert, and enable. Once-per-conversion, explicit + confirmed.
|
|
*/
|
|
public function setup()
|
|
{
|
|
$project = $this->authorize();
|
|
$helper = new QualKardHelper($this->container);
|
|
|
|
$names = array('Drafts', 'Study', 'Hairy', 'Hard', 'Medium', 'Easy', 'Done');
|
|
$columns = $this->columnModel->getAll($project['id']); // position-ordered rows
|
|
$ids = array();
|
|
|
|
for ($i = 0; $i < 7; $i++) {
|
|
if (isset($columns[$i])) {
|
|
$this->columnModel->update($columns[$i]['id'], $names[$i]);
|
|
$ids[$i] = (int) $columns[$i]['id'];
|
|
} else {
|
|
$ids[$i] = (int) $this->columnModel->create($project['id'], $names[$i]);
|
|
}
|
|
}
|
|
|
|
// Move every card to Drafts BEFORE deleting extras -- remove() is a raw DELETE (tasks cascade).
|
|
foreach ($this->taskFinderModel->getAll($project['id']) as $task) {
|
|
$this->taskPositionModel->movePosition($project['id'], $task['id'], $ids[0], 1, $task['swimlane_id'], false);
|
|
}
|
|
|
|
for ($i = 7, $n = count($columns); $i < $n; $i++) {
|
|
$this->columnModel->remove($columns[$i]['id']);
|
|
}
|
|
|
|
$roles = array('draft', 'study', 'hairy', 'hard', 'medium', 'easy', 'done');
|
|
foreach ($roles as $k => $role) {
|
|
$this->projectMetadataModel->save($project['id'], array('qualkard_col_'.$role => $ids[$k]));
|
|
}
|
|
|
|
$helper->resetAll($project['id']);
|
|
$this->projectMetadataModel->save($project['id'], array('qualkard_enabled' => 1));
|
|
|
|
$this->flash->success(t('QualKard study board is ready.'));
|
|
$this->redirectToIntegrations($project);
|
|
}
|
|
|
|
/**
|
|
* Reset every card on the board: unread, moved to Drafts, armed-inert. Keeps the columns.
|
|
*/
|
|
public function reset()
|
|
{
|
|
$project = $this->authorize();
|
|
(new QualKardHelper($this->container))->resetAll($project['id']);
|
|
$this->flash->success(t('All cards reset.'));
|
|
$this->redirectToIntegrations($project);
|
|
}
|
|
|
|
/**
|
|
* Disable QualKard on this board (non-destructive: leaves columns and cards as they are).
|
|
*/
|
|
public function disable()
|
|
{
|
|
$project = $this->authorize();
|
|
$this->projectMetadataModel->save($project['id'], array('qualkard_enabled' => 0));
|
|
$this->flash->success(t('QualKard disabled on this board.'));
|
|
$this->redirectToIntegrations($project);
|
|
}
|
|
|
|
// Project-manager gate + CSRF, shared by every action.
|
|
private function authorize()
|
|
{
|
|
$project = $this->getProject();
|
|
|
|
if (! $this->helper->user->hasProjectAccess('ProjectEditController', 'edit', $project['id'])) {
|
|
throw new AccessForbiddenException();
|
|
}
|
|
|
|
$this->checkCSRFForm();
|
|
|
|
return $project;
|
|
}
|
|
|
|
private function redirectToIntegrations(array $project)
|
|
{
|
|
$this->response->redirect($this->helper->url->to('ProjectViewController', 'integrations', array('project_id' => $project['id'])));
|
|
}
|
|
}
|