Completed
Branch develop (a31570)
by Mohamed
08:09 queued 04:45
created

Settings::actions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
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
    public function actions()
34
    {
35
        return [
36
            'submit' => 'update_settings',
37
        ];
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function fields()
44
    {
45
        $fields = [];
46
47
        $settings = Model\Settings::all();
48
        foreach ($settings as $setting) {
49
            $method = camel_case('field_' . $setting->key);
50
            $fields[$setting->key] = $this->{$method}($setting);
51
        }
52
53
        return $fields;
54
    }
55
56
    /**
57
     * Select enable/disable for public projects
58
     *
59
     * @param Model\Settings $setting
60
     * @return array
61
     */
62
    protected function fieldEnablePublicProjects(Model\Settings $setting)
63
    {
64
        return [
65
            'type'    => 'select',
66
            'label'   => $setting->name,
67
            'value'   => $setting->value,
68
            'options' => [Model\Settings::ENABLE => trans('tinyissue.enable'), Model\Settings::DISABLE => trans('tinyissue.disable')],
69
        ];
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    public function rules()
76
    {
77
        $rules = [
78
        ];
79
80
        return $rules;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getRedirectUrl()
87
    {
88
        return 'administration/settings';
89
    }
90
}
91