47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace User;
|
|
|
|
use Core\Db;
|
|
|
|
class Reputation
|
|
{
|
|
private array $r;
|
|
private int $uid;
|
|
|
|
public function __construct(int $userid)
|
|
{
|
|
$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
|
|
from rep where id = ?', [$this->uid]
|
|
);
|
|
|
|
if (empty($this->r)) {
|
|
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
|
|
from rep where id = ?', [$this->uid]
|
|
);
|
|
}
|
|
}
|
|
|
|
public function get(): array
|
|
{
|
|
return $this->r;
|
|
}
|
|
|
|
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];
|
|
}
|
|
} |