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-07-11 00:34:50 +00:00
|
|
|
$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]
|
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-07-11 00:34:50 +00:00
|
|
|
$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]
|
2023-07-11 00:34:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
2023-07-11 00:34:50 +00:00
|
|
|
}
|