2023-07-11 00:34:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace User;
|
|
|
|
|
|
|
|
use Core\Db;
|
|
|
|
|
|
|
|
class Reputation
|
|
|
|
{
|
|
|
|
private array $r;
|
2023-11-02 13:57:39 +00:00
|
|
|
private int $uid;
|
2023-07-11 00:34:50 +00:00
|
|
|
|
|
|
|
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();
|
2023-07-11 00:34:50 +00:00
|
|
|
|
|
|
|
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();
|
2023-07-11 00:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-26 13:08:30 +00:00
|
|
|
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]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-11 00:34:50 +00:00
|
|
|
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];
|
|
|
|
}
|
2023-07-11 00:34:50 +00:00
|
|
|
}
|