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