|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DBStaticUser extends DBStaticRecord { |
|
4
|
|
|
|
|
5
|
|
|
public static $_table = 'users'; |
|
6
|
|
|
public static $_idField = 'id'; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @param int $user_id |
|
11
|
|
|
* |
|
12
|
|
|
* @return string[] |
|
13
|
|
|
*/ |
|
14
|
|
|
public static function getOnlineTime($user_id) { |
|
15
|
|
|
$user_record = static::getRecordById($user_id, array('username', 'onlinetime')); |
|
16
|
|
|
|
|
17
|
|
|
return !empty($user_record) ? $user_record : array(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
// TODO - это вообще-то надо хранить в конфигурации |
|
21
|
|
|
public static function getLastRegisteredUserName() { |
|
22
|
|
|
$user = doquery('SELECT `username` FROM {{users}} WHERE `user_as_ally` IS NULL ORDER BY `id` DESC LIMIT 1', true); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
return isset($user['username']) ? $user['username'] : ''; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public static function db_player_list_blitz_delete_players() { |
|
28
|
|
|
doquery("DELETE FROM `{{users}}` WHERE username LIKE 'Игрок%';"); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public static function db_player_list_blitz_set_50k_dm() { |
|
32
|
|
|
doquery('UPDATE `{{users}}` SET dark_matter = 50000, dark_matter_total = 50000;'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public static function db_player_list_export_blitz_info() { |
|
36
|
|
|
return doquery("SELECT id, username, total_rank, total_points, onlinetime FROM `{{users}}` ORDER BY `id`;"); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function db_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) { |
|
40
|
|
|
return classSupernova::db_get_user_by_username($username_unsafe, $for_update, $fields, $player, $like); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public static function db_user_list($user_filter = '', $for_update = false, $fields = '*') { |
|
|
|
|
|
|
44
|
|
|
return classSupernova::db_get_record_list(LOC_USER, $user_filter); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function db_user_set_by_id($user_id, $set) { |
|
48
|
|
|
return classSupernova::db_upd_record_by_id(LOC_USER, $user_id, $set); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function db_user_lock_all() { |
|
52
|
|
|
doquery("SELECT 1 FROM {{users}} FOR UPDATE;"); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return array|bool|mysqli_result|null |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function db_user_list_non_bots() { |
|
59
|
|
|
$query = doquery("SELECT `id` FROM {{users}} WHERE `user_as_ally` IS NULL AND `user_bot` = " . USER_BOT_PLAYER . " FOR UPDATE;"); |
|
60
|
|
|
|
|
61
|
|
|
return $query; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function db_user_lock_with_target_owner_and_acs($user, $planet = array()) { |
|
65
|
|
|
doquery("SELECT 1 FROM {{users}} WHERE `id` = " . idval($user['id']) . |
|
66
|
|
|
(isset($planet['id_owner']) ? ' OR `id` = ' . idval($planet['id_owner']) : '') . |
|
67
|
|
|
" FOR UPDATE;" |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Выбирает записи игроков по списку их ID |
|
73
|
|
|
* |
|
74
|
|
|
* @param $user_id_list |
|
75
|
|
|
* |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function db_user_list_by_id($user_id_list) { |
|
79
|
|
|
!is_array($user_id_list) ? $user_id_list = array($user_id_list) : false; |
|
80
|
|
|
|
|
81
|
|
|
$user_list = array(); |
|
82
|
|
|
foreach($user_id_list as $user_id_unsafe) { |
|
83
|
|
|
$user = DBStaticUser::db_user_by_id($user_id_unsafe); |
|
84
|
|
|
!empty($user) ? $user_list[$user_id_unsafe] = $user : false; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $user_list; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
public static function db_user_by_id($user_id_unsafe, $for_update = false, $fields = '*', $player = null) { |
|
94
|
|
|
return classSupernova::db_get_user_by_id($user_id_unsafe, $for_update, $fields, $player); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public static function db_user_list_set_mass_mail(&$owners_list, $set) { |
|
98
|
|
|
return classSupernova::db_upd_record_list(LOC_USER, !empty($owners_list) ? '`id` IN (' . implode(',', $owners_list) . ');' : '', $set); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public static function db_user_list_set_by_ally_and_rank($ally_id, $ally_rank_id, $set) { |
|
102
|
|
|
return classSupernova::db_upd_record_list(LOC_USER, "`ally_id`={$ally_id} AND `ally_rank_id` >= {$ally_rank_id}", $set); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public static function db_user_list_set_ally_deprecated_convert_ranks($ally_id, $i, $rank_id) { |
|
106
|
|
|
return classSupernova::db_upd_record_list(LOC_USER, "`ally_id` = {$ally_id} AND `ally_rank_id`={$rank_id}", "`ally_rank_id` = {$i}"); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
// public static function db_user_change_active_planet_to_capital($user_id, $captured_planet) { |
|
|
|
|
|
|
111
|
|
|
// return doquery("UPDATE {{users}} SET `current_planet` = `id_planet` WHERE `id` = {$user_id} AND `current_planet` = {$captured_planet};"); |
|
112
|
|
|
// } |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
public static function db_user_count($online = false) { |
|
116
|
|
|
$result = doquery('SELECT COUNT(id) AS user_count FROM `{{users}}` WHERE user_as_ally IS NULL' . ($online ? ' AND onlinetime > ' . (SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : ''), true); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
return isset($result['user_count']) ? $result['user_count'] : 0; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
public static function db_user_list_to_celebrate($config_user_birthday_range) { |
|
130
|
|
|
return doquery( |
|
131
|
|
|
"SELECT |
|
132
|
|
|
`id`, `username`, `user_birthday`, `user_birthday_celebrated` |
|
133
|
|
|
, CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d')) AS `current_birthday` |
|
134
|
|
|
, DATEDIFF(CURRENT_DATE, CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `days_after_birthday` |
|
135
|
|
|
FROM |
|
136
|
|
|
`{{users}}` |
|
137
|
|
|
WHERE |
|
138
|
|
|
`user_birthday` IS NOT NULL |
|
139
|
|
|
AND (`user_birthday_celebrated` IS NULL OR DATE_ADD(`user_birthday_celebrated`, INTERVAL 1 YEAR) < CURRENT_DATE) |
|
140
|
|
|
AND `user_as_ally` IS NULL |
|
141
|
|
|
HAVING |
|
142
|
|
|
`days_after_birthday` >= 0 AND `days_after_birthday` < {$config_user_birthday_range} FOR UPDATE;"); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
// public static function db_user_list_online_sorted($TypeSort) { |
|
|
|
|
|
|
146
|
|
|
// return doquery( |
|
147
|
|
|
// "SELECT `id` AS `ID`, `username` AS `NAME`, `ally_name` AS `ALLY`, `total_points` AS `STAT_POINTS`, |
|
148
|
|
|
// `onlinetime` AS `ACTIVITY` |
|
149
|
|
|
// FROM `{{users}}` |
|
150
|
|
|
// WHERE `onlinetime` >= " . (SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) . " ORDER BY user_as_ally, `" . $TypeSort . "` ASC;"); |
|
151
|
|
|
// } |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
public static function db_user_list_admin_multiaccounts() { |
|
155
|
|
|
return doquery("SELECT COUNT(*) AS ip_count, user_lastip FROM `{{users}}` WHERE user_as_ally IS NULL GROUP BY user_lastip HAVING COUNT(*) > 1;"); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
public static function db_user_list_admin_sorted($sort, $online = false) { |
|
160
|
|
|
return doquery("SELECT u.*, COUNT(r.id) AS referral_count, SUM(r.dark_matter) AS referral_dm FROM {{users}} as u |
|
161
|
|
|
LEFT JOIN {{referrals}} as r on r.id_partner = u.id |
|
162
|
|
|
WHERE" . |
|
163
|
|
|
($online ? " `onlinetime` >= " . (SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : ' user_as_ally IS NULL') . |
|
|
|
|
|
|
164
|
|
|
" GROUP BY u.id |
|
165
|
|
|
ORDER BY user_as_ally, {$sort} ASC"); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: