misuzu/src/Users/RoleInfo.php
flash 383e2ed0e0 Rewrote the user information class.
This one took multiple days and it pretty invasive into the core of Misuzu so issue might (will) arise, there's also some features that have gone temporarily missing in the mean time and some inefficiencies introduced that will be fixed again at a later time.
The old class isn't gone entirely because I still have to figure out what I'm gonna do about validation, but for the most part this knocks out one of the "layers of backwards compatibility", as I've been referring to it, and is moving us closer to a future where Flashii actually gets real updates.
If you run into anything that's broken and you're inhibited from reporting it through the forum, do it through chat or mail me at flashii-issues@flash.moe.
2023-08-02 22:12:47 +00:00

96 lines
2.4 KiB
PHP

<?php
namespace Misuzu\Users;
use Stringable;
use Index\DateTime;
use Index\Colour\Colour;
use Index\Data\IDbResult;
class RoleInfo implements Stringable {
private string $id;
private int $rank;
private string $name;
private ?string $title;
private ?string $description;
private bool $hidden;
private bool $leavable;
private ?int $colour;
private int $created;
public function __construct(IDbResult $result) {
$this->id = (string)$result->getInteger(0);
$this->rank = $result->getInteger(1);
$this->name = $result->getString(2);
$this->title = $result->isNull(3) ? null : $result->getString(3);
$this->description = $result->isNull(4) ? null : $result->getString(4);
$this->hidden = $result->getInteger(5) !== 0;
$this->leavable = $result->getInteger(6) !== 0;
$this->colour = $result->isNull(7) ? null : $result->getInteger(7);
$this->created = $result->getInteger(8);
}
public function getId(): string {
return $this->id;
}
public function isDefault(): bool {
return $this->id === Roles::DEFAULT_ROLE;
}
public function getRank(): int {
return $this->rank;
}
public function getName(): string {
return $this->name;
}
public function hasTitle(): bool {
return $this->title !== null && $this->title !== '';
}
public function getTitle(): ?string {
return $this->title;
}
public function hasDescription(): bool {
return $this->description !== null && $this->description !== '';
}
public function getDescription(): ?string {
return $this->description;
}
public function isHidden(): bool {
return $this->hidden;
}
public function isLeavable(): bool {
return $this->leavable;
}
public function hasColour(): bool {
return $this->colour !== null && ($this->colour & 0x40000000) === 0;
}
public function getColourRaw(): ?int {
return $this->colour;
}
public function getColour(): Colour {
return $this->colour === null ? Colour::none() : Colour::fromMisuzu($this->colour);
}
public function getCreatedTime(): int {
return $this->created;
}
public function getCreatedAt(): DateTime {
return DateTime::fromUnixTimeSeconds($this->created);
}
public function __toString(): string {
return 'r' . $this->id;
}
}