game/_incl_data/class/Moderation/Moderator.php

48 lines
1.3 KiB
PHP

<?php
namespace Moderation;
use Core\Db;
readonly class Moderator
{
public bool $isModerator;
public bool $canBlockUsers;
public bool $isAdmin;
public function __construct(int $uid)
{
[
'uid' => $isModerator,
'can_block_users' => $canBlockUsers,
'is_admin' => $isAdmin,
] = Db::getRow('select uid, can_block_users, is_admin from moderators where uid = ?', [$uid]);
$this->isModerator = !empty($isModerator);
$this->canBlockUsers = !empty($isModerator) && !empty($canBlockUsers);
$this->isAdmin = !empty($isModerator) && !empty($isAdmin);
}
public static function add(int $uid): void
{
$user = new Moderator($uid);
if ($user->isModerator) {
return;
}
Db::sql('insert into moderators (uid) value (?)', [$uid]);
}
public static function modify(int $uid, bool $allowBlock, bool $adminRights): void
{
$user = new Moderator($uid);
if (!$user->isModerator) {
return;
}
Db::sql('update moderators set can_block_users = ?, is_admin = ? where uid = ?', [(int)$allowBlock, (int)$adminRights, $uid]);
}
public static function remove(int $uid): void
{
Db::sql('delete from moderators where uid = ?', [$uid]);
}
}