summaryrefslogtreecommitdiff
path: root/app/Controller/TaskSuppressionController.php
blob: 019bd97cae9394ff9fd31effb1f3981d4a8a40ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

namespace Kanboard\Controller;

use Kanboard\Core\Controller\AccessForbiddenException;

/**
 * Class TaskSuppressionController
 *
 * @package Kanboard\Controller
 * @author  Frederic Guillot
 */
class TaskSuppressionController extends BaseController
{
    /**
     * Confirmation dialog box before to remove the task
     */
    public function confirm()
    {
        $task = $this->getTask();

        if (! $this->helper->projectRole->canRemoveTask($task)) {
            throw new AccessForbiddenException();
        }

        $this->response->html($this->template->render('task_suppression/remove', array(
            'task' => $task,
            'redirect' => $this->request->getStringParam('redirect'),
        )));
    }

    /**
     * Remove a task
     */
    public function remove()
    {
        $task = $this->getTask();
        $this->checkCSRFParam();

        if (! $this->helper->projectRole->canRemoveTask($task)) {
            throw new AccessForbiddenException();
        }

        if ($this->taskModel->remove($task['id'])) {
            $this->flash->success(t('Task removed successfully.'));
        } else {
            $this->flash->failure(t('Unable to remove this task.'));
        }

        $redirect = $this->request->getStringParam('redirect') === '';
        $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $task['project_id'])), $redirect);
    }
}