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
|
|
|
* Settings is a class to defines fields & rules for editing system settings. |
18
|
|
|
* |
19
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Settings extends FormAbstract |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* An instance of project model. |
25
|
|
|
* |
26
|
|
|
* @var Model\Settings |
27
|
|
|
*/ |
28
|
|
|
protected $settings; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
1 |
|
public function actions() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
1 |
|
'submit' => 'save', |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
1 |
|
public function fields() |
44
|
|
|
{ |
45
|
1 |
|
$fields = []; |
46
|
|
|
|
47
|
1 |
|
$settingsManager = app('tinyissue.settings'); |
48
|
1 |
|
foreach ($settingsManager as $setting) { |
49
|
1 |
|
$method = camel_case('field_' . $setting->key); |
50
|
1 |
|
$fields[$setting->key] = $this->{$method}($setting); |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
return $fields; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Select enable/disable for public projects. |
58
|
|
|
* |
59
|
|
|
* @param Model\Setting $setting |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
1 |
|
protected function fieldEnablePublicProjects(Model\Setting $setting) |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
1 |
|
'type' => 'select', |
67
|
1 |
|
'label' => $setting->name, |
68
|
1 |
|
'value' => $setting->value, |
69
|
1 |
|
'options' => [Model\Setting::ENABLE => trans('tinyissue.enable'), Model\Setting::DISABLE => trans('tinyissue.disable')], |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Select enable/disable for public projects. |
75
|
|
|
* |
76
|
|
|
* @param Model\Setting $setting |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
1 |
|
protected function fieldDateFormat(Model\Setting $setting) |
81
|
|
|
{ |
82
|
1 |
|
$today = new \DateTime(); |
83
|
1 |
|
$today = $today->format('Y-m-d H:i:s'); |
84
|
|
|
|
85
|
|
|
return [ |
86
|
1 |
|
'type' => 'select', |
87
|
1 |
|
'label' => 'date_format', |
88
|
1 |
|
'value' => $setting->value, |
89
|
|
|
'options' => [ |
90
|
1 |
|
'D, d M Y H:i:s' => \Html::date($today, 'D, d M Y H:i:s'), |
91
|
1 |
|
'F jS, Y, g:i a' => \Html::date($today, 'F jS, Y, g:i a'), |
92
|
1 |
|
'd/F/Y g:i A' => \Html::date($today, 'd/F/Y g:i A'), |
93
|
1 |
|
'd. F Y H:i' => \Html::date($today, 'd. F Y H:i'), |
94
|
1 |
|
'Y-m-d H:i' => \Html::date($today, 'Y-m-d H:i'), |
95
|
1 |
|
'd.m.y H:i' => \Html::date($today, 'd.m.y H:i'), |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Select status tag for default first status. |
102
|
|
|
* |
103
|
|
|
* @param Model\Setting $setting |
104
|
|
|
* |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
1 |
|
protected function fieldFirstStatusTag(Model\Setting $setting) |
108
|
|
|
{ |
109
|
|
|
return [ |
110
|
1 |
|
'type' => 'select', |
111
|
1 |
|
'label' => 'first_status_tag', |
112
|
1 |
|
'value' => $setting->value, |
113
|
1 |
|
'options' => (new Model\Tag())->getStatusTags()->get()->lists('fullname', 'id'), |
|
|
|
|
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Select default language. |
119
|
|
|
* |
120
|
|
|
* @param Model\Setting $setting |
121
|
|
|
* |
122
|
|
|
* @return array |
123
|
|
|
*/ |
124
|
1 |
|
protected function fieldLanguage(Model\Setting $setting) |
125
|
|
|
{ |
126
|
|
|
return [ |
127
|
1 |
|
'type' => 'select', |
128
|
1 |
|
'label' => 'language', |
129
|
1 |
|
'value' => $setting->value, |
130
|
1 |
|
'options' => Model\User::getLanguages(), |
131
|
|
|
]; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
1 |
|
public function rules() |
138
|
|
|
{ |
139
|
|
|
$rules = [ |
140
|
1 |
|
]; |
141
|
|
|
|
142
|
1 |
|
return $rules; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getRedirectUrl() |
149
|
|
|
{ |
150
|
|
|
return 'administration/settings'; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks for function calls that miss required arguments.