| Conditions | 15 |
| Paths | 2754 |
| Total Lines | 131 |
| Code Lines | 101 |
| 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 |
||
| 51 | function lx_Statistics() |
||
| 52 | { |
||
| 53 | global $xoopsModule, $xoopsConfig; |
||
| 54 | $helper = Helper::getInstance(); |
||
| 55 | xoops_load('XoopsUserUtility'); |
||
| 56 | xoops_cp_header(); |
||
| 57 | $myts = \MyTextSanitizer::getInstance(); |
||
| 58 | xoops_load('XoopsUserUtility'); // LionHell |
||
| 59 | |||
| 60 | $stats = []; |
||
|
|
|||
| 61 | $stats = lx_GetStatistics($helper->getConfig('perpage')); |
||
| 62 | $totals = [0, 0, 0, 0]; |
||
| 63 | |||
| 64 | $adminObject = Admin::getInstance(); |
||
| 65 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 66 | // First part of the stats, everything about categories |
||
| 67 | $termspercategory = $stats['termspercategory']; |
||
| 68 | $readspercategory = $stats['readspercategory']; |
||
| 69 | $offlinepercategory = $stats['offlinepercategory']; |
||
| 70 | $authorspercategory = $stats['authorspercategory']; |
||
| 71 | $class = ''; |
||
| 72 | |||
| 73 | echo "<div class='center;'><strong>" . _AM_LEXIKON_STATS0 . '</strong><br>'; |
||
| 74 | echo "<table class='outer' style='margin-top:6px; clear:both; width:99%;'>"; |
||
| 75 | echo "<tr class='bg3'><th style='text-align:center;'>" . _AM_LEXIKON_ENTRYCATNAME . "</th><th style='text-align:center;'>" . _AM_LEXIKON_TOTALENTRIES . '</th><th>' . _READS . '</th><th>' . _AM_LEXIKON_STATS6 . '</th><th>' . _AM_LEXIKON_STATS1 . '</th></tr>'; |
||
| 76 | |||
| 77 | foreach ($termspercategory as $categoryID => $data) { |
||
| 78 | $url = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/category.php?categoryID=' . $categoryID; |
||
| 79 | $views = 0; |
||
| 80 | if (array_key_exists($categoryID, $readspercategory)) { |
||
| 81 | $views = $readspercategory[$categoryID]; |
||
| 82 | } |
||
| 83 | $offline = 0; |
||
| 84 | if (array_key_exists($categoryID, $offlinepercategory)) { |
||
| 85 | $offline = $offlinepercategory[$categoryID]; |
||
| 86 | } |
||
| 87 | $authors = 0; |
||
| 88 | if (array_key_exists($categoryID, $authorspercategory)) { |
||
| 89 | $authors = $authorspercategory[$categoryID]; |
||
| 90 | } |
||
| 91 | $terms = $data['cpt']; |
||
| 92 | |||
| 93 | $totals[0] += $terms; |
||
| 94 | $totals[1] += $views; |
||
| 95 | $totals[2] += $offline; |
||
| 96 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 97 | printf( |
||
| 98 | "<tr class='" . $class . "'><td style='text-align:left;'><a href='%s' target ='_blank'>%s</a></td><td style='text-align:center;'>%u</td><td style='text-align:center;'>%u</td><td style='text-align:center;'>%u</td><td style='text-align:center;'>%u</td></tr>\n", |
||
| 99 | $url, |
||
| 100 | $myts->displayTarea($data['name']), |
||
| 101 | $terms, |
||
| 102 | $views, |
||
| 103 | $offline, |
||
| 104 | $authors |
||
| 105 | ); |
||
| 106 | } |
||
| 107 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 108 | printf("<tr class='" . $class . "'><td style='text-align:right;'><b>%s:</b></td><td style='text-align:center;'><b>%u</b></td><td style='text-align:center;'><b>%u</b></td><td style='text-align:center;'><b>%u</b></td><td> </td>\n", _AM_LEXIKON_STATS2, $totals[0], $totals[1], $totals[2]); |
||
| 109 | echo '</table></div><br><br>'; |
||
| 110 | |||
| 111 | // Second part of the stats, everything about reads |
||
| 112 | // a) Most read definitions |
||
| 113 | $mostreadterms = $stats['mostreadterms']; |
||
| 114 | |||
| 115 | echo "<div class='center;'><strong>" . _AM_LEXIKON_STATS3 . '</strong><br>' . _AM_LEXIKON_STATS4 . '<br>'; |
||
| 116 | echo "<table class='outer' style='margin-top:6px; clear:both; width:99%;'>"; |
||
| 117 | echo "<tr class='bg3'><th style='text-align:center;'>" . _AM_LEXIKON_ENTRYCATNAME . "</th><th style='text-align:center;'>" . _AM_LEXIKON_ENTRYTERM . '</th><th>' . _AM_LEXIKON_AUTHOR . '</th><th>' . _READS . '</th></tr>'; |
||
| 118 | foreach ($mostreadterms as $entryID => $data) { |
||
| 119 | $url1 = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/category.php?categoryID=' . $data['categoryID']; |
||
| 120 | $url2 = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/entry.php?entryID=' . $entryID; |
||
| 121 | $sentby = \XoopsUserUtility::getUnameFromId($data['uid']); |
||
| 122 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 123 | printf( |
||
| 124 | "<tr class='" . $class . "'><td style='text-align:left;'><a href='%s' target ='_blank'>%s</a></td><td style='text-align:left;'><a href='%s' target='_blank'>%s</a></td><td style='text-align:center;'>%s</td><td style='text-align:right;'>%u</td></tr>\n", |
||
| 125 | $url1, |
||
| 126 | $myts->displayTarea($data['name']), |
||
| 127 | $url2, |
||
| 128 | $myts->displayTarea($data['term']), |
||
| 129 | $sentby, |
||
| 130 | $data['counter'] |
||
| 131 | ); |
||
| 132 | } |
||
| 133 | echo '</table></div><br><br>'; |
||
| 134 | |||
| 135 | // b) Less read definitions |
||
| 136 | $lessreadnews = $stats['lessreadterms']; |
||
| 137 | echo "<div class='center;'><strong>" . _AM_LEXIKON_STATS5 . '</strong><br>'; |
||
| 138 | echo "<table class='outer' style='margin-top:6px; clear:both; width:99%;'>"; |
||
| 139 | echo "<tr class='bg3'><th style='text-align:center;'>" . _AM_LEXIKON_ENTRYCATNAME . "</th><th style='text-align:center;'>" . _AM_LEXIKON_ENTRYTERM . "</th><th style='text-align:center;'>" . _AM_LEXIKON_AUTHOR . "</th><th style='text-align:center;'>" . _READS . '</th></tr>'; |
||
| 140 | foreach ($lessreadnews as $entryID => $data) { |
||
| 141 | $url1 = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/category.php?categoryID=' . $data['categoryID']; |
||
| 142 | $url2 = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/entry.php?entryID=' . $entryID; |
||
| 143 | $sentby = \XoopsUserUtility::getUnameFromId($data['uid']); |
||
| 144 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 145 | printf( |
||
| 146 | "<tr class='" . $class . "'><td style='text-align:left;'><a href='%s' target ='_blank'>%s</a></td><td style='text-align:left;'><a href='%s' target='_blank'>%s</a></td><td style='text-align:center;'>%s</td><td style='text-align:right;'>%u</td></tr>\n", |
||
| 147 | $url1, |
||
| 148 | $myts->displayTarea($data['name']), |
||
| 149 | $url2, |
||
| 150 | $myts->displayTarea($data['term']), |
||
| 151 | $sentby, |
||
| 152 | $data['counter'] |
||
| 153 | ); |
||
| 154 | } |
||
| 155 | echo '</table></div><br><br>'; |
||
| 156 | |||
| 157 | // Last part of the stats, everything about authors |
||
| 158 | // a) Most read authors |
||
| 159 | $mostreadauthors = $stats['mostreadauthors']; |
||
| 160 | echo "<div class='center;'><strong>" . _AM_LEXIKON_STATS10 . '</strong><br>' . _AM_LEXIKON_STATS7 . '<br>'; |
||
| 161 | echo "<table class='outer' style='margin-top:6px; clear:both; width:99%;'>"; |
||
| 162 | echo "<tr class='bg3'><th style='text-align:center;'>" . _AM_LEXIKON_AUTHOR . "</th><th style='text-align:center;'>" . _READS . '</th></tr>'; |
||
| 163 | foreach ($mostreadauthors as $uid => $reads) { |
||
| 164 | $sentby = \XoopsUserUtility::getUnameFromId($uid); |
||
| 165 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 166 | printf("<tr class='" . $class . "'><td style='text-align:center;'>%s</td><td style='text-align:center;'>%u</td></tr>\n", $sentby, $reads); |
||
| 167 | } |
||
| 168 | echo '</table></div><br><br>'; |
||
| 169 | |||
| 170 | // c) Biggest contributors |
||
| 171 | $biggestcontributors = $stats['biggestcontributors']; |
||
| 172 | echo "<div class='center;'><strong>" . _AM_LEXIKON_STATS9 . '</strong><br>'; |
||
| 173 | echo "<table class='outer' style='margin-top:6px; clear:both; width:99%;'>"; |
||
| 174 | echo "<tr class='bg3'><th style='text-align:center;'>" . _AM_LEXIKON_AUTHOR . "</th><th style='text-align:center;'>" . _AM_LEXIKON_STATS11 . '</th></tr>'; |
||
| 175 | foreach ($biggestcontributors as $uid => $count) { |
||
| 176 | $url = XOOPS_URL . '/userinfo.php?uid=' . $uid; |
||
| 177 | $sentby = \XoopsUserUtility::getUnameFromId($uid); |
||
| 178 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 179 | printf("<tr class='" . $class . "'><td style='text-align:center;'>%s</td><td style='text-align:center;'>%u</td></tr>\n", $sentby, $count); |
||
| 180 | } |
||
| 181 | echo '</table></div><br>'; |
||
| 182 | } |
||
| 193 |