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; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* GlobalIssue is a class to defines fields & rules for adding an issue form. |
18
|
|
|
* |
19
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class GlobalIssue extends Issue |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* List of projects. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $projects = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Returns list of logged in user projects. |
32
|
|
|
* |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
1 |
|
protected function getProjects() |
36
|
|
|
{ |
37
|
1 |
|
if (!$this->projects) { |
|
|
|
|
38
|
1 |
|
$this->projects = \Auth::user()->projects()->get()->lists('name', 'id'); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
return $this->projects; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param array $params |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
1 |
|
public function setup(array $params) |
50
|
|
|
{ |
51
|
1 |
|
$this->project = new Model\Project(); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
1 |
|
public function actions() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
1 |
|
'submit' => 'create_issue', |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
1 |
|
public function fields() |
68
|
|
|
{ |
69
|
1 |
|
$fields = $this->fieldTitle(); |
70
|
|
|
|
71
|
1 |
|
$fields['project'] = [ |
72
|
1 |
|
'type' => 'select', |
73
|
1 |
|
'label' => 'project', |
74
|
1 |
|
'options' => $this->getProjects()->all(), |
|
|
|
|
75
|
|
|
]; |
76
|
|
|
|
77
|
1 |
|
$fields += $this->fieldBody(); |
78
|
|
|
|
79
|
1 |
|
$fields += $this->fieldTypeTags(); |
80
|
|
|
|
81
|
|
|
// Only on creating new issue |
82
|
1 |
|
$fields += $this->fieldUpload(); |
83
|
|
|
|
84
|
1 |
|
return $fields; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
1 |
|
public function rules() |
91
|
|
|
{ |
92
|
1 |
|
$rules = parent::rules(); |
93
|
1 |
|
$rules['project'] = 'required|in:' . $this->getProjects()->keys()->implode(','); |
|
|
|
|
94
|
|
|
|
95
|
1 |
|
return $rules; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getRedirectUrl() |
102
|
|
|
{ |
103
|
|
|
return 'projects/new-issue'; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.