game/_incl_data/class/User/Reputation.php

47 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace User;
use Core\Db;
class Reputation
{
private array $r;
2023-11-02 13:57:39 +00:00
private int $uid;
public function __construct(int $userid)
{
2023-11-02 13:57:39 +00:00
$this->uid = $userid;
$this->r = Db::getRow(
'select *,
(repcapitalcity+repdemonscity+repangelscity+repsuncity+repdreamscity+repabandonedplain+repsandcity+repemeraldscity+repdevilscity) as allrep,
(nu_capitalcity+nu_demonscity+nu_angelscity+nu_suncity+nu_dreamscity+nu_abandonedplain+nu_sandcity+nu_emeraldscity+nu_devilscity) as allnurep
2023-11-02 13:57:39 +00:00
from rep where id = ?', [$this->uid]
);
if (empty($this->r)) {
2023-11-02 13:57:39 +00:00
Db::sql('insert into rep (id) value (?)', [$this->uid]);
$this->r = Db::getRow(
'select *,
(repcapitalcity+repdemonscity+repangelscity+repsuncity+repdreamscity+repabandonedplain+repsandcity+repemeraldscity+repdevilscity) as allrep,
(nu_capitalcity+nu_demonscity+nu_angelscity+nu_suncity+nu_dreamscity+nu_abandonedplain+nu_sandcity+nu_emeraldscity+nu_devilscity) as allnurep
2023-11-02 13:57:39 +00:00
from rep where id = ?', [$this->uid]
);
}
}
public function get(): array
{
return $this->r;
}
2023-11-02 13:57:39 +00:00
public function addRep(string $dungeonName, int $value): int
{
if (!isset($this->r[$dungeonName]) || $value <= 0) {
return 0;
}
$this->r[$dungeonName] += $value;
Db::sql("update rep set $dungeonName = ? where id = ?", [$value, $this->uid]);
return $this->r[$dungeonName];
}
}