| Conditions | 13 |
| Paths | 190 |
| Total Lines | 93 |
| 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 |
||
| 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) { |
||
|
|
|||
| 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 | } |
||
| 176 |