game/_incl_data/class/Moderation/AdmFactory.php

99 lines
2.7 KiB
PHP
Raw Normal View History

<?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'],
2023-12-19 01:58:37 +00:00
'Назначен на пост модератора.'
);
}
public function removemoderator(): void
{
Moderator::remove($this->targetUser['id']);
Delo::add(
10,
'moderation.removemoderator',
$this->targetUser['id'],
2023-12-19 01:58:37 +00:00
'Уволен с поста модератора.'
);
}
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'],
2023-12-19 01:58:37 +00:00
'Изменен пол персонажа.'
);
}
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'],
2023-12-19 01:58:37 +00:00
"Изменен логин персонажа. $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'])) {
2023-12-19 01:58:37 +00:00
$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']]);
2023-12-19 01:58:37 +00:00
// В оригинале тут ещё писалась запись в лог боя, но нужна ли она?
}
}