b_arts_rated_edit()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 22
nc 16
nop 1
dl 0
loc 34
rs 9.2568
c 0
b 0
f 0
1
<?php
2
/**
3
 * Module: Soapbox
4
 * Author: hsalazar
5
 * Licence: GNU
6
 * @param $options
7
 * @return array
8
 */
9
10
use XoopsModules\Soapbox;
11
12
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
13
/**
14
 * @param $options
15
 * @return array|null
16
 */
17
function b_arts_rated($options)
18
{
19
    $myts          = \MyTextSanitizer:: getInstance();
20
    $helper        = \XoopsModules\Soapbox\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
21
    $block_outdata = [];
22
    $module_name   = 'soapbox';
23
    $moduleHandler = xoops_getHandler('module');
24
    $soapModule    = $moduleHandler->getByDirname($module_name);
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

24
    /** @scrutinizer ignore-call */ 
25
    $soapModule    = $moduleHandler->getByDirname($module_name);
Loading history...
25
    if (!is_object($soapModule)) {
26
        return null;
27
    }
28
    $hModConfig = xoops_getHandler('config');
29
    $module_id  = $soapModule->getVar('mid');
30
    $soapConfig = $hModConfig->getConfigsByCat(0, $module_id);
0 ignored issues
show
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

30
    /** @scrutinizer ignore-call */ 
31
    $soapConfig = $hModConfig->getConfigsByCat(0, $module_id);
Loading history...
31
    //-------------------------------------
32
    if (!in_array($options[0], ['datesub', 'weight', 'counter', 'rating', 'headline'], true)) {
33
        $options[0] = 'datesub';
34
    }
35
    $sortorder = 'DESC';
36
    if ('weight' === $options[0]) {
37
        $sortorder = 'ASC';
38
    }
39
    /** @var \XoopsModules\Soapbox\EntrygetHandler $entrydataHandler */
40
    $entrydataHandler = new \XoopsModules\Soapbox\EntrygetHandler();
41
    $entryobArray     = $entrydataHandler->getArticlesAllPermcheck((int)$options[1], 0, true, true, 0, 0, 1, $options[0], $sortorder, null, null, false, false);
42
    if (empty($entryobArray) || 0 === count($entryobArray)) {
43
        return $block_outdata;
44
    }
45
    //-------------------------------------
46
    foreach ($entryobArray as $_entryob) {
47
        if (is_object($_entryob)) {
48
            //-----------
49
            $newarts['linktext'] = xoops_substr($_entryob->getVar('headline'), 0, (int)$options[2]);
50
            $newarts['id']       = $_entryob->getVar('articleID');
51
            $newarts['dir']      = $module_name;
52
            $newarts['date']     = $myts->htmlSpecialChars(formatTimestamp($_entryob->getVar('datesub'), $soapConfig['dateformat']));
53
            if ('datesub' === $options[0]) {
54
                $newarts['new'] = $myts->htmlSpecialChars(formatTimestamp($_entryob->getVar('datesub'), $soapConfig['dateformat']));
55
            } elseif ('counter' === $options[0]) {
56
                $newarts['new'] = $_entryob->getVar('counter');
57
            } elseif ('weight' === $options[0]) {
58
                $newarts['new'] = $_entryob->getVar('weight');
59
            } elseif ('rating' === $options[0]) {
60
                $newarts['new']   = number_format($_entryob->getVar('rating'), 2, '.', '');
61
                $newarts['votes'] = $_entryob->getVar('votes');
62
            } else {
63
                $newarts['new'] = $myts->htmlSpecialChars(formatTimestamp($_entryob->getVar('datesub'), $soapConfig['dateformat']));
64
            }
65
            $block_outdata['artslist'][] = $newarts;
66
        }
67
    }
68
69
    return $block_outdata;
70
}
71
72
/**
73
 * @param $options
74
 * @return string
75
 */
76
function b_arts_rated_edit($options)
77
{
78
    $myts = \MyTextSanitizer:: getInstance();
79
    $form = '' . _MB_SOAPBOX_ORDER . "&nbsp;<select name='options[]'>";
80
81
    $form .= "<option value='datesub'";
82
    if ('datesub' === $options[0]) {
83
        $form .= ' selected';
84
    }
85
    $form .= '>' . _MB_SOAPBOX_DATE . "</option>\n";
86
87
    $form .= "<option value='counter'";
88
    if ('counter' === $options[0]) {
89
        $form .= ' selected';
90
    }
91
    $form .= '>' . _MB_SOAPBOX_HITS . "</option>\n";
92
93
    $form .= "<option value='weight'";
94
    if ('weight' === $options[0]) {
95
        $form .= ' selected';
96
    }
97
    $form .= '>' . _MB_SOAPBOX_WEIGHT . "</option>\n";
98
99
    $form .= "<option value='rating'";
100
    if ('rating' === $options[0]) {
101
        $form .= ' selected';
102
    }
103
    $form .= '>' . _MB_SOAPBOX_RATING . "</option>\n";
104
105
    $form .= "</select>\n";
106
    $form .= '&nbsp;' . _MB_SOAPBOX_DISP . "&nbsp;<input type='text' name='options[]' value='" . $myts->htmlSpecialChars($options[1]) . "'>&nbsp;" . _MB_SOAPBOX_ARTCLS . '';
107
    $form .= '&nbsp;<br>' . _MB_SOAPBOX_CHARS . "&nbsp;<input type='text' name='options[]' value='" . $myts->htmlSpecialChars($options[2]) . "'>&nbsp;" . _MB_SOAPBOX_LENGTH . '';
108
109
    return $form;
110
}
111