Passed
Push — master ( 84b92c...f405db )
by Michael
13:24
created

listBlocks()   F

Complexity

Conditions 22
Paths 3457

Size

Total Lines 226
Code Lines 177

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 177
c 1
b 0
f 0
dl 0
loc 226
rs 0
cc 22
nc 3457
nop 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 declare(strict_types=1);
2
3
/**
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 *
9
 * @category        Module
10
 * @author          XOOPS Development Team
11
 * @copyright       XOOPS Project (https://xoops.org)
12
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
13
 */
14
15
use Xmf\Module\Admin;
16
use Xmf\Request;
17
use XoopsModules\Smartfaq\{
18
    Common\Blocksadmin,
19
    Helper
20
};
21
22
/** @var Admin $adminObject */
23
/** @var Helper $helper */
24
25
require __DIR__ . '/admin_header.php';
26
xoops_cp_header();
27
28
$moduleDirName      = $helper->getDirname();
29
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
30
31
/** @var \XoopsMySQLDatabase $xoopsDB */
32
$xoopsDB     = \XoopsDatabaseFactory::getDatabaseConnection();
33
$blocksadmin = new Blocksadmin($xoopsDB, $helper);
34
35
$xoopsModule = XoopsModule::getByDirname($moduleDirName);
36
37
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
38
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
39
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
40
}
41
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
42
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
43
44
    $op = Request::getCmd('op', 'list');
45
    if (!empty($_POST)) {
46
        $ok             = Request::getInt('ok', 0, 'POST');
47
        $confirm_submit = Request::getCmd('confirm_submit', '', 'POST');
48
        $submit         = Request::getString('submit', '', 'POST');
49
        $bside          = Request::getString('bside', '0', 'POST');
50
        $bweight        = Request::getString('bweight', '0', 'POST');
51
        $bvisible       = Request::getString('bvisible', '0', 'POST');
52
        $bmodule        = Request::getArray('bmodule', [], 'POST');
53
        $btitle         = Request::getString('btitle', '', 'POST');
54
        $bcachetime     = Request::getString('bcachetime', '0', 'POST');
55
        $groups         = Request::getArray('groups', [], 'POST');
56
        $options        = Request::getArray('options', [], 'POST');
57
        $submitblock    = Request::getString('submitblock', '', 'POST');
58
        $fct            = Request::getString('fct', '', 'POST');
59
        $title          = Request::getString('title', '', 'POST');
60
        $side           = Request::getString('side', '0', 'POST');
61
        $weight         = Request::getString('weight', '0', 'POST');
62
        $visible        = Request::getString('visible', '0', 'POST');
63
    }
64
65
    if ('list' === $op) {
66
        //        xoops_cp_header();
67
        $blocksadmin->listBlocks();
68
        require_once __DIR__ . '/admin_footer.php';
69
        exit();
70
    }
71
72
    if (\in_array($op, ['edit', 'edit_ok', 'delete', 'delete_ok', 'clone', 'clone_ok'])) {
73
        $bid = Request::getInt('bid', 0);
74
        $ok  = Request::getInt('ok', 0);
75
76
        if ('clone' === $op) {
77
            $blocksadmin->cloneBlock($bid);
78
        }
79
80
        if ('delete' === $op) {
81
            if (1 === $ok) {
82
                //            if (!$GLOBALS['xoopsSecurity']->check()) {
83
                //                redirect_header($helper->url('admin/blocksadmin.php'), 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
84
                //            }
85
                $blocksadmin->deleteBlock($bid);
86
            } else {
87
                //            xoops_cp_header();
88
                xoops_confirm(['ok' => 1, 'op' => 'delete', 'bid' => $bid], 'blocksadmin.php', constant('CO_' . $moduleDirNameUpper . '_' . 'DELETE_BLOCK_CONFIRM'), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true);
89
                xoops_cp_footer();
90
            }
91
        }
92
93
        if ('edit' === $op) {
94
            $blocksadmin->editBlock($bid);
95
        }
96
97
        if ('edit_ok' === $op) {
98
            $blocksadmin->updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
99
        }
100
101
        if ('clone_ok' === $op) {
102
            $blocksadmin->isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
103
        }
104
    }
105
106
    if ('order' === $op) {
107
        $bid = Request::getArray('bid', []);
108
109
        $title      = Request::getArray('title', [], 'POST');
110
        $side       = Request::getArray('side', [], 'POST');
111
        $weight     = Request::getArray('weight', [], 'POST');
112
        $visible    = Request::getArray('visible', [], 'POST');
113
        $bcachetime = Request::getArray('bcachetime', [], 'POST');
114
        $bmodule    = Request::getArray('bmodule', [], 'POST');//mb
115
116
        $oldtitle      = Request::getArray('oldtitle', [], 'POST');
117
        $oldside       = Request::getArray('oldside', [], 'POST');
118
        $oldweight     = Request::getArray('oldweight', [], 'POST');
119
        $oldvisible    = Request::getArray('oldvisible', [], 'POST');
120
        $oldgroups     = Request::getArray('oldgroups', [], 'POST');
121
        $oldbcachetime = Request::getArray('oldcachetime', [], 'POST');
122
        $oldbmodule    = Request::getArray('oldbmodule', [], 'POST');//mb
123
124
        $blocksadmin->orderBlock(
125
            $bid,
126
            $oldtitle,
127
            $oldside,
128
            $oldweight,
129
            $oldvisible,
130
            $oldgroups,
131
            $oldbcachetime,
132
            $oldbmodule,
133
            $title,
134
            $weight,
135
            $visible,
136
            $side,
137
            $bcachetime,
138
            $groups,
139
            $bmodule
140
        );
141
    }
142
} else {
143
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
144
}
145
146
require __DIR__ . '/admin_footer.php';
147