Completed
Push — develop ( f089cf...86c33f )
by Mohamed
08:59 queued 02:24
created

Settings::fields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 2
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'),
0 ignored issues
show
Bug introduced by
The call to get() misses a required argument $key.

This check looks for function calls that miss required arguments.

Loading history...
114
        ];
115
    }
116
117
    /**
118
     * @return array
119
     */
120 1
    public function rules()
121
    {
122
        $rules = [
123 1
        ];
124
125 1
        return $rules;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function getRedirectUrl()
132
    {
133
        return 'administration/settings';
134
    }
135
}
136