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
|
|
|
use SnTemplate; |
12
|
|
|
|
13
|
|
|
class PageAdminMining extends PageDeprecated { |
14
|
|
|
const PAGE_SORT_BY_PRODUCTION = 0; |
15
|
|
|
const PAGE_SORT_BY_RANK = 1; |
16
|
|
|
const PAGE_SORT_BY_ID = 2; |
17
|
|
|
const PAGE_SORT_BY_NAME = 3; |
18
|
|
|
const PAGE_SORT_BY_POINTS = 4; |
19
|
|
|
|
20
|
|
|
public static function viewStatic() { |
21
|
|
|
$sorting = [ |
22
|
|
|
static::PAGE_SORT_BY_PRODUCTION => [ |
23
|
|
|
'ID' => static::PAGE_SORT_BY_PRODUCTION, |
24
|
|
|
'HTML_ID' => 'sortByTotalProduction', |
25
|
|
|
'HTML_NAME' => '{ byTotalProduction }', |
26
|
|
|
'SQL_SORT' => ['$specialField'], |
27
|
|
|
], |
28
|
|
|
self::PAGE_SORT_BY_RANK => [ |
29
|
|
|
'ID' => self::PAGE_SORT_BY_RANK, |
30
|
|
|
'HTML_ID' => 'byTotalRank', |
31
|
|
|
'HTML_NAME' => '{ byTotalRank }', |
32
|
|
|
'SQL_SORT' => ['u.total_rank',], |
33
|
|
|
], |
34
|
|
|
self::PAGE_SORT_BY_ID => [ |
35
|
|
|
'ID' => self::PAGE_SORT_BY_ID, |
36
|
|
|
'HTML_ID' => 'byId', |
37
|
|
|
'HTML_NAME' => '{ byId }', |
38
|
|
|
'SQL_SORT' => ['u.id',], |
39
|
|
|
], |
40
|
|
|
self::PAGE_SORT_BY_NAME => [ |
41
|
|
|
'ID' => self::PAGE_SORT_BY_NAME, |
42
|
|
|
'HTML_ID' => 'byName', |
43
|
|
|
'HTML_NAME' => '{ byName }', |
44
|
|
|
'SQL_SORT' => ['u.username',], |
45
|
|
|
], |
46
|
|
|
|
47
|
|
|
self::PAGE_SORT_BY_POINTS => [ |
48
|
|
|
'ID' => self::PAGE_SORT_BY_POINTS, |
49
|
|
|
'HTML_ID' => 'byTotalPoints', |
50
|
|
|
'HTML_NAME' => '{ byTotalPoints }', |
51
|
|
|
'SQL_SORT' => ['u.total_points DESC'], |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
// Currently unused - because it duplicates sorting by rank for now |
56
|
|
|
unset($sorting[self::PAGE_SORT_BY_POINTS]); |
57
|
|
|
|
58
|
|
|
define('IN_ADMIN', true); |
59
|
|
|
|
60
|
|
|
lng_include('admin'); |
61
|
|
|
|
62
|
|
|
$specialField = |
63
|
|
|
'sum(metal_perhour) * ' . get_unit_cost_in([RES_METAL => 1]) . ' + ' . |
64
|
|
|
'sum(crystal_perhour) * ' . get_unit_cost_in([RES_CRYSTAL => 1]) . ' + ' . |
65
|
|
|
'sum(deuterium_perhour) * ' . get_unit_cost_in([RES_DEUTERIUM => 1]); |
66
|
|
|
$sorting[static::PAGE_SORT_BY_PRODUCTION]['SQL_SORT'] = [$specialField . ' DESC']; |
67
|
|
|
|
68
|
|
|
$filterActive = sys_get_param_int('ACTIVE_STATUS', 0); |
69
|
|
|
$sortBy = sys_get_param_int('SORT_BY', static::PAGE_SORT_BY_PRODUCTION); |
70
|
|
|
array_key_exists($sortBy, $sorting) ?: ($sortBy = static::PAGE_SORT_BY_PRODUCTION); |
71
|
|
|
|
72
|
|
|
$stringSqlQuery = " |
73
|
|
|
SELECT |
74
|
|
|
u.id, username, total_rank, total_points, |
75
|
|
|
sum(metal_perhour) AS `metal_prod`, |
76
|
|
|
sum(crystal_perhour) AS `crystal_prod`, |
77
|
|
|
sum(deuterium_perhour) AS `deuterium_prod`, |
78
|
|
|
{$specialField} AS `total_prod`, |
79
|
|
|
avg(metal_mine_porcent) AS `average_metal_percent`, |
80
|
|
|
avg(crystal_mine_porcent) AS `average_crystal_percent`, |
81
|
|
|
avg(deuterium_sintetizer_porcent) AS `average_deuterium_percent` |
82
|
|
|
FROM |
83
|
|
|
`{{planets}}` AS p |
84
|
|
|
LEFT JOIN `{{users}}` AS u ON u.id = p.id_owner |
85
|
|
|
WHERE |
86
|
|
|
u.total_rank <> 0 |
87
|
|
|
AND metal_mine_porcent != 0 |
88
|
|
|
AND crystal_mine_porcent != 0 |
89
|
|
|
AND deuterium_sintetizer_porcent != 0 |
90
|
|
|
AND `user_as_ally` IS NULL" |
91
|
|
|
. ($filterActive == self::PAGE_SORT_BY_NAME ? " AND FROM_UNIXTIME(u.`onlinetime`) >= DATE_SUB(NOW(), INTERVAL " . PLAYER_INACTIVE_TIMEOUT_LONG . " SECOND) " : '') |
92
|
|
|
. ($filterActive == self::PAGE_SORT_BY_ID ? " AND FROM_UNIXTIME(u.`onlinetime`) >= DATE_SUB(NOW(), INTERVAL " . PLAYER_INACTIVE_TIMEOUT . " SECOND) " : '') |
93
|
|
|
. " |
94
|
|
|
GROUP BY |
95
|
|
|
id_owner |
96
|
|
|
" . " ORDER BY " . implode(',', $sorting[$sortBy]['SQL_SORT']); |
97
|
|
|
|
98
|
|
|
// View all at one page // $iterator = SN::$db->selectIterator($stringSqlQuery); |
99
|
|
|
$iterator = new DbSqlPaging($stringSqlQuery, 50, sys_get_param_int(PagingRenderer::KEYWORD)); |
100
|
|
|
|
101
|
|
|
$render = []; |
102
|
|
|
foreach ($iterator as $row) { |
103
|
|
|
$render[] = [ |
104
|
|
|
'ID' => $row['id'], |
105
|
|
|
'NAME' => player_nick_render_to_html($row, true), |
106
|
|
|
'NAME_clear' => $row['username'], |
107
|
|
|
'RANK' => $row['total_rank'], |
108
|
|
|
'POINTS' => $row['total_points'], |
109
|
|
|
'METAL' => $row['metal_prod'], |
110
|
|
|
'CRYSTAL' => $row['crystal_prod'], |
111
|
|
|
'DEUTERIUM' => $row['deuterium_prod'], |
112
|
|
|
'TOTAL' => $row['total_prod'], |
113
|
|
|
'TOTAL_CALC' => get_unit_cost_in([ |
114
|
|
|
RES_METAL => $row['metal_prod'], |
115
|
|
|
RES_CRYSTAL => $row['crystal_prod'], |
116
|
|
|
RES_DEUTERIUM => $row['deuterium_prod'], |
117
|
|
|
]), |
118
|
|
|
'PERCENT' => |
119
|
|
|
round($row['average_metal_percent'], 2) . '/' . |
120
|
|
|
round($row['average_crystal_percent'], 2) . '/' . |
121
|
|
|
round($row['average_deuterium_percent'], 2), |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$template = SnTemplate::gettemplate('admin/admin_mining'); |
126
|
|
|
|
127
|
|
|
$sorting[$sortBy]['CHECKED'] = true; |
128
|
|
|
$template->assign_recursive(['.' => ['sorting' => $sorting]]); |
129
|
|
|
|
130
|
|
|
$pager = new PagingRenderer($iterator, |
131
|
|
|
'index.php?page=admin/admin_mining' . |
132
|
|
|
'&ACTIVE_STATUS=' . intval($filterActive) . |
133
|
|
|
'&SORT_BY=' . intval($sortBy) |
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
$template->assign_recursive([ |
137
|
|
|
'PAGE_NAME' => SN::$lang['menu_admin_mining'], |
138
|
|
|
|
139
|
|
|
'PAGER_MESSAGES' => $pager ? $pager->render() : '', |
|
|
|
|
140
|
|
|
|
141
|
|
|
'SORT_BY' => $sortBy, |
142
|
|
|
'ACTIVE_STATUS' => $filterActive, |
143
|
|
|
|
144
|
|
|
'.' => ['production' => $render], |
145
|
|
|
]); |
146
|
|
|
SnTemplate::display($template, SN::$lang['menu_admin_mining']); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
} |
150
|
|
|
|