Completed
Push — trunk ( 0e0d9a...90d099 )
by SuperNova.WS
04:43
created

PageAdminPayment::getUsedModules()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 05.03.2018 12:57
4
 */
5
6
namespace Pages\Deprecated;
7
8
use SN;
9
use DBAL\DbSqlPaging;
10
use General\Helpers\PagingRenderer;
11
12
class PageAdminPayment extends PageDeprecated {
13
14
  public static function viewStatic() {
15
    define('INSIDE', true);
16
    define('INSTALL', false);
17
    define('IN_ADMIN', true);
18
19
    global $lang;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
20
21
    messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
22
23
    $template = gettemplate('admin/admin_payment', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type null|template expected by parameter $template of gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
    $template = gettemplate('admin/admin_payment', /** @scrutinizer ignore-type */ true);
Loading history...
24
25
26
    $flt_payer = sys_get_param_int('flt_payer', -1);
27
    $flt_module = sys_get_param_str('flt_module');
28
    $flt_status = sys_get_param_int('flt_status', PAYMENT_STATUS_ALL);
29
    $flt_test = sys_get_param_int('flt_test', PAYMENT_TEST_REAL);
30
    $flt_currency = sys_get_param_int('flt_currency', -1);
31
    $flt_stat = sys_get_param_int('flt_stat', PAYMENT_FILTER_STAT_NORMAL);
32
    $flt_stat_type = sys_get_param_int('flt_stat_type', -1);
0 ignored issues
show
Unused Code introduced by
The assignment to $flt_stat_type is dead and can be removed.
Loading history...
33
34
35
    // TODO - remove debug
36
//    $flt_stat = PAYMENT_FILTER_STAT_YEAR;
37
//    $flt_stat = PAYMENT_FILTER_STAT_MONTH;
38
39
    $stats = [
40
      PAYMENT_FILTER_STAT_NORMAL => [
41
        'sql_fields' => [],
42
      ],
43
      PAYMENT_FILTER_STAT_MONTH  => [
44
        'sql_fields' => [
45
          'payment_status',
46
//          'payment_user_id',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
//          'payment_user_name',
48
          'sum(if(payment_currency = "UAH", payment_amount / 11, payment_amount)) as payment_amount',
49
          'if(payment_currency = "UAH", "USD", payment_currency) as payment_currency',
50
          'sum(payment_dark_matter_paid) as payment_dark_matter_paid',
51
          'sum(payment_dark_matter_gained) as payment_dark_matter_gained',
52
          'date_format(payment_date, "%Y-%m") as payment_date',
53
          'payment_comment',
54
          'payment_module_name',
55
          'payment_external_id',
56
          'payment_external_date',
57
          'payment_external_lots',
58
          'sum(payment_external_amount) as payment_external_amount',
59
          'payment_external_currency',
60
          'payment_test',
61
        ],
62
        'sql_group'  => [
63
          'date_format(payment_date, "%Y-%m")',
64
          'if(payment_currency = "UAH", "USD", payment_currency)',
65
          'payment_external_currency',
66
          'payment_test',
67
          'payment_status',
68
        ],
69
        'sql_order'  => 'date_format(payment_date, "%Y-%m") desc',
70
      ],
71
      PAYMENT_FILTER_STAT_YEAR   => [
72
        'sql_fields' => [
73
          'payment_status',
74
//          'payment_user_id',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
//          'payment_user_name',
76
          'sum(if(payment_currency = "UAH", payment_amount / 11, payment_amount)) as payment_amount',
77
          'if(payment_currency = "UAH", "USD", payment_currency) as payment_currency',
78
          'payment_dark_matter_paid',
79
          'payment_dark_matter_gained',
80
          'date_format(payment_date, "%Y") as payment_date',
81
          'payment_comment',
82
          'payment_module_name',
83
          'payment_external_id',
84
          'payment_external_date',
85
          'payment_external_lots',
86
          'sum(payment_external_amount) as payment_external_amount',
87
          'payment_external_currency',
88
          'payment_test',
89
        ],
90
        'sql_group'  => [
91
          'date_format(payment_date, "%Y")',
92
          'if(payment_currency = "UAH", "USD", payment_currency)',
93
          'payment_external_currency',
94
          'payment_test',
95
          'payment_status',
96
        ],
97
        'sql_order'  => 'date_format(payment_date, "%Y") desc',
98
      ],
99
      PAYMENT_FILTER_STAT_ALL  => [
100
        'sql_fields' => [
101
          'payment_status',
102
//          'payment_user_id',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
103
//          'payment_user_name',
104
          'sum(if(payment_currency = "UAH", payment_amount / 11, payment_amount)) as payment_amount',
105
          'if(payment_currency = "UAH", "USD", payment_currency) as payment_currency',
106
          'payment_dark_matter_paid',
107
          'payment_dark_matter_gained',
108
//          'date_format(payment_date, "%Y") as payment_date',
109
          'payment_comment',
110
          'payment_module_name',
111
          'payment_external_id',
112
          'payment_external_date',
113
          'payment_external_lots',
114
          'sum(payment_external_amount) as payment_external_amount',
115
          'payment_external_currency',
116
          'payment_test',
117
        ],
118
        'sql_group'  => [
119
//          'date_format(payment_date, "%Y")',
120
          'if(payment_currency = "UAH", "USD", payment_currency)',
121
          'payment_external_currency',
122
          'payment_test',
123
          'payment_status',
124
        ],
125
        'sql_order'  => 'date_format(payment_date, "%Y") desc',
126
      ],
127
    ];
128
129
130
    if (!isset($stats[$flt_stat])) {
131
      $flt_stat = PAYMENT_FILTER_STAT_NORMAL;
132
    }
133
134
    $theStat = $stats[$flt_stat];
135
136
    if (!empty($theStat['sql_fields']) && $flt_payer != -1) {
137
      $theStat['sql_fields'] = array_merge($theStat['sql_fields'], [
138
        'payment_user_id',
139
        'payment_user_name',
140
      ]);
141
    }
142
143
    $query = new \DBAL\DbSqlPaging(
144
      "SELECT " .
145
      (!empty($theStat['sql_fields']) ? implode(',', $theStat['sql_fields']) : '*') .
146
      " FROM `{{payment}}` WHERE 1 " .
147
      ($flt_payer > 0 ? "AND payment_user_id = {$flt_payer} " : '') .
148
      ($flt_status >= 0 ? "AND payment_status = {$flt_status} " : '') .
149
      ($flt_test >= 0 ? "AND payment_test = {$flt_test} " : '') .
150
      ($flt_module ? "AND payment_module_name = '{$flt_module}' " : '') .
151
152
      (!empty($theStat['sql_group']) ? ' GROUP BY ' . implode(',', $theStat['sql_group']) : '') .
153
      ' ORDER BY ' . (!empty($theStat['sql_order']) ? $theStat['sql_order'] : 'payment_id desc')
154
      ,
155
      PAGING_PAGE_SIZE_DEFAULT_PAYMENTS,
156
      sys_get_param_int(PagingRenderer::KEYWORD)
157
    );
158
159
    $pager = new PagingRenderer($query, 'index.php?' . $_SERVER['QUERY_STRING']);
160
    $pager->setDelta(10);
161
162
    foreach ($query as $row) {
163
      $row2 = array();
164
      foreach ($row as $key => $value) {
165
        $row2[strtoupper($key)] = $value;
166
      }
167
      $template->assign_block_vars('payment', $row2);
168
    }
169
170
    tpl_assign_select($template, 'payer', self::getPayers());
171
    tpl_assign_select($template, 'module', self::getUsedModules());
172
    tpl_assign_select($template, 'status', SN::$lang['adm_pay_filter_status']);
173
    tpl_assign_select($template, 'test', SN::$lang['adm_pay_filter_test']);
174
    tpl_assign_select($template, 'flt_stat', SN::$lang['adm_pay_filter_stat']);
175
    tpl_assign_select($template, 'flt_currency', self::getCurrencies());
176
177
    $template->assign_vars(array(
178
      'FLT_PAYER'    => $flt_payer,
179
      'FLT_STATUS'   => $flt_status,
180
      'FLT_TEST'     => $flt_test,
181
      'FLT_MODULE'   => $flt_module,
182
      'FLT_CURRENCY' => $flt_currency,
183
      'FLT_STAT'     => $flt_stat,
184
185
      'PAGER_PAYMENTS' => $pager->render(),
186
    ));
187
188
    display($template, $lang['adm_pay_stats']);
189
  }
190
191
  /**
192
   * @return array
193
   */
194
  protected static function getUsedModules() {
195
    $module_list = array(
196
      '' => SN::$lang['adm_pay_filter_all'],
197
    );
198
    $query = doquery("SELECT distinct payment_module_name FROM `{{payment}}` ORDER BY payment_module_name");
199
    while ($row = db_fetch($query)) {
200
      $module_list[$row['payment_module_name']] = $row['payment_module_name'];
201
    }
202
203
    return $module_list;
204
  }
205
206
  /**
207
   * @return array
208
   */
209
  protected static function getPayers() {
210
    $payer_list = array(
211
      -1 => SN::$lang['adm_pay_filter_all'],
212
    );
213
    $query = doquery("SELECT payment_user_id, payment_user_name FROM `{{payment}}` GROUP BY payment_user_id ORDER BY payment_user_name");
214
    while ($row = db_fetch($query)) {
215
      $payer_list[$row['payment_user_id']] = '[' . $row['payment_user_id'] . '] ' . $row['payment_user_name'];
216
    }
217
218
    return $payer_list;
219
  }
220
221
  /**
222
   * @return array
223
   */
224
  protected static function getCurrencies() {
225
    $payer_list = array(
226
      -1 => SN::$lang['adm_pay_filter_all'],
227
    );
228
    $query = doquery("SELECT distinct payment_external_currency FROM `{{payment}}`");
229
    while ($row = db_fetch($query)) {
230
      $payer_list[$row['payment_external_currency']] = $row['payment_external_currency'];
231
    }
232
233
    return $payer_list;
234
  }
235
236
}
237