Переделал вызов User()->info[] на статический, чтобы можно было вызывать в том числе и извне для частных случаев, когда нужна инфомация не только по активному игроку.

This commit is contained in:
Ivor Barhansky 2023-07-24 13:02:30 +03:00
parent 83ec9d12f9
commit 2d3f23f81b

View File

@ -588,47 +588,8 @@ class User
private function __construct()
{
if (!empty($_SESSION['uid'])) {
$user = Db::getRow(
'select
*,
users.id as id,
users.level as level,
users.align as align,
users.sex as sex,
users.clan as clan,
stats.timeGo as timeGo,
users.name as name,
stats.lider as lider
from users
left join stats on users.id = stats.id
left join room on users.room = room.id
where users.id = ?',
[$_SESSION['uid']]
);
} else {
$user = Db::getRow(
'select
*,
users.id as id,
users.level as level,
users.align as align,
users.sex as sex,
users.clan as clan,
stats.timeGo as timeGo,
users.name as name,
stats.lider as lider
from users
left join stats on users.id = stats.id
left join room on users.room = room.id
where login = ?',
[$_COOKIE['login']]
);
}
if (!empty($user) && is_array($user)) {
$this->info = $user;
}
$user = !empty($_SESSION['uid']) ? $_SESSION['uid'] : $_COOKIE['login'];
$this->info = self::getInfo($user);
unset($user);
Database::init(); // для всяких mysql_*
@ -1144,6 +1105,31 @@ class User
}
}
/**
* @param int|string $user
* @return array
*/
public static function getInfo($user): array
{
$cell = is_numeric($user) ? 'id' : 'login';
$query = 'select
*,
users.id as id,
users.level as level,
users.align as align,
users.sex as sex,
users.clan as clan,
stats.timeGo as timeGo,
users.name as name,
stats.lider as lider
from users
left join stats on users.id = stats.id
left join room on users.room = room.id
where users.' . $cell . ' = ?';
$result = Db::getRow($query, [$user]);
return $result ?: [];
}
private function infoTasks()
{
if (empty($this->info)) {