game/_incl_data/class/User/Reputation.php

47 lines
1.2 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;
2023-12-19 01:58:37 +00:00
$this->r = $this->getr();
if (empty($this->r)) {
2023-11-02 13:57:39 +00:00
Db::sql('insert into rep (id) value (?)', [$this->uid]);
2023-12-19 01:58:37 +00:00
$this->r = $this->getr();
}
}
private function getr(): array
{
return 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;
}
2023-11-02 13:57:39 +00:00
2023-12-19 01:58:37 +00:00
public function addRep(string $dungeonName, int $value): mixed
2023-11-02 13:57:39 +00:00
{
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];
}
}