Passed
Branch master (4e30dc)
by Michael
02:20
created

faqs_new.php ➔ b_faqs_new_show()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 41
Code Lines 25

Duplication

Lines 41
Ratio 100 %

Importance

Changes 0
Metric Value
cc 7
eloc 25
nc 4
nop 1
dl 41
loc 41
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 * @param $options
8
 * @return array
9
 */
10
11
use XoopsModules\Smartfaq;
12
13
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
14
15
/**
16
 * @param $options
17
 * @return array
18
 */
19
function b_faqs_new_show($options)
20
{
21
//    require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php';
22
23
    $block = [];
24
25
    if (0 == $options[0]) {
26
        $categoryid = -1;
27
    } else {
28
        $categoryid = $options[0];
29
    }
30
31
    $sort              = $options[1];
32
    $limit             = $options[2];
33
    $maxQuestionLength = $options[3];
34
35
    // Creating the faq handler object
36
    /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
37
    $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
38
    // creating the FAQ objects that belong to the selected category
39
    $faqsObj   = $faqHandler->getAllPublished($limit, 0, $categoryid, $sort);
40
41
    if ($faqsObj) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $faqsObj of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
42
        foreach ($faqsObj as $iValue) {
43
            $newfaqs             = [];
44
            $newfaqs['linktext'] = $iValue->question($maxQuestionLength);
45
            $newfaqs['id']       = $iValue->faqid();
46
            if ('datesub' === $sort) {
47
                $newfaqs['new'] = $iValue->datesub();
48
            } elseif ('counter' === $sort) {
49
                $newfaqs['new'] = $iValue->counter();
50
            } elseif ('weight' === $sort) {
51
                $newfaqs['new'] = $iValue->weight();
52
            }
53
            $newfaqs['show_date'] = $options[4];
54
            $block['newfaqs'][]   = $newfaqs;
55
        }
56
    }
57
58
    return $block;
59
}
60
61
/**
62
 * @param $options
63
 * @return string
64
 */
65
function b_faqs_new_edit($options)
66
{
67
    global $xoopsDB, $xoopsModule, $xoopsUser;
68
//    require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php';
69
70
    $form = Smartfaq\Utility::createCategorySelect($options[0]);
71
72
    $form .= '&nbsp;<br>' . _MB_SF_ORDER . "&nbsp;<select name='options[]'>";
73
74
    $form .= "<option value='datesub'";
75
    if ('datesub' === $options[1]) {
76
        $form .= ' selected';
77
    }
78
    $form .= '>' . _MB_SF_DATE . "</option>\n";
79
80
    $form .= "<option value='counter'";
81
    if ('counter' === $options[1]) {
82
        $form .= ' selected';
83
    }
84
    $form .= '>' . _MB_SF_HITS . "</option>\n";
85
86
    $form .= "<option value='weight'";
87
    if ('weight' === $options[1]) {
88
        $form .= ' selected';
89
    }
90
    $form .= '>' . _MB_SF_WEIGHT . "</option>\n";
91
92
    $form .= "</select>\n";
93
94
    $form .= '&nbsp;' . _MB_SF_DISP . "&nbsp;<input type='text' name='options[]' value='" . $options[2] . "'>&nbsp;" . _MB_SF_FAQS . '';
95
    $form .= '&nbsp;<br>' . _MB_SF_CHARS . "&nbsp;<input type='text' name='options[]' value='" . $options[3] . "'>&nbsp;" . _MB_SF_LENGTH . '';
96
97
    $form .= '<br>' . _MB_SF_SHOW_DATE . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
98
    if (1 == $options[4]) {
99
        $form .= ' checked';
100
    }
101
    $form .= '>&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
102
    if (0 == $options[4]) {
103
        $form .= ' checked';
104
    }
105
    $form .= '>&nbsp;' . _NO . '';
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
106
107
    return $form;
108
}
109