| Conditions | 22 |
| Paths | 3680 |
| Total Lines | 205 |
| 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 declare(strict_types=1); |
||
| 26 | function b_tdmdownloads_top_show($options) |
||
| 27 | { |
||
| 28 | require dirname(__DIR__) . '/include/common.php'; |
||
| 29 | |||
| 30 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 31 | |||
| 32 | $moduleHandler = xoops_getHandler('module'); |
||
| 33 | |||
| 34 | // 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 |
||
| 35 | |||
| 36 | //$mydir = basename(dirname(__DIR__)); |
||
| 37 | |||
| 38 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 39 | |||
| 40 | $mymodule = $moduleHandler->getByDirname($moduleDirName); |
||
| 41 | |||
| 42 | //appel de la class |
||
| 43 | |||
| 44 | /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $downloadsHandler */ |
||
| 45 | |||
| 46 | $downloadsHandler = Helper::getInstance()->getHandler('Downloads'); |
||
| 47 | |||
| 48 | $block = []; |
||
| 49 | |||
| 50 | $type_block = $options[0]; |
||
| 51 | |||
| 52 | $nb_entree = $options[1]; |
||
| 53 | |||
| 54 | $lenght_title = (int)$options[2]; |
||
| 55 | |||
| 56 | $use_logo = $options[3]; |
||
| 57 | |||
| 58 | $use_description = $options[4]; |
||
| 59 | |||
| 60 | $show_information = $options[5]; |
||
| 61 | |||
| 62 | $logo_float = $options[6]; |
||
| 63 | |||
| 64 | $logo_width = $options[7]; |
||
| 65 | |||
| 66 | $length_description = (int)$options[8]; |
||
| 67 | |||
| 68 | $blockstyle = $options[9]; |
||
| 69 | |||
| 70 | array_shift($options); |
||
| 71 | |||
| 72 | array_shift($options); |
||
| 73 | |||
| 74 | array_shift($options); |
||
| 75 | |||
| 76 | array_shift($options); |
||
| 77 | |||
| 78 | array_shift($options); |
||
| 79 | |||
| 80 | array_shift($options); |
||
| 81 | |||
| 82 | array_shift($options); |
||
| 83 | |||
| 84 | array_shift($options); |
||
| 85 | |||
| 86 | array_shift($options); |
||
| 87 | |||
| 88 | array_shift($options); |
||
| 89 | |||
| 90 | // Add styles |
||
| 91 | |||
| 92 | global $xoTheme; |
||
| 93 | |||
| 94 | $db = null; |
||
|
|
|||
| 95 | |||
| 96 | /** @var \xos_opal_Theme $xoTheme */ |
||
| 97 | |||
| 98 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/blocks.css', null); |
||
| 99 | |||
| 100 | /** @var \XoopsModules\Tdmdownloads\Utility $utility */ |
||
| 101 | |||
| 102 | $utility = new \XoopsModules\Tdmdownloads\Utility(); |
||
| 103 | |||
| 104 | /** @var \XoopsModules\Tdmdownloads\Helper $helper */ |
||
| 105 | |||
| 106 | $helper->loadLanguage('main'); |
||
| 107 | |||
| 108 | $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); |
||
| 109 | |||
| 110 | $criteria = new \CriteriaCompo(); |
||
| 111 | |||
| 112 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||
| 113 | |||
| 114 | if (is_array($options) && !empty($options) && !0 == $options[0] && 1 === count($options)) { |
||
| 115 | $criteria->add(new \Criteria('cid', '(' . implode(',', $options) . ')', 'IN')); |
||
| 116 | } |
||
| 117 | |||
| 118 | $criteria->add(new \Criteria('status', 0, '!=')); |
||
| 119 | |||
| 120 | switch ($type_block) { // pour le bloc: dernier fichier |
||
| 121 | case 'date': |
||
| 122 | $criteria->setSort('date'); |
||
| 123 | $criteria->setOrder('DESC'); |
||
| 124 | break; |
||
| 125 | // pour le bloc: plus téléchargé |
||
| 126 | case 'hits': |
||
| 127 | $criteria->setSort('hits'); |
||
| 128 | $criteria->setOrder('DESC'); |
||
| 129 | break; |
||
| 130 | // pour le bloc: mieux noté |
||
| 131 | case 'rating': |
||
| 132 | $criteria->setSort('rating'); |
||
| 133 | $criteria->setOrder('DESC'); |
||
| 134 | break; |
||
| 135 | // pour le bloc: aléatoire |
||
| 136 | case 'random': |
||
| 137 | $criteria->setSort('RAND()'); |
||
| 138 | break; |
||
| 139 | } |
||
| 140 | |||
| 141 | $criteria->setLimit($nb_entree); |
||
| 142 | |||
| 143 | $downloadsArray = $downloadsHandler->getAll($criteria); |
||
| 144 | |||
| 145 | foreach (array_keys($downloadsArray) as $i) { |
||
| 146 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */ |
||
| 147 | |||
| 148 | $block[$i]['lid'] = $downloadsArray[$i]->getVar('lid'); |
||
| 149 | |||
| 150 | $titleFinal = $downloadsArray[$i]->getVar('title'); |
||
| 151 | |||
| 152 | if ($lenght_title > 0) { |
||
| 153 | $titleFinal = mb_strlen($titleFinal) > $lenght_title ? mb_substr($titleFinal, 0, $lenght_title) . '...' : $titleFinal; |
||
| 154 | } |
||
| 155 | |||
| 156 | $block[$i]['title'] = $titleFinal; |
||
| 157 | |||
| 158 | $descriptionFinal = ''; |
||
| 159 | |||
| 160 | if (true == $use_description) { |
||
| 161 | $description = $downloadsArray[$i]->getVar('description'); |
||
| 162 | |||
| 163 | //permet d'afficher uniquement la description courte |
||
| 164 | |||
| 165 | if ($length_description > 0) { |
||
| 166 | if (false === mb_strpos($description, '[pagebreak]')) { |
||
| 167 | $descriptionFinal = mb_substr($description, 0, $length_description); |
||
| 168 | |||
| 169 | if (mb_strlen($description) > mb_strlen($descriptionFinal)) { |
||
| 170 | $descriptionFinal .= ' ...'; |
||
| 171 | } |
||
| 172 | } else { |
||
| 173 | $descriptionFinal = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')) . ' ...'; |
||
| 174 | } |
||
| 175 | } else { |
||
| 176 | $descriptionFinal = $description; |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | $block[$i]['description'] = $descriptionFinal; |
||
| 181 | |||
| 182 | $logourl = ''; |
||
| 183 | |||
| 184 | if (true == $use_logo) { |
||
| 185 | if ('blank.gif' === $downloadsArray[$i]->getVar('logourl') || '' === $downloadsArray[$i]->getVar('logourl')) { |
||
| 186 | $logourl = ''; |
||
| 187 | } else { |
||
| 188 | $logourl = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/shots/' . $downloadsArray[$i]->getVar('logourl'); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | $block[$i]['logourl'] = $logourl; |
||
| 193 | |||
| 194 | $block[$i]['logourl_class'] = $logo_float; |
||
| 195 | |||
| 196 | $block[$i]['logourl_width'] = $logo_width; |
||
| 197 | |||
| 198 | $block[$i]['hits'] = $downloadsArray[$i]->getVar('hits'); |
||
| 199 | |||
| 200 | $block[$i]['rating'] = number_format((float)$downloadsArray[$i]->getVar('rating'), 1); |
||
| 201 | |||
| 202 | $block[$i]['date'] = formatTimestamp($downloadsArray[$i]->getVar('date'), 's'); |
||
| 203 | |||
| 204 | $block[$i]['submitter'] = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter')); |
||
| 205 | |||
| 206 | $block[$i]['inforation'] = $show_information; |
||
| 207 | |||
| 208 | $block[$i]['blockstyle'] = $blockstyle; |
||
| 209 | } |
||
| 210 | |||
| 211 | $GLOBALS['xoopsTpl']->assign('tdmblockstyle', $blockstyle); |
||
| 212 | |||
| 213 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 214 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 215 | |||
| 216 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
| 217 | |||
| 218 | if (is_object($GLOBALS['xoopsUser'])) { |
||
| 219 | $groups = $GLOBALS['xoopsUser']->getGroups(); |
||
| 220 | } |
||
| 221 | |||
| 222 | $perm_submit = $grouppermHandler->checkRight('tdmdownloads_ac', 4, $groups, $mymodule->getVar('mid')) ? true : false; |
||
| 223 | |||
| 224 | $perm_modif = $grouppermHandler->checkRight('tdmdownloads_ac', 8, $groups, $mymodule->getVar('mid')) ? true : false; |
||
| 225 | |||
| 226 | $GLOBALS['xoopsTpl']->assign('perm_submit', $perm_submit); |
||
| 227 | |||
| 228 | $GLOBALS['xoopsTpl']->assign('perm_modif', $perm_modif); |
||
| 229 | |||
| 230 | return $block; |
||
| 231 | } |
||
| 362 |