Passed
Pull Request — master (#4)
by Michael
02:50
created

b_tdmdownloads_top_show()   D

Complexity

Conditions 13
Paths 190

Size

Total Lines 93

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 93
rs 4.846
cc 13
nc 190

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
17
function b_tdmdownloads_top_show($options)
18
{
19
    require_once XOOPS_ROOT_PATH."/modules/TDMDownloads/include/functions.php";
20
    //appel de la class
21
    $downloads_Handler = xoops_getModuleHandler('tdmdownloads_downloads', 'TDMDownloads');
22
    $block = array();
23
    $type_block = $options[0];
24
    $nb_entree = $options[1];
25
    $lenght_title = $options[2];
26
    $use_logo = $options[3];
27
    $use_description = $options[4];
28
    $show_inforation = $options[5];
29
    $logo_float = $options[6];
30
    $logo_white = $options[7];
31
    $lenght_description = $options[8];
32
33
    array_shift($options);
34
    array_shift($options);
35
    array_shift($options);
36
    array_shift($options);
37
    array_shift($options);
38
    array_shift($options);
39
    array_shift($options);
40
    array_shift($options);
41
    array_shift($options);
42
43
    // Add styles
44
    global $xoTheme;
45
    $xoTheme->addStylesheet(XOOPS_URL . '/modules/TDMDownloads/css/blocks.css', null);
46
47
    $categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads');
48
    $criteria = new CriteriaCompo();
49
    $criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN'));
50
    if (!(count($options) == 1 && $options[0] == 0)) {
51
        $criteria->add(new Criteria('cid', '(' . implode(',', $options) . ')','IN'));
52
    }
53
    $criteria->add(new Criteria('status', 0, '!='));
54
    switch ($type_block) {    // pour le bloc: dernier fichier
55
        case "date":
56
            $criteria->setSort('date');
57
            $criteria->setOrder('DESC');
58
        break;
59
        // pour le bloc: plus t�l�charg�
60
        case "hits":
61
            $criteria->setSort('hits');
62
            $criteria->setOrder('DESC');
63
        break;
64
        // pour le bloc: mieux not�
65
        case "rating":
66
            $criteria->setSort('rating');
67
            $criteria->setOrder('DESC');
68
        break;
69
        // pour le bloc: al�atoire
70
        case "random":
71
            $criteria->setSort('RAND()');
72
        break;
73
    }
74
    $criteria->setLimit($nb_entree);
75
    $downloads_arr = $downloads_Handler->getall($criteria);
76
    foreach (array_keys($downloads_arr) as $i) {
77
        $block[$i]['lid'] = $downloads_arr[$i]->getVar('lid');
78
        $block[$i]['title'] = strlen($downloads_arr[$i]->getVar('title')) > $lenght_title ? substr($downloads_arr[$i]->getVar('title'),0,($lenght_title))."..." : $downloads_arr[$i]->getVar('title');
79
        $description_short = '';
80
        if ($use_description == true) {
81
            $description = $downloads_arr[$i]->getVar('description');
82
            //permet d'afficher uniquement la description courte
83
            if (strpos($description,'[pagebreak]')==false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($description, '[pagebreak]') of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
84
                $description_short = substr($description, 0, $lenght_description) . ' ...';
85
            } else {
86
                $description_short = substr($description, 0, strpos($description,'[pagebreak]')) . ' ...';
87
            }
88
        }
89
        $block[$i]['description'] = $description_short;
90
        $logourl = '';
91
        if ($use_logo == true) {
92
            if ($downloads_arr[$i]->getVar('logourl') == 'blank.gif') {
93
                $logourl = '';
94
            } else {
95
                $logourl = XOOPS_URL . '/uploads/TDMDownloads/images/shots/'. $downloads_arr[$i]->getVar('logourl');
96
            }
97
        }
98
        $block[$i]['logourl'] = $logourl;
99
        $block[$i]['logourl_class'] = $logo_float;
100
        $block[$i]['logourl_width'] = $logo_white;
101
        $block[$i]['hits'] = $downloads_arr[$i]->getVar("hits");
102
        $block[$i]['rating'] = number_format($downloads_arr[$i]->getVar("rating"),1);
103
        $block[$i]['date'] = formatTimeStamp($downloads_arr[$i]->getVar("date"),"s");
104
        $block[$i]['submitter'] = XoopsUser::getUnameFromId($downloads_arr[$i]->getVar('submitter'));
105
        $block[$i]['inforation'] = $show_inforation;
106
107
    }
108
109
    return $block;
110
}
111
112
function b_tdmdownloads_top_edit($options)
113
{
114
    //appel de la class
115
    $downloadscat_Handler = xoops_getModuleHandler('tdmdownloads_cat', 'TDMDownloads');
116
    $criteria = new CriteriaCompo();
0 ignored issues
show
Unused Code introduced by
The assignment to $criteria is dead and can be removed.
Loading history...
117
    $criteria = new CriteriaCompo();
118
    $criteria->setSort('cat_weight ASC, cat_title');
119
    $criteria->setOrder('ASC');
120
    $downloadscat_arr = $downloadscat_Handler->getall($criteria);
121
    $form = _MB_TDMDOWNLOADS_DISP . "&nbsp;\n";
122
    $form .= "<input type=\"hidden\" name=\"options[0]\" value=\"" . $options[0] . "\" />\n";
123
    $form .= "<input name=\"options[1]\" size=\"5\" maxlength=\"255\" value=\"" . $options[1] . "\" type=\"text\" />&nbsp;" . _MB_TDMDOWNLOADS_FILES . "<br />\n";
124
    $form .= _MB_TDMDOWNLOADS_CHARS . " : <input name=\"options[2]\" size=\"5\" maxlength=\"255\" value=\"" . $options[2] . "\" type=\"text\" /><br />\n";
125
    if ($options[3] == false) {
126
        $checked_yes = '';
127
        $checked_no = 'checked="checked"';
128
    } else {
129
        $checked_yes = 'checked="checked"';
130
        $checked_no = '';
131
    }
132
    $form .= _MB_TDMDOWNLOADS_LOGO . " : <input name=\"options[3]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . "&nbsp;\n";
133
    $form .= "<input name=\"options[3]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br />\n";
134
    if ($options[4] == false) {
135
        $checked_yes = '';
136
        $checked_no = 'checked="checked"';
137
    } else {
138
        $checked_yes = 'checked="checked"';
139
        $checked_no = '';
140
    }
141
    $form .= _MB_TDMDOWNLOADS_DESCRIPTION . " : <input name=\"options[4]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . "&nbsp;\n";
142
    $form .= "<input name=\"options[4]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br />\n";
143
    if ($options[5] == false) {
144
        $checked_yes = '';
145
        $checked_no = 'checked="checked"';
146
    } else {
147
        $checked_yes = 'checked="checked"';
148
        $checked_no = '';
149
    }
150
    $form .= _MB_TDMDOWNLOADS_INFORMATIONS . " : <input name=\"options[5]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . "&nbsp;\n";
151
    $form .= "<input name=\"options[5]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br /><br />\n";
152
    $floatelect = new XoopsFormSelect(_MB_TDMDOWNLOADS_FLOAT, 'options[6]',$options[6]);
153
    $floatelect->addOption("left", _MB_TDMDOWNLOADS_FLOAT_LEFT);
154
    $floatelect->addOption("right", _MB_TDMDOWNLOADS_FLOAT_RIGHT);
155
    $form .= _MB_TDMDOWNLOADS_FLOAT." : ".$floatelect->render().'<br />';
156
    $form .= _MB_TDMDOWNLOADS_WHITE . " : <input name=\"options[7]\" size=\"5\" maxlength=\"255\" value=\"" . $options[7] . "\" type=\"text\" /><br />\n";
157
    $form .= _MB_TDMDOWNLOADS_CHARSDSC . " : <input name=\"options[8]\" size=\"5\" maxlength=\"255\" value=\"" . $options[8] . "\" type=\"text\" /><br />\n";
158
    array_shift($options);
159
    array_shift($options);
160
    array_shift($options);
161
    array_shift($options);
162
    array_shift($options);
163
    array_shift($options);
164
    array_shift($options);
165
    array_shift($options);
166
    array_shift($options);
167
    $form .= _MB_TDMDOWNLOADS_CATTODISPLAY . "<br /><select name=\"options[]\" multiple=\"multiple\" size=\"5\">\n";
168
    $form .= "<option value=\"0\" " . (array_search(0, $options) === false ? '' : 'selected="selected"') . ">" . _MB_TDMDOWNLOADS_ALLCAT . "</option>\n";
169
    foreach (array_keys($downloadscat_arr) as $i) {
170
        $form .= "<option value=\"" . $downloadscat_arr[$i]->getVar('cat_cid') . "\" " . (array_search($downloadscat_arr[$i]->getVar('cat_cid'), $options) === false ? '' : 'selected="selected"') . ">".$downloadscat_arr[$i]->getVar('cat_title')."</option>\n";
171
    }
172
    $form .= "</select>\n";
173
174
    return $form;
175
}
176