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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<?php
namespace Kanboard\Controller;
/**
* Class ProjectTagController
*
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class ProjectTagController extends BaseController
{
public function index()
{
$project = $this->getProject();
$this->response->html($this->helper->layout->project('project_tag/index', array(
'project' => $project,
'tags' => $this->tagModel->getAllByProject($project['id']),
'title' => t('Project tags management'),
)));
}
public function create(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$this->response->html($this->template->render('project_tag/create', array(
'project' => $project,
'values' => $values,
'colors' => $this->colorModel->getList(),
'errors' => $errors,
)));
}
public function save()
{
$project = $this->getProject();
$values = $this->request->getValues();
$values['project_id'] = $project['id'];
list($valid, $errors) = $this->tagValidator->validateCreation($values);
if ($valid) {
if ($this->tagModel->create($project['id'], $values['name'], $values['color_id']) > 0) {
$this->flash->success(t('Tag created successfully.'));
} else {
$this->flash->failure(t('Unable to create this tag.'));
}
$this->response->redirect($this->helper->url->to('ProjectTagController', 'index', array('project_id' => $project['id'])));
} else {
$this->create($values, $errors);
}
}
public function edit(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$tag = $this->getProjectTag($project);
if (empty($values)) {
$values = $tag;
}
$this->response->html($this->template->render('project_tag/edit', array(
'project' => $project,
'tag' => $tag,
'values' => $values,
'colors' => $this->colorModel->getList(),
'errors' => $errors,
)));
}
public function update()
{
$project = $this->getProject();
$tag = $this->getProjectTag($project);
$values = $this->request->getValues();
$values['project_id'] = $project['id'];
$values['id'] = $tag['id'];
list($valid, $errors) = $this->tagValidator->validateModification($values);
if ($valid) {
if ($this->tagModel->update($values['id'], $values['name'], $values['color_id'])) {
$this->flash->success(t('Tag updated successfully.'));
} else {
$this->flash->failure(t('Unable to update this tag.'));
}
$this->response->redirect($this->helper->url->to('ProjectTagController', 'index', array('project_id' => $project['id'])));
} else {
$this->edit($values, $errors);
}
}
public function confirm()
{
$project = $this->getProject();
$tag = $this->getProjectTag($project);
$this->response->html($this->template->render('project_tag/remove', array(
'tag' => $tag,
'project' => $project,
)));
}
public function remove()
{
$this->checkCSRFParam();
$project = $this->getProject();
$tag = $this->getProjectTag($project);
if ($this->tagModel->remove($tag['id'])) {
$this->flash->success(t('Tag removed successfully.'));
} else {
$this->flash->failure(t('Unable to remove this tag.'));
}
$this->response->redirect($this->helper->url->to('ProjectTagController', 'index', array('project_id' => $project['id'])));
}
}
|