| Conditions | 22 |
| Paths | 768 |
| Total Lines | 195 |
| Code Lines | 150 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 43 | function b_donations_donatometer_show($options) |
||
| 44 | { |
||
| 45 | global $xoopsDB; |
||
| 46 | $xdBlockDir = basename(dirname(__DIR__)); |
||
| 47 | $utility = new Xdonations\Utility(); |
||
| 48 | $tr_config = $utility::getConfigInfo(); |
||
| 49 | //determine the currency |
||
| 50 | $PP_CURR_CODE = explode('|', $tr_config['pp_curr_code']); // [USD,GBP,JPY,CAD,EUR] |
||
| 51 | $PP_CURR_CODE = $PP_CURR_CODE[0]; |
||
| 52 | $currencySign = $utility::defineCurrency($PP_CURR_CODE); |
||
| 53 | |||
| 54 | $block = []; |
||
| 55 | |||
| 56 | $swingd = $tr_config['swing_day']; |
||
| 57 | if (($swingd < 0) || ($swingd > 31)) { |
||
| 58 | $swingd = 6; |
||
| 59 | } |
||
| 60 | $dmshowdate = $options[1]; |
||
| 61 | $dmshowamt = $options[2]; |
||
| 62 | |||
| 63 | if (is_numeric($options[0]) && $options[0] > 0) { |
||
| 64 | $dmlen = $options[0]; |
||
| 65 | } elseif (is_numeric($dmlen) && 0 == $dmlen) { |
||
| 66 | $dmlen = -1; |
||
| 67 | } else { |
||
| 68 | $dmlen = 10; |
||
| 69 | } |
||
| 70 | |||
| 71 | // Check the current day against the swing day to execute the proper query |
||
| 72 | if (date('d') >= $swingd) { |
||
| 73 | $query_Recordset1 = 'SELECT count(mc_gross) AS count, sum(mc_gross) AS gross, sum(' |
||
| 74 | . "mc_gross-mc_fee) AS net, date_format( now(),'%M') AS mon, date_format( subdate( date_format( adddate(" |
||
| 75 | . "now(), INTERVAL 1 MONTH),'%Y-%c-1'), INTERVAL 1 DAY), '%b %e') AS due_by, date_format(now(),'%b') AS " |
||
| 76 | . 'mon_short FROM ' |
||
| 77 | . $xoopsDB->prefix('donations_transactions') |
||
| 78 | . ' WHERE (payment_date >= date_format(' |
||
| 79 | . "now(),'%Y-%m-" |
||
| 80 | . $swingd |
||
| 81 | . "'))"; |
||
| 82 | |||
| 83 | $query_Recordset3 = 'select custom as muser_id, option_selection1 as showname, ' |
||
| 84 | . "date_format( payment_date, '%b-%e') as date, concat('" |
||
| 85 | . $currencySign |
||
| 86 | . "',sum(mc_gross)) as amt " |
||
| 87 | . 'from ' |
||
| 88 | . $xoopsDB->prefix('donations_transactions') |
||
| 89 | . ' where (payment_date >= date_format( ' |
||
| 90 | . "now(), '%Y-%m-" |
||
| 91 | . $swingd |
||
| 92 | . "')) group by txn_id order by payment_date desc"; |
||
| 93 | } else { |
||
| 94 | $query_Recordset1 = 'select count(mc_gross) as count, sum(mc_gross) as gross, sum(mc_gross -' |
||
| 95 | . ' mc_fee) as net, date_format( subdate( now(), interval ' |
||
| 96 | . $swingd |
||
| 97 | . " day), '%M') as mon," |
||
| 98 | . " 'Now!' as due_by, date_format( subdate( now(), interval " |
||
| 99 | . $swingd |
||
| 100 | . " day), '%b') as mon_short" |
||
| 101 | . ' from ' |
||
| 102 | . $xoopsDB->prefix('donations_transactions') |
||
| 103 | . " where (payment_date < date_format( now(), '%Y-%m-" |
||
| 104 | . $swingd |
||
| 105 | . "')" |
||
| 106 | . ') and payment_date > date_format( subdate( now(), interval ' |
||
| 107 | . $swingd |
||
| 108 | . " day), '%Y-%m-" |
||
| 109 | . $swingd |
||
| 110 | . "')"; |
||
| 111 | |||
| 112 | $query_Recordset3 = 'select custom as muser_id, option_selection1 as showname, ' |
||
| 113 | . "date_format( payment_date, '%b-%e') as date, concat('" |
||
| 114 | . $currencySign |
||
| 115 | . "', sum(mc_gross)) as amt " |
||
| 116 | . 'from ' |
||
| 117 | . $xoopsDB->prefix('donations_transactions') |
||
| 118 | . ' where (payment_date < date_format(now(),' |
||
| 119 | . " '%Y-%m-" |
||
| 120 | . $swingd |
||
| 121 | . "')) and payment_date > date_format( subdate( now(),interval " |
||
| 122 | . $swingd |
||
| 123 | . ' ' |
||
| 124 | . "day), '%Y-%m-" |
||
| 125 | . $swingd |
||
| 126 | . "') group by txn_id order by payment_date desc"; |
||
| 127 | } |
||
| 128 | |||
| 129 | // Get the donation totals |
||
| 130 | $Recordset1 = $xoopsDB->query($query_Recordset1); |
||
| 131 | $row_Recordset1 = $xoopsDB->fetchArray($Recordset1); |
||
| 132 | //If there are not records, then get "null" data |
||
| 133 | if (!$row_Recordset1) { |
||
| 134 | $query_Recordset1 = "select '0' as count, '0' as gross, '0' as net, date_format( now()," |
||
| 135 | . "'%M') as mon, date_format( subdate( date_format( adddate( now(), interval 1 month), '%Y-%c-1')," |
||
| 136 | . " interval 1 day), '%b %e') as due_by, date_format( now(), '%b') as mon_short from " |
||
| 137 | . ' ' |
||
| 138 | . $xoopsDB->prefix('donations_transactions') |
||
| 139 | . ''; |
||
| 140 | $Recordset1 = $xoopsDB->query($query_Recordset1); |
||
| 141 | $row_Recordset1 = $xoopsDB->fetchArray($Recordset1); |
||
| 142 | } |
||
| 143 | // Get the goal |
||
| 144 | $query_Recordset2 = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name='month_goal' AND subtype='" . $row_Recordset1['mon_short'] . "'"; |
||
| 145 | $Recordset2 = $xoopsDB->query($query_Recordset2); |
||
| 146 | $row_Recordset2 = $xoopsDB->fetchArray($Recordset2); |
||
| 147 | |||
| 148 | // Set our remaining template vars |
||
| 149 | if (!$row_Recordset1['mon']) { |
||
| 150 | $DM_MON = date('F'); |
||
| 151 | } else { |
||
| 152 | $DM_MON = $row_Recordset1['mon']; |
||
| 153 | } |
||
| 154 | $difference = $row_Recordset1['net'] - $row_Recordset2['value']; |
||
| 155 | $DM_GOAL = sprintf($currencySign . '%.02f', $row_Recordset2['value']); |
||
| 156 | $DM_DUE = $row_Recordset1['due_by']; |
||
| 157 | $DM_NUM = $row_Recordset1['count']; |
||
| 158 | $DM_GROSS = sprintf($currencySign . '%.02f', $row_Recordset1['gross']); |
||
| 159 | $DM_NET = sprintf($currencySign . '%.02f', $row_Recordset1['net']); |
||
| 160 | $DM_LEFT = sprintf($currencySign . '%.02f', $row_Recordset2['value'] - $row_Recordset1['net']); |
||
| 161 | $DM_BUTTON = $options[3]; |
||
| 162 | $DM_BUTT_DIMS = ''; |
||
| 163 | if (is_numeric($options[4])) { |
||
| 164 | $DM_BUTT_DIMS .= 'width=' . $options[4] . ' '; |
||
| 165 | } |
||
| 166 | if (is_numeric($options[5])) { |
||
| 167 | $DM_BUTT_DIMS .= 'height=' . $options[5] . ' '; |
||
| 168 | } |
||
| 169 | |||
| 170 | // Load the template |
||
| 171 | $block['DM_BUTTON'] = $DM_BUTTON; |
||
| 172 | $block['DM_BUTT_DIMS'] = $DM_BUTT_DIMS; |
||
| 173 | $block['DM_MON'] = $DM_MON; |
||
| 174 | $block['DM_GOAL'] = $DM_GOAL; |
||
| 175 | $block['DM_DUE'] = $DM_DUE; |
||
| 176 | $block['DM_GROSS'] = $DM_GROSS; |
||
| 177 | $block['DM_NET'] = $DM_NET; |
||
| 178 | $block['DON_URL'] = XOOPS_URL . '/modules/' . $xdBlockDir . '/index.php'; |
||
| 179 | $show_don = 0; |
||
| 180 | // Do we want to display the donators? |
||
| 181 | if (is_numeric($dmlen) && $dmlen >= 0) { |
||
| 182 | $show_don = 1; |
||
| 183 | // Get the list of donators |
||
| 184 | $Recordset3 = $xoopsDB->query($query_Recordset3); |
||
| 185 | |||
| 186 | // List all the donators |
||
| 187 | $i = 0; |
||
| 188 | $var = ''; |
||
| 189 | while (($row_Recordset3 = $xoopsDB->fetchArray($Recordset3)) && ($i != $options[0])) { |
||
| 190 | // Refunded transactions will show up with $0 amount |
||
| 191 | if ($row_Recordset3['amt'] > '$0') { |
||
| 192 | $dmalign = 'center'; |
||
| 193 | $var .= "<tr><td style=\"width: 100%; text-align: {$dmalign};\" colspan=\"2\">\n"; |
||
| 194 | // Observe the user's wish regarding revealing their name |
||
| 195 | $muser_id = $row_Recordset3['muser_id']; |
||
| 196 | /** @var \XoopsUser $userfoin */ |
||
| 197 | if (0 == strcmp($row_Recordset3['showname'], 'Yes') && ($userfoin = $utility::getUserInfo($muser_id))) { |
||
| 198 | $var .= "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userfoin->getVar('uid') . "'>" . $userfoin->getVar('uname') . "</a>\n"; |
||
| 199 | } else { |
||
| 200 | $var .= _MB_XDONATION_ANONYMOUS_SHORT; |
||
| 201 | } |
||
| 202 | $var .= ' '; |
||
| 203 | if ($dmshowamt) { |
||
| 204 | $var .= '(' . $row_Recordset3['amt'] . ')'; |
||
| 205 | } |
||
| 206 | if ($dmshowdate) { |
||
| 207 | $var .= $row_Recordset3['date']; |
||
| 208 | } |
||
| 209 | $var .= "</td></tr>\n"; |
||
| 210 | } |
||
| 211 | ++$i; |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | if ($difference >= 0) { |
||
| 216 | $DM_OVERAGE = sprintf($currencySign . '%.02f', $difference); |
||
| 217 | $block['DM_REMAIN'] = _MB_XDONATION_SURPLUS; |
||
| 218 | $block['DM_BALANCE'] = $DM_OVERAGE; |
||
| 219 | } else { |
||
| 220 | $block['DM_REMAIN'] = _MB_XDONATION_LEFT2GO; |
||
| 221 | $block['DM_BALANCE'] = "<span style=\"color: #CC0000;\">{$DM_LEFT}</span>"; |
||
| 222 | } |
||
| 223 | |||
| 224 | // Define language constants |
||
| 225 | $block['DM_STAT'] = _MB_XDONATION_STAT; |
||
| 226 | $block['DM_MONGOAL'] = _MB_XDONATION_MONGOAL; |
||
| 227 | $block['DM_DUEDATE'] = _MB_XDONATION_DUEDATE; |
||
| 228 | $block['DM_GROSSAMT'] = _MB_XDONATION_GROSSAMT; |
||
| 229 | $block['DM_NETBAL'] = _MB_XDONATION_NETBAL; |
||
| 230 | $block['DM_DONATIONS'] = _MB_XDONATION_DONATIONS; |
||
| 231 | $block['DM_MAKEDON'] = _MB_XDONATION_MAKEDON; |
||
| 232 | |||
| 233 | // Display block |
||
| 234 | $block['show_don'] = $show_don; |
||
| 235 | $block['content'] = $var; |
||
| 236 | |||
| 237 | return $block; |
||
| 238 | } |
||
| 273 |