Test Failed
Push — trunk ( e02d87...314b8c )
by SuperNova.WS
07:20
created
Labels
Severity
1
<?php
2
3
use Alliance\DBStaticAlly;
4
5
/**
6
 * stat.php
7
 *
8
 * 2.0 copyright (c) 2010-2012 by Gorlum for http://supernova.ws
9
 *   [!] Full rewrote
10
*/
11
12
function stat_tpl_assign(&$template, $selected, $array_name, $array, $sn_group_stat_common) {
13
  global $who, $lang;
14
15
  // $sn_group_stat_common = sn_get_groups('STAT_COMMON');
16
  foreach($array as $key => $value) {
17
    if($array_name == 'type' && $who == 2 && !in_array($key, $sn_group_stat_common)) {
18
      continue;
19
    }
20
21
    $header = isset($value['header']) ? $value['header'] : $lang['stat_type'][$key];
22
23
    $template->assign_block_vars($array_name, array(
24
      'ID'       => $key,
25
      'HEADER'   => $header,
26
      'SELECTED' => $key == $selected,
27
    ));
28
  }
29
}
30
31
$allow_anonymous = true;
32
33
include('common.' . substr(strrchr(__FILE__, '.'), 1));
34
35
lng_include('stat');
36
37
$sn_group_stat_common = sn_get_groups('STAT_COMMON');
38
$who = sys_get_param_int('who', 1);
39
$type = sys_get_param_int('type');
40
$type = $who != 1 && !in_array($type, $sn_group_stat_common) ? 1 : $type;
41
$range = sys_get_param_int('range', 1);
42
$source = sys_get_param_str('source');
43
44
$template = SnTemplate::gettemplate('stat_statistics', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

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

44
$template = SnTemplate::gettemplate('stat_statistics', /** @scrutinizer ignore-type */ true);
Loading history...
45
46
$subject_list = array(
47
  1 => array('header' => $lang['stat_player']),
48
);
49
if(!$source) {
50
  $subject_list[2] = array('header' => $lang['stat_allys']);
51
}
52
stat_tpl_assign($template, $who, 'subject', $subject_list, $sn_group_stat_common);
53
54
$stat_types = array(
55
   STAT_TOTAL => array(
56
     'type' => 'total',
57
   ),
58
59
   STAT_FLEET => array(
60
     'type' => 'fleet',
61
   ),
62
63
   STAT_TECH => array(
64
     'type' => 'tech',
65
   ),
66
67
   STAT_BUILDING => array(
68
     'type' => 'build',
69
   ),
70
71
   STAT_DEFENSE => array(
72
     'type' => 'defs',
73
   ),
74
75
   STAT_RESOURCE => array(
76
     'type' => 'res',
77
   ),
78
79
   STAT_RAID_TOTAL => array(
80
     'type' => 'raids',
81
   ),
82
83
   STAT_RAID_WON => array(
84
     'type' => 'raidswin',
85
   ),
86
87
   STAT_RAID_LOST => array(
88
     'type' => 'raidsloose',
89
   ),
90
91
  STAT_LVL_BUILDING => array(
92
     'type' => 'lvl_minier',
93
  ),
94
95
  STAT_LVL_TECH => array(
96
     'type' => 'player_rpg_tech_level',
97
  ),
98
99
  STAT_LVL_RAID => array(
100
     'type' => 'lvl_raid',
101
  ),
102
);
103
stat_tpl_assign($template, $type, 'type', $stat_types, $sn_group_stat_common);
104
105
$Rank = $stat_types[$type]['type'];
106
107
$is_common_stat = in_array($type, $sn_group_stat_common);
108
$start = floor($range / 100 % 100) * 100;
109
$query = db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source);
110
111
// TODO - Не работает, если игроков на Блице > 100
112
$record_count = $source ? db_num_rows($query) : ($who == 1 ? db_user_count() : DBStaticAlly::db_ally_count());
113
114
$page_count = floor($record_count / 100);
115
$pages = array();
116
for($i = 0; $i <= $page_count; $i++) {
117
  $first_element = $i * 100 + 1;
118
  $last_element = $first_element + 99;
119
  $pages[$first_element] = array(
120
    'header' => "{$first_element}-{$last_element}",
121
  );
122
}
123
124
$range = $range > $record_count ? $record_count : $range;
125
stat_tpl_assign($template, $range, 'range', $pages, $sn_group_stat_common);
126
127
while ($row = db_fetch($query)) {
128
  $row_stat = array(
129
    'ID' => $row['id'],
130
    'RANK'        => $row['rank'],
131
    'RANK_CHANGE' => $row['rank_old'] ? $row['rank_old'] - $row['rank'] : 0,
132
    'POINTS' => HelperString::numberFloorAndFormat($row['points']),
133
  );
134
135
  if($who == 1) {
136
    $row_stat['ALLY_NAME'] = $row['ally_name'];
137
    $row_stat['ALLY_ID'] = $row['ally_id'];
138
    empty($row['username']) ? $row['username'] = $row['name'] : false;
139
    $row_stat['NAME'] = player_nick_render_to_html($row, [
140
      'icons' => empty($source),
141
      'color' => empty($source),
142
    ]);
143
144
145
//      // TODO - Добавлять реальное имя игрока на Блице для закрытого раунда
146
  } else {
147
    $row_stat['MEMBERS'] = $row['ally_members'];
148
    $row_stat['POINTS_PER_MEMBER'] = HelperString::numberFloorAndFormat(floor($row['points'] / $row['ally_members']));
149
    $row_stat['NAME'] = $row['name'];
150
  }
151
152
  $template->assign_block_vars('stat', $row_stat);
153
}
154
155
$next_run = sys_schedule_get_prev_run(SN::$config->stats_schedule, SN::$config->var_stat_update, true);
156
$template->assign_vars(array(
157
  'REFRESH_DATE' => SN::$config->var_stat_update ? date(FMT_DATE_TIME, strtotime(SN::$config->var_stat_update) + SN_CLIENT_TIME_DIFF) : '',
158
  'NEXT_DATE' => $next_run ? date(FMT_DATE_TIME, $next_run + SN_CLIENT_TIME_DIFF) : '',
159
  'RANGE' => $range,
160
  'SUBJECT' => $who,
161
  'TYPE' => $type,
162
  'USER_ALLY' => $user['ally_id'],
163
  // TODO - Для блица - вытаскивать blitz_player_id и подсвечивать пользователя на блице
164
  'USER_ID' => $source ? 0 : $user['id'],
165
  'SOURCE' => $source,
166
  'STATS_HIDE_PM_LINK' => SN::$config->stats_hide_pm_link || $source,
167
));
168
169
SnTemplate::display($template, $lang['stat_header']);
170