1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tinyissue\Form; |
13
|
|
|
|
14
|
|
|
use Tinyissue\Model\Project as ProjectModel; |
15
|
|
|
use Tinyissue\Model\Tag as TagModel; |
16
|
|
|
use Tinyissue\Model\Tag; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Project is a class to defines fields & rules for add/edit project form. |
20
|
|
|
* |
21
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class Project extends FormAbstract |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
2 |
|
public function actions() |
29
|
|
|
{ |
30
|
2 |
|
if ($this->isEditing()) { |
31
|
|
|
return [ |
32
|
2 |
|
'submit' => 'update', |
33
|
|
|
'delete' => [ |
34
|
2 |
|
'type' => 'danger_submit', |
35
|
2 |
|
'label' => trans('tinyissue.delete_something', ['name' => $this->getModel()->name]), |
36
|
2 |
|
'class' => 'delete-project', |
37
|
2 |
|
'name' => 'delete-project', |
38
|
2 |
|
'data-message' => trans('tinyissue.delete_project_confirm'), |
39
|
|
|
], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return [ |
44
|
|
|
'submit' => 'create_project', |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
2 |
|
public function fields() |
52
|
|
|
{ |
53
|
|
|
$fields = [ |
54
|
|
|
'name' => [ |
55
|
|
|
'type' => 'text', |
56
|
|
|
'label' => 'name', |
57
|
2 |
|
], |
58
|
|
|
'private' => [ |
59
|
2 |
|
'type' => 'select', |
60
|
2 |
|
'label' => 'visibility', |
61
|
|
|
'options' => [ |
62
|
2 |
|
ProjectModel::INTERNAL_YES => trans('tinyissue.internal'), |
63
|
2 |
|
ProjectModel::PRIVATE_YES => trans('tinyissue.private'), |
64
|
2 |
|
ProjectModel::PRIVATE_NO => trans('tinyissue.public'), |
65
|
|
|
], |
66
|
|
|
], |
67
|
|
|
'default_assignee' => [ |
68
|
|
|
'type' => 'hidden', |
69
|
|
|
'id' => 'default_assignee-id', |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
// On create project can assign users |
74
|
|
|
// On edit project can change status or default assignee |
75
|
2 |
|
if (!$this->isEditing()) { |
76
|
|
|
$fields['user'] = [ |
77
|
|
|
'type' => 'selectUser', |
78
|
|
|
'label' => 'assign_users', |
79
|
|
|
'id' => 'add-user-project', |
80
|
|
|
'placeholder' => trans('tinyissue.assign_a_user'), |
81
|
|
|
]; |
82
|
|
|
} else { |
83
|
2 |
|
$fields['status'] = [ |
84
|
2 |
|
'type' => 'select', |
85
|
2 |
|
'label' => 'status', |
86
|
2 |
|
'options' => [ProjectModel::STATUS_OPEN => trans('tinyissue.open'), ProjectModel::STATUS_ARCHIVED => trans('tinyissue.archived')], |
87
|
|
|
]; |
88
|
2 |
|
$fields['default_assignee'] = [ |
89
|
2 |
|
'type' => 'select', |
90
|
2 |
|
'label' => 'default_assignee', |
91
|
2 |
|
'options' => [0 => ''] + $this->getModel()->usersCanFixIssue()->get()->lists('fullname', 'id')->all(), |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
|
95
|
2 |
|
$fields['kanban_board'] = [ |
96
|
|
|
'type' => 'legend', |
97
|
|
|
]; |
98
|
|
|
|
99
|
2 |
|
$fields += $this->getKanbanColumnsField(); |
100
|
|
|
|
101
|
2 |
|
return $fields; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Return Kanban columns field. |
106
|
|
|
* |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
2 |
|
protected function getKanbanColumnsField() |
110
|
|
|
{ |
111
|
2 |
|
$fields = []; |
112
|
|
|
|
113
|
|
|
// All of the status tags |
114
|
2 |
|
$statusTags = (new Tag())->getStatusTags()->get()->filter(function (Tag $tag) { |
|
|
|
|
115
|
2 |
|
return !($tag->name == Tag::STATUS_OPEN || $tag->name == Tag::STATUS_CLOSED); |
116
|
2 |
|
}); |
117
|
|
|
|
118
|
|
|
// Get selected status tags on editing a project |
119
|
2 |
|
$selectTags = []; |
120
|
2 |
|
if ($this->isEditing()) { |
121
|
2 |
|
$selectTags = $this->getModel()->kanbanTags()->get()->lists('id'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// An array for checkboxes |
125
|
2 |
|
$options = []; |
126
|
2 |
|
foreach ($selectTags as $tagId) { |
127
|
|
|
$tag = $statusTags->find($tagId); |
128
|
|
|
if ($tag) { |
129
|
|
|
$options[ucwords($tag->name)] = $this->getKanbanColumnField($tag, true); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
2 |
|
foreach ($statusTags as $tag) { |
134
|
2 |
|
if (!isset($options[ucwords($tag->name)])) { |
135
|
2 |
|
$options[ucwords($tag->name)] = $this->getKanbanColumnField($tag); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
// The checkbox button element |
140
|
2 |
|
$fields['columns[]'] = [ |
141
|
2 |
|
'label' => 'columns', |
142
|
2 |
|
'type' => 'checkboxButton', |
143
|
2 |
|
'checkboxes' => $options, |
144
|
|
|
'grouped' => true, |
145
|
|
|
]; |
146
|
|
|
|
147
|
2 |
|
return $fields; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Returns an array structure for a checkbox button in the kanban field. |
152
|
|
|
* |
153
|
|
|
* @param Tag $tag |
154
|
|
|
* @param bool $checked |
155
|
|
|
* |
156
|
|
|
* @return array |
157
|
|
|
*/ |
158
|
2 |
|
protected function getKanbanColumnField(Tag $tag, $checked = false) |
159
|
|
|
{ |
160
|
|
|
return [ |
161
|
2 |
|
'value' => $tag->id, |
162
|
2 |
|
'data-tags' => $tag->id, |
163
|
2 |
|
'color' => $tag->bgcolor, |
164
|
2 |
|
'checked' => $checked, |
165
|
|
|
]; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return array |
170
|
|
|
*/ |
171
|
2 |
|
public function rules() |
172
|
|
|
{ |
173
|
|
|
$rules = [ |
174
|
2 |
|
'name' => 'required|max:250', |
175
|
|
|
'user' => 'array|min:1', |
176
|
|
|
]; |
177
|
|
|
|
178
|
2 |
|
return $rules; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
public function getRedirectUrl() |
185
|
|
|
{ |
186
|
|
|
if ($this->isEditing()) { |
187
|
|
|
return $this->getModel()->to('edit'); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return 'projects/new'; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: