Conditions | 16 |
Paths | 3026 |
Total Lines | 169 |
Code Lines | 103 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
11 | function sn_imperator_view($template = null) { |
||
12 | global $template_result, $config, $lang, $user; |
||
13 | |||
14 | $stat_fields = array( |
||
15 | 'stat_date' => 'STAT_DATE', |
||
16 | |||
17 | // 'stat_code' => 'STAT_CODE', |
||
18 | 'total_rank' => 'TOTAL_RANK', |
||
19 | 'total_points' => 'TOTAL_POINTS', |
||
20 | //'total_count' => 'TOTAL_COUNT', |
||
21 | 'tech_rank' => 'TECH_RANK', |
||
22 | 'tech_points' => 'TECH_POINTS', |
||
23 | //'tech_count' => 'TECH_COUNT', |
||
24 | 'build_rank' => 'BUILD_RANK', |
||
25 | 'build_points' => 'BUILD_POINTS', |
||
26 | //'build_count' => 'BUILD_COUNT', |
||
27 | 'defs_rank' => 'DEFS_RANK', |
||
28 | 'defs_points' => 'DEFS_POINTS', |
||
29 | //'defs_count' => 'DEFS_COUNT', |
||
30 | 'fleet_rank' => 'FLEET_RANK', |
||
31 | 'fleet_points' => 'FLEET_POINTS', |
||
32 | //'fleet_count' => 'FLEET_COUNT', |
||
33 | 'res_rank' => 'RES_RANK', |
||
34 | 'res_points' => 'RES_POINTS', |
||
35 | // 'res_count' => 'RES_COUNT', |
||
36 | ); |
||
37 | |||
38 | $user_id = sys_get_param_id('int_user_id', $user['id']); |
||
39 | |||
40 | $user_data = ($same_user = $user_id == $user['id']) ? $user : db_user_by_id($user_id); |
||
41 | |||
42 | // if($user_id == $user['id']) { |
||
43 | // $user_data = &$user; |
||
44 | // $same_user = true; |
||
45 | // } else { |
||
46 | // $user_data = db_user_by_id($user_id); |
||
47 | // $same_user = false; |
||
48 | // } |
||
49 | |||
50 | if(!$user_data) { |
||
51 | SnTemplate::messageBox($lang['imp_imperator_none'], $lang['sys_error'], 'index.php', 10); |
||
52 | die(); |
||
53 | } |
||
54 | |||
55 | $template = SnTemplate::gettemplate('imperator', $template); |
||
56 | $StatRecord = doquery("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `stat_code` = 1 AND `id_owner` = {$user_id};", true); |
||
57 | |||
58 | $stat_array = array(); |
||
59 | $query = doquery("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `id_owner` = {$user_id} ORDER BY `stat_code` DESC;"); |
||
60 | $stat_count = SN::$db->db_affected_rows(); |
||
61 | while($row = db_fetch($query)) { |
||
62 | foreach($stat_fields as $field_db_name => $field_template_name) { |
||
63 | // $stat_count - $row['stat_code'] - для реверсирования ID статы в JS |
||
64 | $stat_array[$field_template_name]['DATA'][$stat_count - $row['stat_code']] = $row[$field_db_name]; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $stat_array_date = $stat_array['STAT_DATE']; |
||
69 | empty($stat_array_date['DATA']) ? $stat_array_date['DATA'] = array() : false; |
||
70 | foreach($stat_array_date['DATA'] as $key => $value) { |
||
71 | $template->assign_block_vars('stat_date', array( |
||
72 | 'ID' => $key, |
||
73 | 'VALUE' => $value, |
||
74 | 'TEXT' => date(FMT_DATE_TIME, $value), |
||
75 | )); |
||
76 | } |
||
77 | |||
78 | unset($stat_array['STAT_DATE']); |
||
79 | $template_data = array(); |
||
80 | foreach($stat_array as $stat_type => &$stat_type_data) { |
||
81 | $reverse_min_max = strpos($stat_type, '_RANK') !== false; |
||
82 | $stat_type_data['MIN'] = $reverse_min_max ? max($stat_type_data['DATA']) : min($stat_type_data['DATA']); |
||
83 | $stat_type_data['MAX'] = $reverse_min_max ? min($stat_type_data['DATA']) : max($stat_type_data['DATA']); |
||
84 | $stat_type_data['AVG'] = avg($stat_type_data['DATA']); |
||
85 | foreach($stat_type_data['DATA'] as $key => $value) { |
||
86 | $stat_type_data['PERCENT'][$key] = ($stat_type_data['MAX'] - $value ? ($value - $stat_type_data['MIN']) / ($stat_type_data['MAX'] - $stat_type_data['MIN']) : 1) * 100; |
||
87 | $template_data[$stat_type][$key]['ID'] = $key; |
||
88 | $template_data[$stat_type][$key]['VALUE'] = $value; |
||
89 | $template_data[$stat_type][$key]['DELTA'] = ($reverse_min_max ? $stat_type_data['MIN'] - $value : $value - $stat_type_data['MAX']); |
||
90 | $template_data[$stat_type][$key]['PERCENT'] = $stat_type_data['PERCENT'][$key]; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | foreach($template_data as $stat_type => $stat_type_data) { |
||
95 | $template->assign_block_vars('stat', array( |
||
96 | 'TYPE' => $stat_type, |
||
97 | 'TEXT' => $lang['imp_stat_types'][$stat_type], |
||
98 | 'MIN' => $stat_array[$stat_type]['MIN'], |
||
99 | 'MAX' => $stat_array[$stat_type]['MAX'], |
||
100 | 'AVG' => $stat_array[$stat_type]['AVG'], |
||
101 | )); |
||
102 | foreach($stat_type_data as $stat_entry) { |
||
103 | $template->assign_block_vars('stat.entry', $stat_entry); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | |||
108 | if($same_user) { |
||
109 | rpg_level_up($user, RPG_STRUCTURE); |
||
110 | rpg_level_up($user, RPG_RAID); |
||
111 | rpg_level_up($user, RPG_TECH); |
||
112 | rpg_level_up($user, RPG_EXPLORE); |
||
113 | |||
114 | |||
115 | /* |
||
116 | // ----------------------------------------------------------------------------------------------- |
||
117 | // News Frame ... |
||
118 | if ($config->game_news_overview) |
||
119 | { |
||
120 | nws_render($template, "WHERE UNIX_TIMESTAMP(`tsTimeStamp`)<=" . SN_TIME_NOW . "", $config->game_news_overview); |
||
121 | } |
||
122 | */ |
||
123 | } |
||
124 | |||
125 | |||
126 | $template->assign_vars(array( |
||
127 | 'USERS_TOTAL' => $config->users_amount, |
||
128 | |||
129 | 'USER_ID' => $user_id, |
||
130 | 'user_username' => player_nick_render_to_html($user_data, true), |
||
131 | // 'user_gender' => $user_data['gender'] == 'F' ? 'female' : 'male', |
||
132 | 'USER_AVATAR' => $user_data['avatar'], |
||
133 | 'VACATION' => $user_data['vacation'], |
||
134 | 'GENDER_TEXT' => $lang['sys_gender_list'][$user_data['gender']], |
||
135 | |||
136 | 'PLAYER_RANK_NUMBER' => $playerRank = SN::$gc->playerLevelHelper->getPointLevel($user_data['total_points'], $user_data['authlevel']), |
||
137 | 'PLAYER_RANK_NAME' => $lang['ranks'][$playerRank], |
||
138 | |||
139 | 'NEW_MESSAGES' => $user_data['new_message'], |
||
140 | 'REGISTRATION_DATE' => date(FMT_DATE_TIME, $user_data['register_time']), |
||
141 | |||
142 | 'builder_xp' => HelperString::numberFloorAndFormat($user_data['xpminier']), |
||
143 | 'builder_lvl' => HelperString::numberFloorAndFormat($user_data['lvl_minier']), |
||
144 | 'builder_lvl_st' => HelperString::numberFloorAndFormat(rpg_get_miner_xp($user_data['lvl_minier'])), |
||
145 | 'builder_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_miner_xp($user_data['lvl_minier']+1)), |
||
146 | 'raid_xp' => HelperString::numberFloorAndFormat($user_data['xpraid']), |
||
147 | 'raid_lvl' => HelperString::numberFloorAndFormat($user_data['lvl_raid']), |
||
148 | 'raid_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_raider_xp($user_data['lvl_raid']+1)), |
||
149 | 'raids' => HelperString::numberFloorAndFormat($user_data['raids']), |
||
150 | 'raidswin' => HelperString::numberFloorAndFormat($user_data['raidswin']), |
||
151 | 'raidsloose' => HelperString::numberFloorAndFormat($user_data['raidsloose']), |
||
152 | 'tech_xp' => HelperString::numberFloorAndFormat($user_data['player_rpg_tech_xp']), |
||
153 | 'tech_lvl' => HelperString::numberFloorAndFormat($user_data['player_rpg_tech_level']), |
||
154 | 'tech_lvl_st' => HelperString::numberFloorAndFormat(rpg_get_tech_xp($user_data['player_rpg_tech_level'])), |
||
155 | 'tech_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_tech_xp($user_data['player_rpg_tech_level']+1)), |
||
156 | |||
157 | 'explore_xp' => HelperString::numberFloorAndFormat($user_data['player_rpg_explore_xp']), |
||
158 | 'explore_lvl' => HelperString::numberFloorAndFormat($user_data['player_rpg_explore_level']), |
||
159 | 'explore_lvl_st' => HelperString::numberFloorAndFormat(rpg_get_explore_xp($user_data['player_rpg_explore_level'])), |
||
160 | 'explore_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_explore_xp($user_data['player_rpg_explore_level']+1)), |
||
161 | |||
162 | 'build_points' => HelperString::numberFloorAndFormat( $StatRecord['build_points'] ), |
||
163 | 'tech_points' => HelperString::numberFloorAndFormat( $StatRecord['tech_points'] ), |
||
164 | 'fleet_points' => HelperString::numberFloorAndFormat( $StatRecord['fleet_points'] ), |
||
165 | 'defs_points' => HelperString::numberFloorAndFormat( $StatRecord['defs_points'] ), |
||
166 | 'res_points' => HelperString::numberFloorAndFormat( $StatRecord['res_points'] ), |
||
167 | 'total_points' => HelperString::numberFloorAndFormat( $StatRecord['total_points'] ), |
||
168 | 'user_rank' => $StatRecord['total_rank'], |
||
169 | 'RANK_DIFF' => $StatRecord['total_old_rank'] - $StatRecord['total_rank'], |
||
170 | |||
171 | 'STAT_COUNT' => $stat_count, |
||
172 | 'STAT_SPAN' => $stat_count + 1, |
||
173 | |||
174 | // 'GAME_NEWS_OVERVIEW' => $config->game_news_overview, |
||
175 | |||
176 | 'SAME_USER' => $same_user, |
||
177 | )); |
||
178 | |||
179 | return $template; |
||
180 | } |
||
181 |