PreferencesForm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 76
c 0
b 0
f 0
dl 0
loc 136
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 110 5
1
<?php
2
3
namespace XoopsModules\Xooghost\Form;
4
5
/**
6
 * Xooghost module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xooghost
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
 */
21
22
/**
23
 * Class PreferencesForm
24
 */
25
class PreferencesForm extends \Xoops\Form\ThemeForm
26
{
27
    private $colors = [
0 ignored issues
show
introduced by
The private property $colors is not used, and could be removed.
Loading history...
28
        'Aqua' => '#00FFFF',
29
        'Black' => '#000000',
30
        'Blue' => '#0000FF',
31
        'Fuchsia' => '#FF00FF',
32
        'Gray' => '#808080',
33
        'Green' => '#008000',
34
        'Lime' => '#00FF00',
35
        'Maroon' => '#800000',
36
        'Navy' => '#000080',
37
        'Olive' => '#808000',
38
        'Purple' => '#800080',
39
        'Red' => '#FF0000',
40
        'Silver' => '#C0C0C0',
41
        'Teal' => '#008080',
42
        'White' => '#FFFFFF',
43
        'Yellow' => '#FFFF00',
44
    ];
45
46
    private $config = [];
47
48
    /**
49
     * @internal param null $obj
50
     */
51
    public function __construct()
52
    {
53
        $this->config = \XoopsModules\Xooghost\Preferences::getInstance()->loadConfig();
54
55
        extract($this->config);
56
        parent::__construct('', 'form_preferences', 'preferences.php', 'post', true);
57
        $this->setExtra('enctype="multipart/form-data"');
58
59
        $tabTray = new \Xoops\Form\TabTray('', 'uniqueid');
60
61
        /**
62
         * Main page
63
         */
64
        $tab1 = new \Xoops\Form\Tab(_XOO_CONFIG_MAINPAGE, 'tabid-1');
65
        //xooghost_main
66
        $tab1->addElement(new \Xoops\Form\RadioYesNo(_XOO_CONFIG_MAIN, 'xooghost_main', $xooghost_main));
67
68
        //xooghost_welcome
69
        $tab1->addElement(new \Xoops\Form\TextArea(_XOO_CONFIG_WELCOME, 'xooghost_welcome', $xooghost_welcome, 12, 12));
70
71
        //xooghost_main_mode
72
        $main_mode = new \Xoops\Form\Select(_XOO_CONFIG_MAIN_MODE, 'xooghost_main_mode', $xooghost_main_mode, $size = 1);
73
        $main_mode->addOption('blog', _XOO_CONFIG_MAIN_MODE_BLOG);
74
        $main_mode->addOption('list', _XOO_CONFIG_MAIN_MODE_LIST);
75
        $main_mode->addOption('select', _XOO_CONFIG_MAIN_MODE_SELECT);
76
        $main_mode->addOption('table', _XOO_CONFIG_MAIN_MODE_TABLE);
77
        $tab1->addElement($main_mode);
78
79
        // limit per page
80
        $tab1->addElement(new \Xoops\Form\Text(_XOO_CONFIG_LIMIT_MAIN, 'xooghost_limit_main', 1, 10, $xooghost_limit_main));
81
82
        // date format
83
        $main_mode = new \Xoops\Form\Select(_XOO_CONFIG_DATE_FORMAT, 'xooghost_date_format', $xooghost_date_format, $size = 1);
84
85
        try {
86
            $main_mode->addOption('_DATESTRING', \Xoops\Core\Locale\Time::formatDateTime(new \DateTime('now'), 'long'));
87
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
88
        }
89
90
        try {
91
            $main_mode->addOption('_MEDIUMDATESTRING', \Xoops\Core\Locale\Time::formatDateTime(new \DateTime('now'), 'medium'));
92
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
93
        }
94
95
        try {
96
            $main_mode->addOption('_SHORTDATESTRING', \Xoops\Core\Locale\Time::formatDateTime(new \DateTime('now'), 'short'));
97
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
98
        }
99
100
        $tab1->addElement($main_mode);
101
102
        $tabTray->addElement($tab1);
103
104
        /**
105
         * Images
106
         */
107
        $tab2 = new \Xoops\Form\Tab(_XOO_CONFIG_IMAGE, 'tabid-2');
108
        // xooghost_image_size
109
        $tab2->addElement(new \Xoops\Form\Text(_XOO_GHOST_CONFIG_IMAGE_SIZE, 'xooghost_image_size', 1, 10, $xooghost_image_size));
110
111
        // xooghost_image_width
112
        $tab2->addElement(new \Xoops\Form\Text(_XOO_GHOST_CONFIG_IMAGE_WIDTH, 'xooghost_image_width', 1, 10, $xooghost_image_width));
113
114
        // xooghost_image_height
115
        $tab2->addElement(new \Xoops\Form\Text(_XOO_GHOST_CONFIG_IMAGE_HEIGHT, 'xooghost_image_height', 1, 10, $xooghost_image_height));
116
117
        $tabTray->addElement($tab2);
118
119
        /**
120
         * Rate / Like - Dislike
121
         */
122
        $rld = new \Xoops\Form\Tab(_XOO_CONFIG_RLD, 'tabid-rld');
123
124
        // Rate / Like / Dislike Mode
125
        $rld_mode = new \Xoops\Form\Select(_XOO_CONFIG_RLD_MODE, 'xooghost_rld[rld_mode]', $xooghost_rld['rld_mode']);
126
        $rld_mode->addOption('none', _XOO_CONFIG_RLD_NONE);
127
        $rld_mode->addOption('rate', _XOO_CONFIG_RLD_RATE);
128
        $rld_mode->addOption('likedislike', _XOO_CONFIG_RLD_LIKEDISLIKE);
129
        $rld->addElement($rld_mode);
130
131
        $rate_scale = new \Xoops\Form\Select(_XOO_CONFIG_RATE_SCALE, 'xooghost_rld[rate_scale]', $xooghost_rld['rate_scale']);
132
        for ($i = 4; $i <= 10; ++$i) {
133
            $rate_scale->addOption($i, $i);
134
        }
135
        $rld->addElement($rate_scale);
136
137
        $tabTray->addElement($rld);
138
139
        $this->addElement($tabTray);
140
141
        /**
142
         * Buttons
143
         */
144
        $buttonTray = new \Xoops\Form\ElementTray('', '');
145
        $buttonTray->addElement(new \Xoops\Form\Hidden('op', 'save'));
146
147
        $buttonSubmit = new \Xoops\Form\Button('', 'submit', \XoopsLocale::A_SUBMIT, 'submit');
148
        $buttonSubmit->setClass('btn btn-success');
149
        $buttonTray->addElement($buttonSubmit);
150
151
        $buttonReset = new \Xoops\Form\Button('', 'reset', \XoopsLocale::A_RESET, 'reset');
152
        $buttonReset->setClass('btn btn-warning');
153
        $buttonTray->addElement($buttonReset);
154
155
        $buttonCancel = new \Xoops\Form\Button('', 'cancel', \XoopsLocale::A_CANCEL, 'button');
156
        $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

156
        /** @scrutinizer ignore-deprecated */ $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
157
        $buttonCancel->setClass('btn btn-danger');
158
        $buttonTray->addElement($buttonCancel);
159
160
        $this->addElement($buttonTray);
161
    }
162
}
163