game/_incl_data/class/User/Clan.php

92 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace User;
use Clan\ClanInfo;
use Core\Config;
use Core\Db;
use Images;
class Clan
{
private $userid;
private int $id = 0;
private ?string $name;
private ?int $align;
private ?int $logo;
private ?int $status;
2023-07-31 17:06:51 +00:00
public function __construct(array $userinfo)
{
$this->userid = $userinfo['id'];
if (isset($_POST['joinclan']) && ClanInfo::isJoinable($_POST['joinclan'])) {
$this->join($_POST['joinclan']);
exit('<script>window.location.replace("/main.php?clan=1");</script>');
}
$c = Db::getRow('select * from clan where id = ?', [$userinfo['clan']]);
if (!empty($c)) {
foreach ($c as $k => $v) {
$this->$k = $v;
}
}
}
private function join(string $clanname)
{
Db::sql('update users set clan = (select id from clan where clan.name = ?) where id = ?', [$clanname, $this->userid]);
}
public function getId(): int
{
return $this->id;
}
2023-07-31 17:06:51 +00:00
public function getStatus(): ?int
{
2023-07-31 17:06:51 +00:00
return $this->status;
}
2023-07-31 17:06:51 +00:00
public function printClan()
{
2023-07-31 17:06:51 +00:00
echo '<img style="vertical-align:text-bottom;" src="' . Config::img() . '/i/align/align' . $this->getAlign() . '.gif" alt="Склонность">' . $this->printLogoImage() . $this->getName();
}
2023-07-31 17:06:51 +00:00
public function getAlign(): ?int
{
2023-07-31 17:06:51 +00:00
return $this->align;
}
2023-07-31 17:06:51 +00:00
public function printLogoImage(): string
{
2023-07-31 17:06:51 +00:00
return '<img style="vertical-align:text-bottom;" src = "' . Images::getSrc($this->logo) . '" width = "24px" height = "15px">';
}
2023-07-31 17:06:51 +00:00
public function getName(): ?string
{
2023-07-31 17:06:51 +00:00
return $this->name;
}
public function getLogo(): ?int
{
return $this->logo;
}
/**
* Клан зарегистрирован и подверждён.
* @return bool
*/
public function isRegistered(): bool
{
return !empty($this->id) && $this->status !== 0;
}
/**
* Клан зарегистрирован и ожидает подтверждения.
* @return bool
*/
public function isAwaitingConfirmation(): bool
{
return !empty($this->id) && $this->status === 0;
}
}