Completed
Push — master ( 6c5294...348995 )
by Michael
02:27
created

faqs_recent_questions.php ➔ b_faqs_recent_questions_show()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 44
Code Lines 27

Duplication

Lines 23
Ratio 52.27 %

Importance

Changes 0
Metric Value
cc 7
eloc 27
nc 4
nop 1
dl 23
loc 44
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
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
11
12
function b_faqs_recent_questions_show($options)
13
{
14
    include_once(XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php');
15
16
    $block = array();
17
18 View Code Duplication
    if ($options[0] == 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
        $categoryid = -1;
20
    } else {
21
        $categoryid = $options[0];
22
    }
23
24
    $sort              = $options[1];
25
    $limit             = $options[2];
26
    $maxQuestionLength = $options[3];
27
28
    // Creating the faq handler object
29
    $faqHandler = sf_gethandler('faq');
30
31
    // creating the FAQ objects that belong to the selected category
32
    $faqsObj   = $faqHandler->getFaqs($limit, 0, _SF_STATUS_OPENED, $categoryid, $sort);
33
    $totalfaqs = count($faqsObj);
34
35 View Code Duplication
    if ($faqsObj) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
        for ($i = 0; $i < $totalfaqs; ++$i) {
37
            $newfaqs = array();
38
39
            $newfaqs['linktext'] = $faqsObj[$i]->question($maxQuestionLength);
40
            $newfaqs['id']       = $faqsObj[$i]->faqid();
41
            if ($sort === 'datesub') {
42
                $newfaqs['new'] = $faqsObj[$i]->datesub();
43
            } elseif ($sort === 'counter') {
44
                $newfaqs['new'] = $faqsObj[$i]->counter();
45
            } elseif ($sort === 'weight') {
46
                $newfaqs['new'] = $faqsObj[$i]->weight();
47
            }
48
49
            $block['newfaqs'][] = $newfaqs;
50
        }
51
        $block['lang_allunanswered'] = _MB_SF_ALLUNANSWERED;
52
    }
53
54
    return $block;
55
}
56
57
/**
58
 * @param $options
59
 * @return string
60
 */
61
function b_faqs_recent_questions_edit($options)
62
{
63
    include_once(XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php');
64
65
    $form = sf_createCategorySelect($options[0]);
66
67
    $form .= '&nbsp;<br>' . _MB_SF_ORDER . "&nbsp;<select name='options[]'>";
68
69
    $form .= "<option value='datesub'";
70
    if ($options[1] === 'datesub') {
71
        $form .= " selected='selected'";
72
    }
73
    $form .= '>' . _MB_SF_DATE . "</option>\n";
74
75
    $form .= "<option value='counter'";
76
    if ($options[1] === 'counter') {
77
        $form .= " selected='selected'";
78
    }
79
    $form .= '>' . _MB_SF_HITS . "</option>\n";
80
81
    $form .= "<option value='weight'";
82
    if ($options[1] === 'weight') {
83
        $form .= " selected='selected'";
84
    }
85
    $form .= '>' . _MB_SF_WEIGHT . "</option>\n";
86
87
    $form .= "</select>\n";
88
89
    $form .= '&nbsp;' . _MB_SF_DISP . "&nbsp;<input type='text' name='options[]' value='" . $options[2] . "' />&nbsp;" . _MB_SF_QUESTIONS . '';
90
    $form .= '&nbsp;<br>' . _MB_SF_CHARS . "&nbsp;<input type='text' name='options[]' value='" . $options[3] . "' />&nbsp;" . _MB_SF_LENGTH . '';
91
92
    $form .= '<br />' . _MB_SF_SHOW_DATE . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
93
    if ($options[4] == 1) {
94
        $form .= " checked='checked'";
95
    }
96
    $form .= ' />&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
97
    if ($options[4] == 0) {
98
        $form .= " checked='checked'";
99
    }
100
    $form .= ' />&nbsp;' . _NO . '';
101
102
    return $form;
103
}
104