Conditions | 13 |
Paths | 190 |
Total Lines | 103 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
25 | function b_tdmdownloads_top_show($options) |
||
26 | { |
||
27 | require dirname(__DIR__) . '/include/common.php'; |
||
28 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
29 | $moduleHandler = xoops_getHandler('module'); |
||
30 | // get the name of the file's directory to get the "owner" of the block, i.e. its module, and not the "user", where it is currently |
||
31 | //$mydir = basename(dirname(__DIR__)); |
||
32 | $moduleDirName = basename(dirname(__DIR__)); |
||
33 | $mymodule = $moduleHandler->getByDirname($moduleDirName); |
||
|
|||
34 | //appel de la class |
||
35 | /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $downloadsHandler */ |
||
36 | $downloadsHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downloads'); |
||
37 | $block = []; |
||
38 | $type_block = $options[0]; |
||
39 | $nb_entree = $options[1]; |
||
40 | $lenght_title = $options[2]; |
||
41 | $use_logo = $options[3]; |
||
42 | $use_description = $options[4]; |
||
43 | $show_inforation = $options[5]; |
||
44 | $logo_float = $options[6]; |
||
45 | $logo_white = $options[7]; |
||
46 | $lenght_description = $options[8]; |
||
47 | |||
48 | array_shift($options); |
||
49 | array_shift($options); |
||
50 | array_shift($options); |
||
51 | array_shift($options); |
||
52 | array_shift($options); |
||
53 | array_shift($options); |
||
54 | array_shift($options); |
||
55 | array_shift($options); |
||
56 | array_shift($options); |
||
57 | |||
58 | // Add styles |
||
59 | global $xoTheme; |
||
60 | $db = null; |
||
61 | |||
62 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/blocks.css', null); |
||
63 | /** @var \XoopsModules\Tdmdownloads\Utility $utility */ |
||
64 | $utility = new \XoopsModules\Tdmdownloads\Utility(); |
||
65 | |||
66 | $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); |
||
67 | $criteria = new \CriteriaCompo(); |
||
68 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
69 | if (!(0 == $options[0] && 1 === count($options))) { |
||
70 | $criteria->add(new \Criteria('cid', '(' . implode(',', $options) . ')', 'IN')); |
||
71 | } |
||
72 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
73 | switch ($type_block) { // pour le bloc: dernier fichier |
||
74 | case 'date': |
||
75 | $criteria->setSort('date'); |
||
76 | $criteria->setOrder('DESC'); |
||
77 | break; |
||
78 | // pour le bloc: plus téléchargé |
||
79 | case 'hits': |
||
80 | $criteria->setSort('hits'); |
||
81 | $criteria->setOrder('DESC'); |
||
82 | break; |
||
83 | // pour le bloc: mieux noté |
||
84 | case 'rating': |
||
85 | $criteria->setSort('rating'); |
||
86 | $criteria->setOrder('DESC'); |
||
87 | break; |
||
88 | // pour le bloc: aléatoire |
||
89 | case 'random': |
||
90 | $criteria->setSort('RAND()'); |
||
91 | break; |
||
92 | } |
||
93 | $criteria->setLimit($nb_entree); |
||
94 | $downloads_arr = $downloadsHandler->getAll($criteria); |
||
95 | foreach (array_keys($downloads_arr) as $i) { |
||
96 | $block[$i]['lid'] = $downloads_arr[$i]->getVar('lid'); |
||
97 | $block[$i]['title'] = mb_strlen($downloads_arr[$i]->getVar('title')) > $lenght_title ? mb_substr($downloads_arr[$i]->getVar('title'), 0, $lenght_title) . '...' : $downloads_arr[$i]->getVar('title'); |
||
98 | $description_short = ''; |
||
99 | if (true === $use_description) { |
||
100 | $description = $downloads_arr[$i]->getVar('description'); |
||
101 | //permet d'afficher uniquement la description courte |
||
102 | if (false === mb_strpos($description, '[pagebreak]')) { |
||
103 | $description_short = mb_substr($description, 0, $lenght_description) . ' ...'; |
||
104 | } else { |
||
105 | $description_short = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')) . ' ...'; |
||
106 | } |
||
107 | } |
||
108 | $block[$i]['description'] = $description_short; |
||
109 | $logourl = ''; |
||
110 | if (true === $use_logo) { |
||
111 | if ('blank.gif' === $downloads_arr[$i]->getVar('logourl')) { |
||
112 | $logourl = ''; |
||
113 | } else { |
||
114 | $logourl = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/shots/' . $downloads_arr[$i]->getVar('logourl'); |
||
115 | } |
||
116 | } |
||
117 | $block[$i]['logourl'] = $logourl; |
||
118 | $block[$i]['logourl_class'] = $logo_float; |
||
119 | $block[$i]['logourl_width'] = $logo_white; |
||
120 | $block[$i]['hits'] = $downloads_arr[$i]->getVar('hits'); |
||
121 | $block[$i]['rating'] = number_format($downloads_arr[$i]->getVar('rating'), 1); |
||
122 | $block[$i]['date'] = formatTimestamp($downloads_arr[$i]->getVar('date'), 's'); |
||
123 | $block[$i]['submitter'] = \XoopsUser::getUnameFromId($downloads_arr[$i]->getVar('submitter')); |
||
124 | $block[$i]['inforation'] = $show_inforation; |
||
125 | } |
||
126 | |||
127 | return $block; |
||
128 | } |
||
200 |