xhp_block_courseranking.php ➔ b_XHP_courseranking_show()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 24
nc 2
nop 1
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
1
<?php
2
// $Id: xhp_block_courseranking.php 11919 2013-08-14 14:07:10Z beckmi $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://www.xoops.org/>                             //
7
// ------------------------------------------------------------------------- //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
28
// Variables //
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
29
// $options[0]: sorting order <DESC or ''> //
30
// $options[1]: num to list //
31
// $options[2]: avg threshold //
32
// $options[3]: sec_id //
33
// $options[4]: module dirname //
34
35
/**
36
 * @param $options
37
 * @return array
38
 */
39
function b_XHP_courseranking_show($options)
40
{
41
    global $xoopsDB, $xoopsUser, $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
42
    $myts      = MyTextSanitizer::getInstance();
43
    $block     = array();
44
    $mydirname = $options[4];
45
    $mymodpath = "modules/$mydirname";
46
    include "$mymodpath/module_prefix.php";
47
    $rsl    = $xoopsDB->prefix($module_prefix . '_results');
0 ignored issues
show
Bug introduced by
The variable $module_prefix does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
48
    $qiz    = $xoopsDB->prefix($module_prefix . '_quiz');
49
    $usr    = $xoopsDB->prefix('users');
50
    $sql    =
51
        "SELECT round(avg(score),2) AS average, $rsl.uid, $usr.uname FROM $rsl INNER JOIN $usr ON $rsl.uid=$usr.uid INNER JOIN $qiz ON $rsl.quiz_id=$qiz.artid WHERE secid=$options[3] GROUP BY $rsl.uid HAVING average >= $options[2] ORDER BY average $options[0] LIMIT $options[1]";
52
    $result = $xoopsDB->query($sql);
53
    while ($myrow = $xoopsDB->fetchArray($result)) {
54
        $items            = array();
55
        $items['average'] = $myrow['average'];
56
        $items['uname']   = $myrow['uname'];
57
        $items['uid']     = $myrow['uid'];
58
        $block['items'][] = $items;
59
    }
60
    $sec    = $xoopsDB->prefix($module_prefix . '_sections');
61
    $sql    = "SELECT secid, secname FROM $sec WHERE secid=$options[3] AND display=1 LIMIT 1";
62
    $result = $xoopsDB->query($sql);
63
    list($block['secid'], $block['secname']) = $xoopsDB->fetchRow($result);
64
65
    return $block;
66
}
67
68
/**
69
 * @param $options
70
 * @return string
71
 */
72
function b_XHP_courseranking_edit($options)
73
{
74
    global $xoopsDB, $xoopsUser, $xoopsConfig, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
75
    $myts = MyTextSanitizer::getInstance();
76
    $form = _MB_XHP_ITEMS_ORDER . "&nbsp;<select name='options[]'>";
77
    $form .= "<option value='DESC'";
78
    if ($options[0] === 'DESC') {
79
        $form .= " selected='selected'";
80
    }
81
    $form .= '>' . _MB_XHP_ITEMS_DESC . "</option>\n";
82
    $form .= "<option value=''";
83
    if ($options[0] === '') {
84
        $form .= " selected='selected'";
85
    }
86
    $form .= '>' . _MB_XHP_ITEMS_ASCEND . "</option>\n";
87
    $form .= "</select>\n";
88
    $form .= '&nbsp;' . _MB_XHP_ITEMS_DISP . "&nbsp;<input type='text' size=5 name='options[]' value='" . $options[1] . "' />&nbsp;" . _MB_XHP_ITEMS_ARTCLS . "<br>\n";
89
    $form .= '&nbsp;' . _MB_XHP_MINIMUM . "&nbsp;<input type='text' size=5 name='options[]' value='" . $options[2] . "' />&nbsp; %<br>";
90
    $form .= _MB_XHP_COURSE . "&nbsp;<select name='options[]'>";
91
    $mydirname = $options[4];
92
    $mymodpath = XOOPS_ROOT_PATH . "/modules/$mydirname";
93
    include "$mymodpath/module_prefix.php";
94
    $sec    = $xoopsDB->prefix($module_prefix . '_sections');
0 ignored issues
show
Bug introduced by
The variable $module_prefix does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
95
    $sql    = "SELECT secid, secname FROM $sec WHERE display=1";
96
    $result = $xoopsDB->query($sql);
97
    while ($myrow = $xoopsDB->fetchArray($result)) {
98
        $form .= '<option value=' . $myrow['secid'];
99
        if ($options[3] == $myrow['secid']) {
100
            $form .= " selected='selected'";
101
        }
102
        $form .= '>' . $myrow['secname'] . "</option>\n";
103
    }
104
    $form .= "</select>\n";
105
    $form .= "<input type='hidden' name='options[]' value='" . $options[4] . "'>";
106
107
    return $form;
108
}
109