misuzu/src/Comments/CommentsCategoryInfo.php

77 lines
1.9 KiB
PHP

<?php
namespace Misuzu\Comments;
use Index\DateTime;
use Index\Data\IDbResult;
use Misuzu\Users\UserInfo;
class CommentsCategoryInfo {
public function __construct(
private string $id,
private string $name,
private ?string $ownerId,
private int $created,
private ?int $locked,
private int $comments,
) {}
public static function fromResult(IDbResult $result): CommentsCategoryInfo {
return new CommentsCategoryInfo(
id: $result->getString(0),
name: $result->getString(1),
ownerId: $result->getStringOrNull(2),
created: $result->getInteger(3),
locked: $result->getIntegerOrNull(4),
comments: $result->getInteger(5),
);
}
public function getId(): string {
return $this->id;
}
public function getName(): string {
return $this->name;
}
public function hasOwnerId(): bool {
return $this->ownerId !== null;
}
public function getOwnerId(): ?string {
return $this->ownerId;
}
public function isOwner(UserInfo|string $user): bool {
if($this->ownerId === null)
return false;
if($user instanceof UserInfo)
$user = $user->getId();
return $user === $this->ownerId;
}
public function getCreatedTime(): int {
return $this->created;
}
public function getCreatedAt(): DateTime {
return DateTime::fromUnixTimeSeconds($this->created);
}
public function getLockedTime(): ?int {
return $this->locked;
}
public function getLockedAt(): ?DateTime {
return $this->locked === null ? null : DateTime::fromUnixTimeSeconds($this->locked);
}
public function isLocked(): bool {
return $this->locked !== null;
}
public function getCommentsCount(): int {
return $this->comments;
}
}