refactor
This commit is contained in:
@@ -8,7 +8,7 @@ use User\ItemsModel;
|
||||
class Achievements
|
||||
{
|
||||
private User $user;
|
||||
private $info;
|
||||
private array $info;
|
||||
private array $data = [
|
||||
'zb' => [
|
||||
'questname' => 'Ежедн.Задания',
|
||||
@@ -99,7 +99,7 @@ class Achievements
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->info = Db::getRow('select * from users_achiv where id = ?', [$user->info['id']]);
|
||||
$this->info = Db::getRow('select * from users_achiv where id = ?', [$user->info['id']]) ?: [];
|
||||
}
|
||||
|
||||
//fixme: сюда иногда приходит (NULL, NULL).
|
||||
@@ -165,7 +165,7 @@ class Achievements
|
||||
return $string;
|
||||
}
|
||||
|
||||
private function calculateCurrent($check = null)
|
||||
private function calculateCurrent($check = null): void
|
||||
{
|
||||
$this->info['bs'] = $this->user->info['win_bs'];
|
||||
foreach ($this->info as $k => $v) {
|
||||
@@ -187,17 +187,18 @@ class Achievements
|
||||
$this->info["klasP$k"] = Math::get100Percentage($this->data[$k]['check'][1], $this->info[$k]);
|
||||
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
if ($this->info[$k] >= $this->data[$k]['check'][$i]) {
|
||||
$this->info["klas$k"] = $i;
|
||||
if ($i === 5) {
|
||||
# На 5 ранге должно отдавать максимум.
|
||||
$this->info["klasP$k"] = 100;
|
||||
} else {
|
||||
$this->info["klasP$k"] = Math::get100Percentage(
|
||||
$this->data[$k]['check'][$i + 1] - $this->data[$k]['check'][$i],
|
||||
$this->info[$k] - $this->data[$k]['check'][$i]
|
||||
);
|
||||
}
|
||||
if ($this->info[$k] < $this->data[$k]['check'][$i]) {
|
||||
continue;
|
||||
}
|
||||
$this->info["klas$k"] = $i;
|
||||
if ($i === 5) {
|
||||
# На 5 ранге должно отдавать максимум.
|
||||
$this->info["klasP$k"] = 100;
|
||||
} else {
|
||||
$this->info["klasP$k"] = Math::get100Percentage(
|
||||
$this->data[$k]['check'][$i + 1] - $this->data[$k]['check'][$i],
|
||||
$this->info[$k] - $this->data[$k]['check'][$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,7 +226,7 @@ class Achievements
|
||||
public function getInfo(?int $uid = null)
|
||||
{
|
||||
if (!is_null($uid)) {
|
||||
$this->info = Db::getRow('select * from users_achiv where id = ?', [$uid]);
|
||||
$this->info = Db::getRow('select * from users_achiv where id = ?', [$uid]) ?: [];
|
||||
}
|
||||
$this->calculateCurrent();
|
||||
return $this->info;
|
||||
|
||||
Reference in New Issue
Block a user