Test Failed
Push — master ( 398493...d4ef72 )
by Michael
11:04
created

SystemGroup::getForm()   F

Complexity

Conditions 12
Paths 576

Size

Total Lines 142
Code Lines 109

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 109
nc 576
nop 1
dl 0
loc 142
rs 2.6273
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 20.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Group class manager
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @author              Gregory Mage (AKA Mage)
15
 * @package             system
16
 */
17
18
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
19
20
include_once XOOPS_ROOT_PATH . '/kernel/group.php';
21
22
/**
23
 * System Group
24
 *
25
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
26
 * @package             system
27
 */
28
class SystemGroup extends XoopsGroup
29
{
30
    /**
31
     *
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * @param bool $action
40
     *
41
     * @return XoopsThemeForm
42
     */
43
    public function getForm($action = false)
44
    {
45
        if ($action === false) {
46
            $action = $_SERVER['REQUEST_URI'];
47
        }
48
49
        if ($this->isNew()) {
50
            $s_cat_value   = '';
51
            $a_mod_value   = array();
52
            $r_mod_value   = array();
53
            $r_block_value = array();
54
        } else {
55
            /* @var $sysperm_handler XoopsGroupPermHandler  */
56
            $sysperm_handler    = xoops_getHandler('groupperm');
57
            $s_cat_value        = $sysperm_handler->getItemIds('system_admin', $this->getVar('groupid'));
58
            /* @var $member_handler XoopsMemberHandler */
59
            $member_handler     = xoops_getHandler('member');
60
            $thisgroup          = $member_handler->getGroup($this->getVar('groupid'));
61
            /* @var $moduleperm_handler XoopsGroupPermHandler  */
62
            $moduleperm_handler = xoops_getHandler('groupperm');
63
            $a_mod_value        = $moduleperm_handler->getItemIds('module_admin', $thisgroup->getVar('groupid'));
64
            $r_mod_value        = $moduleperm_handler->getItemIds('module_read', $thisgroup->getVar('groupid'));
65
            /* @var  $gperm_handler XoopsGroupPermHandler */
66
            $gperm_handler      = xoops_getHandler('groupperm');
67
            $r_block_value      = $gperm_handler->getItemIds('block_read', $this->getVar('groupid'));
68
        }
69
        xoops_load('XoopsFormLoader');
70
        xoops_load('XoopsLists');
71
        include_once XOOPS_ROOT_PATH . '/modules/system/constants.php';
72
73
        $title = $this->isNew() ? sprintf(_AM_SYSTEM_GROUPS_ADD) : sprintf(_AM_SYSTEM_GROUPS_EDIT);
74
        $form  = new XoopsThemeForm($title, 'groupform', $action, 'post', true);
75
        $form->setExtra('enctype="multipart/form-data"');
76
77
        $name_text = new XoopsFormText(_AM_SYSTEM_GROUPS_NAME, 'name', 30, 50, $this->getVar('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

77
        $name_text = new XoopsFormText(_AM_SYSTEM_GROUPS_NAME, 'name', 30, 50, /** @scrutinizer ignore-type */ $this->getVar('name'));
Loading history...
78
        $desc_text = new XoopsFormTextArea(_AM_SYSTEM_GROUPS_DESCRIPTION, 'desc', $this->getVar('description'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('description') can also be of type array and array; however, parameter $value of XoopsFormTextArea::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

78
        $desc_text = new XoopsFormTextArea(_AM_SYSTEM_GROUPS_DESCRIPTION, 'desc', /** @scrutinizer ignore-type */ $this->getVar('description'));
Loading history...
79
80
        $system_catids = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_SYSTEMRIGHTS, '');
81
82
        $s_cat_checkbox_all = new XoopsFormCheckBox('', 'catbox', 1);
83
        $s_cat_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
84
        $s_cat_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"catbox\" , \"system_catids[]\");' ");
85
        $s_cat_checkbox_all->setClass('xo-checkall');
86
        $system_catids->addElement($s_cat_checkbox_all);
87
88
        $s_cat_checkbox          = new XoopsFormCheckBox('', 'system_catids', $s_cat_value);
89
        $s_cat_checkbox->columns = 6;
90
        $admin_dir               = XOOPS_ROOT_PATH . '/modules/system/admin/';
91
        $dirlist                 = XoopsLists::getDirListAsArray($admin_dir);
92
        foreach ($dirlist as $file) {
93
            include XOOPS_ROOT_PATH . '/modules/system/admin/' . $file . '/xoops_version.php';
94
            if (!empty($modversion['category'])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modversion seems to never exist and therefore empty should always be true.
Loading history...
95
                if (xoops_getModuleOption('active_' . $file, 'system') == 1) {
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

95
                if (/** @scrutinizer ignore-deprecated */ xoops_getModuleOption('active_' . $file, 'system') == 1) {
Loading history...
96
                    $s_cat_checkbox->addOption($modversion['category'], $modversion['name']);
97
                }
98
            }
99
            unset($modversion);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modversion seems to be never defined.
Loading history...
100
        }
101
        unset($dirlist);
102
        $system_catids->addElement($s_cat_checkbox);
103
104
        $admin_mids = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_ACTIVERIGHTS, '');
105
106
        $s_admin_checkbox_all = new XoopsFormCheckBox('', 'adminbox', 1);
107
        $s_admin_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
108
        $s_admin_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"adminbox\" , \"admin_mids[]\");' ");
109
        $s_admin_checkbox_all->setClass('xo-checkall');
110
        $admin_mids->addElement($s_admin_checkbox_all);
111
112
        $a_mod_checkbox          = new XoopsFormCheckBox('', 'admin_mids[]', $a_mod_value);
113
        $a_mod_checkbox->columns = 5;
114
        /* @var $module_handler XoopsModuleHandler */
115
        $module_handler          = xoops_getHandler('module');
116
        $criteria                = new CriteriaCompo(new Criteria('hasadmin', 1));
117
        $criteria->add(new Criteria('isactive', 1));
118
        $criteria->add(new Criteria('dirname', 'system', '<>'));
119
        $a_mod_checkbox->addOptionArray($module_handler->getList($criteria));
120
        $admin_mids->addElement($a_mod_checkbox);
121
122
        $read_mids = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_ACCESSRIGHTS, '');
123
124
        $s_mod_checkbox_all = new XoopsFormCheckBox('', 'readbox', 1);
125
        $s_mod_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
126
        $s_mod_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"readbox\" , \"read_mids[]\");' ");
127
        $s_mod_checkbox_all->setClass('xo-checkall');
128
        $read_mids->addElement($s_mod_checkbox_all);
129
130
        $r_mod_checkbox          = new XoopsFormCheckBox('', 'read_mids[]', $r_mod_value);
131
        $r_mod_checkbox->columns = 5;
132
        $criteria                = new CriteriaCompo(new Criteria('hasmain', 1));
133
        $criteria->add(new Criteria('isactive', 1));
134
        $r_mod_checkbox->addOptionArray($module_handler->getList($criteria));
135
        $read_mids->addElement($r_mod_checkbox);
136
137
        $criteria = new CriteriaCompo(new Criteria('isactive', 1));
138
        $criteria->setSort('mid');
139
        $criteria->setOrder('ASC');
140
        $module_list    = $module_handler->getList($criteria);
141
        $module_list[0] = _AM_SYSTEM_GROUPS_CUSTOMBLOCK;
142
        /* @var $block_handler XoopsBlockHandler */
143
        $block_handler = xoops_getHandler('block');
144
        $blocks_obj    = $block_handler->getObjects(new Criteria('mid', "('" . implode("', '", array_keys($module_list)) . "')", 'IN'), true);
145
146
        $blocks_module = array();
147
        foreach (array_keys($blocks_obj) as $bid) {
148
            $title                                                                             = $blocks_obj[$bid]->getVar('title');
149
            $blocks_module[$blocks_obj[$bid]->getVar('mid')][$blocks_obj[$bid]->getVar('bid')] = empty($title) ? $blocks_obj[$bid]->getVar('name') : $title;
150
        }
151
        ksort($blocks_module);
152
153
        $r_block_tray   = new XoopsFormElementTray(_AM_SYSTEM_GROUPS_BLOCKRIGHTS, '<br><br>');
154
        $s_checkbox_all = new XoopsFormCheckBox('', 'blocksbox', 1);
155
        $s_checkbox_all->addOption('allbox', _AM_SYSTEM_ALL);
156
        $s_checkbox_all->setExtra(" onclick='xoopsCheckGroup(\"groupform\", \"blocksbox\" , \"read_bids[]\");' ");
157
        $s_checkbox_all->setClass('xo-checkall');
158
        $r_block_tray->addElement($s_checkbox_all);
159
        foreach (array_keys($blocks_module) as $mid) {
160
            $new_blocks_array = array();
161
            foreach ($blocks_module[$mid] as $key => $value) {
162
                $new_blocks_array[$key] = "<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&amp;op=edit&amp;bid={$key}' title='ID: {$key}' rel='external'>{$value}</a>";
163
            }
164
            $r_block_checkbox          = new XoopsFormCheckBox('<strong>' . $module_list[$mid] . '</strong><br>', 'read_bids[]', $r_block_value);
165
            $r_block_checkbox->columns = 5;
166
            $r_block_checkbox->addOptionArray($new_blocks_array);
167
            $r_block_tray->addElement($r_block_checkbox);
168
            unset($r_block_checkbox);
169
        }
170
        if (!$this->isNew()) {
171
            $form->addElement(new XoopsFormHidden('g_id', $this->getVar('groupid')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('groupid') can also be of type array and array; however, parameter $value of XoopsFormHidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

171
            $form->addElement(new XoopsFormHidden('g_id', /** @scrutinizer ignore-type */ $this->getVar('groupid')));
Loading history...
172
            $form->addElement(new XoopsFormHidden('op', 'groups_save_update'));
173
        } else {
174
            $form->addElement(new XoopsFormHidden('op', 'groups_save_add'));
175
        }
176
        $form->addElement($name_text, true);
177
        $form->addElement($desc_text);
178
        $form->addElement($system_catids);
179
        $form->addElement($admin_mids);
180
        $form->addElement($read_mids);
181
        $form->addElement($r_block_tray);
182
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
183
184
        return $form;
185
    }
186
}
187
188
/**
189
 * System group handler class. (Singelton)
190
 *
191
 * This class is responsible for providing data access mechanisms to the data source
192
 * of XOOPS block class objects.
193
 *
194
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
195
 * @package             system
196
 * @subpackage          avatar
197
 */
198
class SystemGroupHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
199
{
200
    /**
201
     * @param null|XoopsDatabase $db
202
     */
203
    public function __construct(XoopsDatabase $db)
204
    {
205
        parent::__construct($db, 'groups', 'SystemGroup', 'groupid', 'name');
206
    }
207
}
208