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

b_faqs_recent_questions_show()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 43
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 24
nc 4
nop 1
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
use XoopsModules\Smartfaq\Constants;
13
14
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
15
16
/**
17
 * @param $options
18
 * @return array
19
 */
20
function b_faqs_recent_questions_show($options)
21
{
22
//    require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php';
23
24
    $block = [];
25
26
    if (0 == $options[0]) {
27
        $categoryid = -1;
28
    } else {
29
        $categoryid = $options[0];
30
    }
31
32
    $sort              = $options[1];
33
    $limit             = $options[2];
34
    $maxQuestionLength = $options[3];
35
36
    // Creating the faq handler object
37
    /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
38
    $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
39
40
    // creating the FAQ objects that belong to the selected category
41
    $faqsObj   = $faqHandler->getFaqs($limit, 0, Constants::SF_STATUS_OPENED, $categoryid, $sort);
42
43
    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...
44
        foreach ($faqsObj as $iValue) {
45
            $newfaqs = [];
46
47
            $newfaqs['linktext'] = $iValue->question($maxQuestionLength);
48
            $newfaqs['id']       = $iValue->faqid();
49
            if ('datesub' === $sort) {
50
                $newfaqs['new'] = $iValue->datesub();
51
            } elseif ('counter' === $sort) {
52
                $newfaqs['new'] = $iValue->counter();
53
            } elseif ('weight' === $sort) {
54
                $newfaqs['new'] = $iValue->weight();
55
            }
56
57
            $block['newfaqs'][] = $newfaqs;
58
        }
59
        $block['lang_allunanswered'] = _MB_SF_ALLUNANSWERED;
60
    }
61
62
    return $block;
63
}
64
65
/**
66
 * @param $options
67
 * @return string
68
 */
69
function b_faqs_recent_questions_edit($options)
70
{
71
//    require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php';
72
73
    $form = Smartfaq\Utility::createCategorySelect($options[0]);
74
75
    $form .= '&nbsp;<br>' . _MB_SF_ORDER . "&nbsp;<select name='options[]'>";
76
77
    $form .= "<option value='datesub'";
78
    if ('datesub' === $options[1]) {
79
        $form .= ' selected';
80
    }
81
    $form .= '>' . _MB_SF_DATE . "</option>\n";
82
83
    $form .= "<option value='counter'";
84
    if ('counter' === $options[1]) {
85
        $form .= ' selected';
86
    }
87
    $form .= '>' . _MB_SF_HITS . "</option>\n";
88
89
    $form .= "<option value='weight'";
90
    if ('weight' === $options[1]) {
91
        $form .= ' selected';
92
    }
93
    $form .= '>' . _MB_SF_WEIGHT . "</option>\n";
94
95
    $form .= "</select>\n";
96
97
    $form .= '&nbsp;' . _MB_SF_DISP . "&nbsp;<input type='text' name='options[]' value='" . $options[2] . "'>&nbsp;" . _MB_SF_QUESTIONS . '';
98
    $form .= '&nbsp;<br>' . _MB_SF_CHARS . "&nbsp;<input type='text' name='options[]' value='" . $options[3] . "'>&nbsp;" . _MB_SF_LENGTH . '';
99
100
    $form .= '<br>' . _MB_SF_SHOW_DATE . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
101
    if (1 == $options[4]) {
102
        $form .= ' checked';
103
    }
104
    $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...
105
    if (0 == $options[4]) {
106
        $form .= ' checked';
107
    }
108
    $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...
109
110
    return $form;
111
}
112