summaryrefslogtreecommitdiff
path: root/app/Controller/ActionController.php
blob: 43acf590236853e1f2ef358fdd97080d95929e1a (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

namespace Kanboard\Controller;

/**
 * Automatic Actions Controller
 *
 * @package Kanboard\Controller
 * @author  Frederic Guillot
 */
class ActionController extends BaseController
{
    /**
     * List of automatic actions for a given project
     *
     * @access public
     */
    public function index()
    {
        $project = $this->getProject();
        $actions = $this->actionModel->getAllByProject($project['id']);

        $this->response->html($this->helper->layout->project('action/index', array(
            'values' => array('project_id' => $project['id']),
            'project' => $project,
            'actions' => $actions,
            'available_actions' => $this->actionManager->getAvailableActions(),
            'available_events' => $this->eventManager->getAll(),
            'available_params' => $this->actionManager->getAvailableParameters($actions),
            'columns_list' => $this->columnModel->getList($project['id']),
            'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id']),
            'projects_list' => $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()),
            'colors_list' => $this->colorModel->getList(),
            'categories_list' => $this->categoryModel->getList($project['id']),
            'links_list' => $this->linkModel->getList(0, false),
            'swimlane_list' => $this->swimlaneModel->getList($project['id']),
            'title' => t('Automatic actions')
        )));
    }

    /**
     * Confirmation dialog before removing an action
     *
     * @access public
     */
    public function confirm()
    {
        $project = $this->getProject();
        $action = $this->getAction($project);

        $this->response->html($this->helper->layout->project('action/remove', array(
            'action' => $action,
            'available_events' => $this->eventManager->getAll(),
            'available_actions' => $this->actionManager->getAvailableActions(),
            'project' => $project,
            'title' => t('Remove an action')
        )));
    }

    /**
     * Remove an action
     *
     * @access public
     */
    public function remove()
    {
        $this->checkCSRFParam();
        $project = $this->getProject();
        $action = $this->getAction($project);

        if (! empty($action) && $this->actionModel->remove($action['id'])) {
            $this->flash->success(t('Action removed successfully.'));
        } else {
            $this->flash->failure(t('Unable to remove this action.'));
        }

        $this->response->redirect($this->helper->url->to('ActionController', 'index', array('project_id' => $project['id'])));
    }
}