b_lxentries_top_edit()   F
last analyzed

Complexity

Conditions 12
Paths 2048

Size

Total Lines 37
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 27
nc 2048
nop 1
dl 0
loc 37
rs 2.8
c 0
b 0
f 0

How to fix   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
2
3
/**
4
 * Module: Lexikon - glossary module
5
 * Author: hsalazar
6
 * Licence: GNU
7
 */
8
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
9
10
/**
11
 * @param $options
12
 * @return array
13
 */
14
function b_lxentries_top_show($options)
15
{
16
    global $xoopsDB, $xoopsUser;
17
    $myts = MyTextSanitizer:: getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
18
19
    /** @var \XoopsModuleHandler $moduleHandler */
20
    $moduleHandler = xoops_getHandler('module');
21
    $lexikon       = $moduleHandler->getByDirname('lexikon');
22
    if (!isset($lxConfig)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $lxConfig seems to never exist and therefore isset should always be false.
Loading history...
23
        /** @var \XoopsConfigHandler $configHandler */
24
        $configHandler = xoops_getHandler('config');
25
        $lxConfig      = $configHandler->getConfigsByCat(0, $lexikon->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
The assignment to $lxConfig is dead and can be removed.
Loading history...
26
    }
27
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
28
    /** @var \XoopsGroupPermHandler $grouppermHandler */
29
    $grouppermHandler = xoops_getHandler('groupperm');
30
    $module_id        = $lexikon->getVar('mid');
31
    $allowed_cats     = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id);
32
    $catids           = implode(',', $allowed_cats);
33
    $catperms         = " AND categoryID IN ($catids) ";
34
35
    $words      = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE offline = '0' AND submit='0' AND request='0' AND block = '1'");
36
    $totalwords = $xoopsDB->getRowsNum($words);
37
38
    $block                = [];
39
    $block['marquee']     = (1 == $options[2]) ? 1 : 0;
40
    $block['alternate']   = (1 == $options[3]) ? 1 : 0;
41
    $block['showcounter'] = (1 == $options[4]) ? 1 : 0;
42
    $block['direction']   = $options[5];
43
    $block['speed']       = isset($options[6]) && '' != $options[6] ? $options[6] : '2';
44
    $block['bgcolor']     = isset($options[7]) && '' != $options[7] ? $options[7] : '#FFFFFF';
45
46
    $sql    = 'SELECT entryID, categoryID, term, counter FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND offline = '0' " . $catperms . ' ORDER BY ' . $options[0] . ' DESC';
47
    $result = $xoopsDB->query($sql, $options[1], 0);
48
49
    if ($totalwords > 0) { // If there are definitions
50
        while (list($entryID, $categoryID, $term, $counter) = $xoopsDB->fetchRow($result)) {
51
            $popentries             = [];
52
            $linktext               = htmlspecialchars($term, ENT_QUOTES | ENT_HTML5);
53
            $popentries['dir']      = $lexikon->dirname();
54
            $popentries['linktext'] = $linktext;
55
            $popentries['id']       = (int)$entryID;
56
            $popentries['counter']  = (int)$counter;
57
58
            $block['popstuff'][] = $popentries;
59
        }
60
    }
61
62
    return $block;
63
}
64
65
/**
66
 * @param $options
67
 * @return string
68
 */
69
function b_lxentries_top_edit($options)
70
{
71
    $form = "<table width='100%' border='0'  class='bg2'>";
72
    $form .= "<tr><th width='50%'>" . _OPTIONS . "</th><th width='50%'>" . _MB_LEXIKON_SETTINGS . '</th></tr>';
73
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_ORDER . "</td><td class='odd'>";
74
    $form .= "&nbsp;<select name='options[0]'>";
75
    $form .= "<option value='datesub' " . (('datesub' === $options[0]) ? ' selected' : '') . '>' . _MB_LEXIKON_DATE . "</option>\n";
76
    $form .= "<option value='counter' " . (('counter' === $options[0]) ? ' selected' : '') . '>' . _MB_LEXIKON_HITS . "</option>\n";
77
    $form .= "<option value='term' " . (('term' === $options[0]) ? ' selected' : '') . '>' . _MB_LEXIKON_NAME . "</option>\n";
78
    $form .= '</select><br></td></tr>';
79
    //---
80
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_DISP . "</td><td class='odd'><input type='text' name='options[]' value='" . $options[1] . "' >&nbsp;" . _MB_LEXIKON_TERMS . '<br></td></tr>';
81
    //---
82
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_MARQUEE . "</td><td class='odd'>";
83
    $form .= "<input type='radio' name='options[2]' value='1'" . ((1 == $options[2]) ? ' checked' : '') . ' >' . _YES . '&nbsp;';
84
    $form .= "<input type='radio' name='options[2]' value='0'" . ((0 == $options[2]) ? ' checked' : '') . ' >' . _NO . '<br></td></tr>';
85
    //---
86
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_ALTERNATE . "</td><td class='odd'>";
87
    $form .= "<input type='radio' name='options[3]' value='1'" . ((1 == $options[3]) ? ' checked' : '') . ' >' . _YES . '&nbsp;';
88
    $form .= "<input type='radio' name='options[3]' value='0'" . ((0 == $options[3]) ? ' checked' : '') . ' >' . _NO . '<br></td></tr>';
89
    $form .= '</td></tr>';
90
    //---
91
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_SHOWCOUNT . "</td><td class='odd'>";
92
    $form .= "<input type='radio' name='options[4]' value='1'" . ((1 == $options[4]) ? ' checked' : '') . ' >' . _YES . '&nbsp;';
93
    $form .= "<input type='radio' name='options[4]' value='0'" . ((0 == $options[4]) ? ' checked' : '') . ' >' . _NO . '<br></td></tr>';
94
    //---
95
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_DIRECTION . "</td><td class='odd'><select name='options[5]'>";
96
    $form .= "<option value='up' " . (('up' === $options[5]) ? ' selected' : '') . '>' . _MB_LEXIKON_UP . "</option>\n";
97
    $form .= "<option value='down' " . (('down' === $options[5]) ? ' selected' : '') . '>' . _MB_LEXIKON_DOWN . "</option>\n";
98
    $form .= "</select></td></tr>\n";
99
    //---
100
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_BSPEED . "</td><td class='odd'><input type='text' name='options[6]' size='16' maxlength=2 value='" . $options[6] . "' ></td></tr>";
101
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_BACKGROUNDCOLOR . "</td><td class='odd'><input type='text' name='options[7]' size='16'  value='" . $options[7] . "' ></td></tr>";
102
    $form .= '</table>';
103
104
    //----
105
    return $form;
106
}
107