100 lines
2.4 KiB
PHP
100 lines
2.4 KiB
PHP
<?php
|
|
namespace Seria\Users;
|
|
|
|
use RuntimeException;
|
|
use Index\Colour\Colour;
|
|
use Index\Data\IDbResult;
|
|
use Seria\Colours;
|
|
|
|
readonly class UserInfo {
|
|
private string $id;
|
|
private string $name;
|
|
private ?int $colour;
|
|
private int $rank;
|
|
private int $perms;
|
|
private ?string $passKey;
|
|
private int $bytesDownloaded;
|
|
private int $bytesUploaded;
|
|
|
|
public function __construct(IDbResult $result) {
|
|
$this->id = $result->getString(0);
|
|
$this->name = $result->getString(1);
|
|
|
|
$colour = $result->isNull(2) ? null : $result->getInteger(2);
|
|
$this->colour = $colour === null || ($colour & 0x40000000) ? null : $colour;
|
|
|
|
$this->rank = $result->getInteger(3);
|
|
$this->perms = $result->getInteger(4);
|
|
$this->passKey = $result->isNull(5) ? null : $result->getString(5);
|
|
$this->bytesDownloaded = $result->getInteger(6);
|
|
$this->bytesUploaded = $result->getInteger(7);
|
|
}
|
|
|
|
public function getId(): string {
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): string {
|
|
return $this->name;
|
|
}
|
|
|
|
public function hasColour(): bool {
|
|
return $this->colour !== null;
|
|
}
|
|
|
|
public function getColour(): Colour {
|
|
return $this->colour === null ? Colour::none() : Colours::cached($this->colour);
|
|
}
|
|
|
|
public function getColourRaw(): ?int {
|
|
return $this->colour;
|
|
}
|
|
|
|
public function getRank(): int {
|
|
return $this->rank;
|
|
}
|
|
|
|
public function getPermsRaw(): int {
|
|
return $this->perms;
|
|
}
|
|
|
|
public function hasPassKey(): bool {
|
|
return $this->passKey !== null;
|
|
}
|
|
|
|
public function getPassKey(): ?string {
|
|
return $this->passKey;
|
|
}
|
|
|
|
public function getBytesDownloaded(): int {
|
|
return $this->bytesDownloaded;
|
|
}
|
|
|
|
public function getBytesUploaded(): int {
|
|
return $this->bytesUploaded;
|
|
}
|
|
|
|
public function isFlash(): bool {
|
|
return $this->id === '1';
|
|
}
|
|
|
|
public function canCreateTorrents(): bool {
|
|
return true;
|
|
}
|
|
|
|
public function canApproveTorrents(): bool {
|
|
return $this->isFlash();
|
|
}
|
|
|
|
public function canRecalculateInfoHash(): bool {
|
|
return $this->isFlash();
|
|
}
|
|
|
|
public function calculateRatio(): float {
|
|
$bd = $this->getBytesDownloaded();
|
|
if($bd === 0)
|
|
return 0;
|
|
return $this->getBytesUploaded() / $bd;
|
|
}
|
|
}
|