Completed
Push — trunk ( 91a948...0e7a2e )
by SuperNova.WS
05:44
created
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 29.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * stat.php
5
 *
6
 * 2.0 copyright (c) 2010-2012 by Gorlum for http://supernova.ws
7
 *   [!] Full rewrote
8
*/
9
10
function stat_tpl_assign(&$template, $selected, $array_name, $array, $sn_group_stat_common) {
11
  global $who, $lang;
12
13
  // $sn_group_stat_common = sn_get_groups('STAT_COMMON');
14
  foreach($array as $key => $value) {
15
    if($array_name == 'type' && $who == 2 && !in_array($key, $sn_group_stat_common)) {
16
      continue;
17
    }
18
19
    $header = isset($value['header']) ? $value['header'] : $lang['stat_type'][$key];
20
21
    $template->assign_block_vars($array_name, array(
22
      'ID'       => $key,
23
      'HEADER'   => $header,
24
      'SELECTED' => $key == $selected,
25
    ));
26
  }
27
}
28
29
$allow_anonymous = true;
30
31
include('common.' . substr(strrchr(__FILE__, '.'), 1));
32
33
lng_include('stat');
34
35
$sn_group_stat_common = sn_get_groups('STAT_COMMON');
36
$who = sys_get_param_int('who', 1);
37
$type = sys_get_param_int('type');
38
$type = $who != 1 && !in_array($type, $sn_group_stat_common) ? 1 : $type;
39
$range = sys_get_param_int('range', 1);
40
$source = sys_get_param_str('source');
41
42
$template = gettemplate('stat_statistics', true);
43
44
$subject_list = array(
45
  1 => array('header' => $lang['stat_player']),
46
);
47
if(!$source) {
48
  $subject_list[2] = array('header' => $lang['stat_allys']);
49
}
50
stat_tpl_assign($template, $who, 'subject', $subject_list, $sn_group_stat_common);
51
52
$stat_types = array(
53
   STAT_TOTAL => array(
54
     'type' => 'total',
55
   ),
56
57
   STAT_FLEET => array(
58
     'type' => 'fleet',
59
   ),
60
61
   STAT_TECH => array(
62
     'type' => 'tech',
63
   ),
64
65
   STAT_BUILDING => array(
66
     'type' => 'build',
67
   ),
68
69
   STAT_DEFENSE => array(
70
     'type' => 'defs',
71
   ),
72
73
   STAT_RESOURCE => array(
74
     'type' => 'res',
75
   ),
76
77
   STAT_RAID_TOTAL => array(
78
     'type' => 'raids',
79
   ),
80
81
   STAT_RAID_WON => array(
82
     'type' => 'raidswin',
83
   ),
84
85
   STAT_RAID_LOST => array(
86
     'type' => 'raidsloose',
87
   ),
88
89
  STAT_LVL_BUILDING => array(
90
     'type' => 'lvl_minier',
91
  ),
92
93
  STAT_LVL_TECH => array(
94
     'type' => 'player_rpg_tech_level',
95
  ),
96
97
  STAT_LVL_RAID => array(
98
     'type' => 'lvl_raid',
99
  ),
100
);
101
stat_tpl_assign($template, $type, 'type', $stat_types, $sn_group_stat_common);
102
103
$Rank = $stat_types[$type]['type'];
104
105
$is_common_stat = in_array($type, $sn_group_stat_common);
106
$start = floor($range / 100 % 100) * 100;
107
$query = db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source);
108
109
// TODO - Не работает, если игроков на Блице > 100
110
$record_count = $source ? db_num_rows($query) : ($who == 1 ? db_user_count() : DBStaticAlly::db_ally_count());
111
112
$page_count = floor($record_count / 100);
113
$pages = array();
114
for($i = 0; $i <= $page_count; $i++) {
115
  $first_element = $i * 100 + 1;
116
  $last_element = $first_element + 99;
117
  $pages[$first_element] = array(
118
    'header' => "{$first_element}-{$last_element}",
119
  );
120
}
121
122
$range = $range > $record_count ? $record_count : $range;
123
stat_tpl_assign($template, $range, 'range', $pages, $sn_group_stat_common);
124
125
while ($row = db_fetch($query)) {
126
  $row_stat = array(
127
    'ID' => $row['id'],
128
    'RANK'        => $row['rank'],
129
    'RANK_CHANGE' => $row['rank_old'] ? $row['rank_old'] - $row['rank'] : 0,
130
    'POINTS' => HelperString::numberFloorAndFormat($row['points']),
131
  );
132
133
  if($who == 1) {
134
    $row_stat['ALLY_NAME'] = $row['ally_name'];
135
    $row_stat['ALLY_ID'] = $row['ally_id'];
136
    empty($row['username']) ? $row['username'] = $row['name'] : false;
137
    $row_stat['NAME'] = player_nick_render_to_html($row, [
138
      'icons' => empty($source),
139
      'color' => empty($source),
140
    ]);
141
142
143
//      // TODO - Добавлять реальное имя игрока на Блице для закрытого раунда
144
  } else {
145
    $row_stat['MEMBERS'] = $row['ally_members'];
146
    $row_stat['POINTS_PER_MEMBER'] = HelperString::numberFloorAndFormat(floor($row['points'] / $row['ally_members']));
147
    $row_stat['NAME'] = $row['name'];
148
  }
149
150
  $template->assign_block_vars('stat', $row_stat);
151
}
152
153
$next_run = sys_schedule_get_prev_run(SN::$config->stats_schedule, SN::$config->var_stat_update, true);
154
$template->assign_vars(array(
155
  'REFRESH_DATE' => SN::$config->var_stat_update ? date(FMT_DATE_TIME, strtotime(SN::$config->var_stat_update) + SN_CLIENT_TIME_DIFF) : '',
156
  'NEXT_DATE' => $next_run ? date(FMT_DATE_TIME, $next_run + SN_CLIENT_TIME_DIFF) : '',
157
  'RANGE' => $range,
158
  'SUBJECT' => $who,
159
  'TYPE' => $type,
160
  'USER_ALLY' => $user['ally_id'],
161
  // TODO - Для блица - вытаскивать blitz_player_id и подсвечивать пользователя на блице
162
  'USER_ID' => $source ? 0 : $user['id'],
163
  'SOURCE' => $source,
164
  'STATS_HIDE_PM_LINK' => SN::$config->stats_hide_pm_link || $source,
165
));
166
167
display($template, $lang['stat_header']);
168