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 Request; |
15
|
|
|
use Tinyissue\Model; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* FilterIssue is a class to defines fields & rules for issue filter form. |
19
|
|
|
* |
20
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class FilterIssue extends FormAbstract |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* An instance of project model. |
26
|
|
|
* |
27
|
|
|
* @var Model\Project |
28
|
|
|
*/ |
29
|
|
|
protected $project; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Collection of all tags. |
33
|
|
|
* |
34
|
|
|
* @var \Illuminate\Database\Eloquent\Collection |
35
|
|
|
*/ |
36
|
|
|
protected $tags = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $type |
40
|
|
|
* |
41
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|null |
42
|
|
|
*/ |
43
|
29 |
View Code Duplication |
protected function getTags($type = null) |
|
|
|
|
44
|
|
|
{ |
45
|
29 |
|
if ($this->tags === null) { |
46
|
29 |
|
$this->tags = (new Model\Tag())->getGroupTags(); |
47
|
|
|
} |
48
|
|
|
|
49
|
29 |
|
if ($type) { |
|
|
|
|
50
|
29 |
|
return $this->tags->where('name', $type)->first()->tags; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->tags; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array $params |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
36 |
|
public function setup(array $params) |
62
|
|
|
{ |
63
|
36 |
|
$this->project = $params['project']; |
64
|
36 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
2 |
|
public function actions() |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
'filter' => [ |
73
|
|
|
'name' => 'filter', |
74
|
|
|
'label' => 'filter', |
75
|
|
|
'type' => 'info_submit', |
76
|
2 |
|
], |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
29 |
|
public function fields() |
84
|
|
|
{ |
85
|
|
|
// Prefix tag groups with "tag:" |
86
|
29 |
|
$tagGroups = (new Model\Tag())->groupsDropdown(); |
87
|
|
|
|
88
|
|
|
// Array of sort optins |
89
|
29 |
|
$sort = ['updated' => trans('tinyissue.updated')] + $tagGroups; |
90
|
|
|
|
91
|
|
|
// Array of project users |
92
|
29 |
|
$assignTo = [0 => trans('tinyissue.allusers')] + $this->project->users()->get()->lists('fullname', 'id')->all(); |
93
|
|
|
|
94
|
|
|
$fields = [ |
95
|
|
|
'keyword' => [ |
96
|
29 |
|
'type' => 'text', |
97
|
29 |
|
'placeholder' => trans('tinyissue.keywords'), |
98
|
29 |
|
'onGroupAddClass' => 'toolbar-item first', |
99
|
|
|
], |
100
|
|
|
'tag_status' => [ |
101
|
29 |
|
'type' => 'select', |
102
|
29 |
|
'placeholder' => trans('tinyissue.status'), |
103
|
29 |
|
'onGroupAddClass' => 'toolbar-item', |
104
|
29 |
|
'options' => $this->getTags('status')->lists('fullname', 'id'), |
105
|
|
|
], |
106
|
|
|
'tag_type' => [ |
107
|
29 |
|
'type' => 'select', |
108
|
29 |
|
'placeholder' => trans('tinyissue.type'), |
109
|
29 |
|
'onGroupAddClass' => 'toolbar-item', |
110
|
29 |
|
'options' => $this->getTags('type')->lists('fullname', 'id'), |
111
|
|
|
], |
112
|
|
|
'sort' => [ |
113
|
29 |
|
'type' => 'groupField', |
114
|
29 |
|
'onGroupAddClass' => 'toolbar-item', |
115
|
|
|
'fields' => [ |
116
|
|
|
'sortby' => [ |
117
|
29 |
|
'type' => 'select', |
118
|
29 |
|
'placeholder' => trans('tinyissue.sortby'), |
119
|
29 |
|
'options' => $sort, |
120
|
29 |
|
'onGroupClass' => 'control-inline control-sortby', |
121
|
|
|
], |
122
|
|
|
'sortorder' => [ |
123
|
29 |
|
'type' => 'select', |
124
|
29 |
|
'options' => ['asc' => trans('tinyissue.sort_asc'), 'desc' => trans('tinyissue.sort_desc')], |
125
|
29 |
|
'onGroupClass' => 'control-inline control-sortorder', |
126
|
|
|
], |
127
|
|
|
], |
128
|
|
|
], |
129
|
|
|
'assignto' => [ |
130
|
29 |
|
'type' => 'select', |
131
|
29 |
|
'placeholder' => trans('tinyissue.assigned_to'), |
132
|
29 |
|
'options' => $assignTo, |
133
|
29 |
|
'onGroupAddClass' => 'toolbar-item last', |
134
|
|
|
], |
135
|
|
|
]; |
136
|
|
|
|
137
|
29 |
|
return $fields; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getRedirectUrl() |
144
|
|
|
{ |
145
|
|
|
return $this->project->to(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
2 |
|
public function openType() |
152
|
|
|
{ |
153
|
2 |
|
return 'inline_open'; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.