Conditions | 22 |
Paths | 3680 |
Total Lines | 126 |
Code Lines | 99 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
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 |
||
28 | function b_tdmdownloads_top_show($options) |
||
29 | { |
||
30 | require dirname(__DIR__) . '/include/common.php'; |
||
31 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
32 | $moduleHandler = xoops_getHandler('module'); |
||
33 | // 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 |
||
34 | //$mydir = basename(dirname(__DIR__)); |
||
35 | $moduleDirName = basename(dirname(__DIR__)); |
||
36 | $mymodule = $moduleHandler->getByDirname($moduleDirName); |
||
37 | //appel de la class |
||
38 | /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $downloadsHandler */ |
||
39 | $downloadsHandler = Helper::getInstance()->getHandler('Downloads'); |
||
40 | $block = []; |
||
41 | $type_block = $options[0]; |
||
42 | $nb_entree = $options[1]; |
||
43 | $lenght_title = (int)$options[2]; |
||
44 | $use_logo = $options[3]; |
||
45 | $use_description = $options[4]; |
||
46 | $show_information = $options[5]; |
||
47 | $logo_float = $options[6]; |
||
48 | $logo_width = $options[7]; |
||
49 | $length_description = (int)$options[8]; |
||
50 | $blockstyle = $options[9]; |
||
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 | array_shift($options); |
||
58 | array_shift($options); |
||
59 | array_shift($options); |
||
60 | array_shift($options); |
||
61 | // Add styles |
||
62 | global $xoTheme; |
||
63 | $db = null; |
||
|
|||
64 | /** @var \xos_opal_Theme $xoTheme */ |
||
65 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/blocks.css', null); |
||
66 | $utility = new \XoopsModules\Tdmdownloads\Utility(); |
||
67 | /** @var \XoopsModules\Tdmdownloads\Helper $helper */ |
||
68 | $helper->loadLanguage('main'); |
||
69 | $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); |
||
70 | $criteria = new \CriteriaCompo(); |
||
71 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
72 | if (is_array($options) && !empty($options) && !0 == $options[0] && 1 === count($options)) { |
||
73 | $criteria->add(new \Criteria('cid', '(' . implode(',', $options) . ')', 'IN')); |
||
74 | } |
||
75 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
76 | switch ($type_block) { // pour le bloc: dernier fichier |
||
77 | case 'date': |
||
78 | $criteria->setSort('date'); |
||
79 | $criteria->setOrder('DESC'); |
||
80 | break; |
||
81 | // pour le bloc: plus téléchargé |
||
82 | case 'hits': |
||
83 | $criteria->setSort('hits'); |
||
84 | $criteria->setOrder('DESC'); |
||
85 | break; |
||
86 | // pour le bloc: mieux noté |
||
87 | case 'rating': |
||
88 | $criteria->setSort('rating'); |
||
89 | $criteria->setOrder('DESC'); |
||
90 | break; |
||
91 | // pour le bloc: aléatoire |
||
92 | case 'random': |
||
93 | $criteria->setSort('RAND()'); |
||
94 | break; |
||
95 | } |
||
96 | $criteria->setLimit($nb_entree); |
||
97 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||
98 | foreach (array_keys($downloadsArray) as $i) { |
||
99 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ |
||
100 | $block[$i]['lid'] = $downloadsArray[$i]->getVar('lid'); |
||
101 | $titleFinal = $downloadsArray[$i]->getVar('title'); |
||
102 | if ($lenght_title > 0) { |
||
103 | $titleFinal = mb_strlen($titleFinal) > $lenght_title ? mb_substr($titleFinal, 0, $lenght_title) . '...' : $titleFinal; |
||
104 | } |
||
105 | $block[$i]['title'] = $titleFinal; |
||
106 | $descriptionFinal = ''; |
||
107 | if (true == $use_description) { |
||
108 | $description = $downloadsArray[$i]->getVar('description'); |
||
109 | //permet d'afficher uniquement la description courte |
||
110 | if ($length_description > 0) { |
||
111 | if (false === mb_strpos($description, '[pagebreak]')) { |
||
112 | $descriptionFinal = mb_substr($description, 0, $length_description); |
||
113 | if (mb_strlen($description) > mb_strlen($descriptionFinal)) { |
||
114 | $descriptionFinal .= ' ...'; |
||
115 | } |
||
116 | } else { |
||
117 | $descriptionFinal = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')) . ' ...'; |
||
118 | } |
||
119 | } else { |
||
120 | $descriptionFinal = $description; |
||
121 | } |
||
122 | } |
||
123 | $block[$i]['description'] = $descriptionFinal; |
||
124 | $logourl = ''; |
||
125 | if (true == $use_logo) { |
||
126 | if ('blank.gif' === $downloadsArray[$i]->getVar('logourl') || '' === $downloadsArray[$i]->getVar('logourl')) { |
||
127 | $logourl = ''; |
||
128 | } else { |
||
129 | $logourl = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/shots/' . $downloadsArray[$i]->getVar('logourl'); |
||
130 | } |
||
131 | } |
||
132 | $block[$i]['logourl'] = $logourl; |
||
133 | $block[$i]['logourl_class'] = $logo_float; |
||
134 | $block[$i]['logourl_width'] = $logo_width; |
||
135 | $block[$i]['hits'] = $downloadsArray[$i]->getVar('hits'); |
||
136 | $block[$i]['rating'] = number_format((float)$downloadsArray[$i]->getVar('rating'), 1); |
||
137 | $block[$i]['date'] = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); |
||
138 | $block[$i]['submitter'] = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); |
||
139 | $block[$i]['inforation'] = $show_information; |
||
140 | $block[$i]['blockstyle'] = $blockstyle; |
||
141 | } |
||
142 | $GLOBALS['xoopsTpl']->assign('tdmblockstyle', $blockstyle); |
||
143 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
144 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
145 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
146 | if (is_object($GLOBALS['xoopsUser'])) { |
||
147 | $groups = $GLOBALS['xoopsUser']->getGroups(); |
||
148 | } |
||
149 | $perm_submit = $grouppermHandler->checkRight('tdmdownloads_ac', 4, $groups, $mymodule->getVar('mid')) ? true : false; |
||
150 | $perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $mymodule->getVar('mid')) ? true : false; |
||
151 | $GLOBALS['xoopsTpl']->assign('perm_submit', $perm_submit); |
||
152 | $GLOBALS['xoopsTpl']->assign('perm_modif', $perm_modif); |
||
153 | return $block; |
||
154 | } |
||
232 |