|
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
|
3 |
|
public function actions() |
|
29
|
|
|
{ |
|
30
|
3 |
|
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
|
1 |
|
'submit' => 'create_project', |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
3 |
|
public function fields() |
|
52
|
|
|
{ |
|
53
|
|
|
$fields = [ |
|
54
|
|
|
'name' => [ |
|
55
|
|
|
'type' => 'text', |
|
56
|
|
|
'label' => 'name', |
|
57
|
3 |
|
], |
|
58
|
|
|
'private' => [ |
|
59
|
3 |
|
'type' => 'select', |
|
60
|
3 |
|
'label' => 'visibility', |
|
61
|
3 |
|
'options' => [ProjectModel::PRIVATE_YES => trans('tinyissue.private'), ProjectModel::PRIVATE_NO => trans('tinyissue.public')], |
|
62
|
|
|
], |
|
63
|
|
|
'default_assignee' => [ |
|
64
|
|
|
'type' => 'hidden', |
|
65
|
|
|
'id' => 'default_assignee-id', |
|
66
|
|
|
], |
|
67
|
|
|
]; |
|
68
|
|
|
|
|
69
|
|
|
// On create project can assign users |
|
70
|
|
|
// On edit project can change status or default assignee |
|
71
|
3 |
|
if (!$this->isEditing()) { |
|
72
|
1 |
|
$fields['user'] = [ |
|
73
|
1 |
|
'type' => 'selectUser', |
|
74
|
1 |
|
'label' => 'assign_users', |
|
75
|
1 |
|
'id' => 'add-user-project', |
|
76
|
1 |
|
'placeholder' => trans('tinyissue.assign_a_user'), |
|
77
|
|
|
]; |
|
78
|
|
|
} else { |
|
79
|
2 |
|
$fields['status'] = [ |
|
80
|
2 |
|
'type' => 'select', |
|
81
|
2 |
|
'label' => 'status', |
|
82
|
2 |
|
'options' => [ProjectModel::STATUS_OPEN => trans('tinyissue.open'), ProjectModel::STATUS_ARCHIVED => trans('tinyissue.archived')], |
|
83
|
|
|
]; |
|
84
|
2 |
|
$fields['default_assignee'] = [ |
|
85
|
2 |
|
'type' => 'select', |
|
86
|
2 |
|
'label' => 'default_assignee', |
|
87
|
2 |
|
'options' => [0 => ''] + $this->getModel()->usersCanFixIssue()->get()->lists('fullname', 'id')->all(), |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
3 |
|
$fields['kanban_board'] = [ |
|
92
|
|
|
'type' => 'legend', |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
3 |
|
$fields += $this->getKanbanColumnsField(); |
|
96
|
|
|
|
|
97
|
3 |
|
return $fields; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return Kanban columns field. |
|
102
|
|
|
* |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
3 |
|
protected function getKanbanColumnsField() |
|
106
|
|
|
{ |
|
107
|
3 |
|
$fields = []; |
|
108
|
|
|
|
|
109
|
|
|
// All of the status tags |
|
110
|
3 |
|
$statusTags = (new Tag())->getStatusTags()->get()->filter(function (TagModel $tag) { |
|
|
|
|
|
|
111
|
3 |
|
return !($tag->name == TagModel::STATUS_OPEN || $tag->name == TagModel::STATUS_CLOSED); |
|
112
|
3 |
|
}); |
|
113
|
|
|
|
|
114
|
|
|
// Get selected status tags on editing a project |
|
115
|
3 |
|
if ($this->isEditing()) { |
|
116
|
2 |
|
$selectTags = $this->getModel()->kanbanTags()->get()->lists('id'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
// An array for checkboxes |
|
120
|
3 |
|
$options = []; |
|
121
|
3 |
|
foreach ($statusTags as $tag) { |
|
122
|
3 |
|
$options[ucwords($tag->name)] = [ |
|
123
|
3 |
|
'value' => $tag->id, |
|
124
|
3 |
|
'data-tags' => $tag->id, |
|
125
|
3 |
|
'color' => $tag->bgcolor, |
|
126
|
3 |
|
'checked' => (isset($selectTags) && $selectTags->search($tag->id) > 0), |
|
127
|
|
|
]; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
// The checkbox button element |
|
131
|
3 |
|
$fields['columns[]'] = [ |
|
132
|
3 |
|
'label' => 'columns', |
|
133
|
3 |
|
'type' => 'checkboxButton', |
|
134
|
3 |
|
'checkboxes' => $options, |
|
135
|
|
|
'grouped' => true, |
|
136
|
3 |
|
'help' => trans('tinyissue.columns_help'), |
|
137
|
|
|
]; |
|
138
|
|
|
|
|
139
|
3 |
|
return $fields; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return array |
|
144
|
|
|
*/ |
|
145
|
3 |
|
public function rules() |
|
146
|
|
|
{ |
|
147
|
|
|
$rules = [ |
|
148
|
3 |
|
'name' => 'required|max:250', |
|
149
|
|
|
'user' => 'array|min:1', |
|
150
|
|
|
]; |
|
151
|
|
|
|
|
152
|
3 |
|
return $rules; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getRedirectUrl() |
|
159
|
|
|
{ |
|
160
|
|
|
if ($this->isEditing()) { |
|
161
|
|
|
return $this->getModel()->to('edit'); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
return 'projects/new'; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: