game/_incl_data/class/Moderation/AdmFactory.php

99 lines
2.6 KiB
PHP

<?php
namespace Moderation;
use Core\Db;
use Delo;
use User;
class AdmFactory
{
public readonly string $status;
private array $targetUser;
public function __construct(
private readonly string $targetLogin,
)
{
$this->targetUser = User::getInfo($this->targetLogin);
}
public function addmoderator(): void
{
Moderator::add($this->targetUser['id']);
Delo::add(
10,
'moderation.addmoderator',
$this->targetUser['id'],
'Íàçíà÷åí íà ïîñò ìîäåðàòîðà.'
);
}
public function removemoderator(): void
{
Moderator::remove($this->targetUser['id']);
Delo::add(
10,
'moderation.removemoderator',
$this->targetUser['id'],
'Óâîëåí ñ ïîñòà ìîäåðàòîðà.'
);
}
public function changegender(): void
{
$changeto = $this->targetUser['sex'] == 0 ? 1 : 0;
Db::sql('update users set sex = ? where id = ?', [$changeto, $this->targetUser['id']]);
Delo::add(
10,
'moderation.changegender',
$this->targetUser['id'],
'Èçìåíåí ïîë ïåðñîíàæà.'
);
}
public function changelogin(string $login): void
{
$newlogin = strip_tags($login);
if (empty($newlogin)) {
return;
}
Db::sql('update users set login = ? where login = ?', [strip_tags($login), $this->targetLogin]);
Delo::add(
10,
'moderation.changelogin',
$this->targetUser['id'],
"Èçìåíåí ëîãèí ïåðñîíàæà. $this->targetLogin => " . strip_tags($login)
);
}
public function toggleinvisibility(): void
{
$changeto = $this->targetUser['invis'] == 0 ? 1 : 0;
Db::sql('update users set invis = ? where id = ?', [$changeto, $this->targetUser['id']]);
}
public function additem(int $itemId): void
{
if ($itemId < 1) {
return;
}
User\ItemsModel::addItem($itemId, $this->targetUser['id']);
}
public function kickfrombattle(): void
{
if (empty($this->targetUser['battle'])) {
$this->status = 'Ïåðñîíàæ íå â ïîåäèíêå.';
return;
}
Db::sql('update users left join stats on users.id = stats.id
set
battle = default,
team = default,
battle_yron = default,
battle_exp = default
where id = ?', [$this->targetUser['id']]);
// Â îðèãèíàëå òóò åù¸ ïèñàëàñü çàïèñü â ëîã áîÿ, íî íóæíà ëè îíà?
}
}