Completed
Push — work-fleets ( f5fbda...1bdd41 )
by SuperNova.WS
06:04
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
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;
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'] : classLocale::$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' => classLocale::$lang['stat_player']),
46
);
47
if(!$source) {
48
  $subject_list[2] = array('header' => classLocale::$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() : db_ally_count());
111
// pdump($record_count, '$record_count');
112
// $record_count = db_num_rows($query);
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' => pretty_number($row['points']),
133
  );
134
//pdump($row);
135
136
  if($who == 1) {
137
    $row_stat['ALLY_NAME'] = $row['ally_name'];
138
    $row_stat['ALLY_ID'] = $row['ally_id'];
139
    empty($row['username']) ? $row['username'] = $row['name'] : false;
140
    $row_stat['NAME'] = player_nick_render_to_html($row, array('icons' => empty($source), 'color' => empty($source)));
141
//    $row_stat['NAME'] = player_nick_render_to_html(array(
142
//      'id' => $row['id'],
143
//      // TODO - Добавлять реальное имя игрока на Блице для закрытого раунда
144
//      'username' => $row['name'],
145
//      'gender' => isset($row['gender']) ? $row['gender'] : GENDER_UNKNOWN,
146
//      // 'gender',
147
//      // 'race',
148
//      // 'ally_tag',
149
//    ), array('icons' => empty($source), 'color' => empty($source)));
150
  } else {
151
    $row_stat['MEMBERS'] = $row['ally_members'];
152
    $row_stat['POINTS_PER_MEMBER'] = pretty_number(floor($row['points'] / $row['ally_members']));
153
    $row_stat['NAME'] = $row['name'];
154
  }
155
156
  $template->assign_block_vars('stat', $row_stat);
157
}
158
159
$next_run = sys_schedule_get_prev_run(classSupernova::$config->stats_schedule, classSupernova::$config->var_stat_update, true);
0 ignored issues
show
The property stats_schedule does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property var_stat_update does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
160
$template->assign_vars(array(
161
  'REFRESH_DATE' => classSupernova::$config->var_stat_update ? date(FMT_DATE_TIME, strtotime(classSupernova::$config->var_stat_update) + SN_CLIENT_TIME_DIFF) : '',
0 ignored issues
show
The property var_stat_update does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
162
  'NEXT_DATE' => $next_run ? date(FMT_DATE_TIME, $next_run + SN_CLIENT_TIME_DIFF) : '',
163
  'RANGE' => $range,
164
  'SUBJECT' => $who,
165
  'TYPE' => $type,
166
  'USER_ALLY' => $user['ally_id'],
167
  // TODO - Для блица - вытаскивать blitz_player_id и подсвечивать пользователя на блице
168
  'USER_ID' => $source ? 0 : $user['id'],
169
  'SOURCE' => $source,
170
  'STATS_HIDE_PM_LINK' => classSupernova::$config->stats_hide_pm_link || $source,
0 ignored issues
show
The property stats_hide_pm_link does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
171
));
172
173
display($template, classLocale::$lang['stat_header'], !empty($user), '', false, !empty($user));
174