b_lxentries_new_edit()   F
last analyzed

Complexity

Conditions 12
Paths 2048

Size

Total Lines 36
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

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