misuzu/src/Comments/CommentsCategoryInfo.php

77 lines
1.9 KiB
PHP
Raw Normal View History

2023-07-15 23:58:17 +00:00
<?php
namespace Misuzu\Comments;
use Index\DateTime;
use Index\Data\IDbResult;
use Misuzu\Users\UserInfo;
2023-07-15 23:58:17 +00:00
class CommentsCategoryInfo {
2024-02-07 00:04:45 +00:00
public function __construct(
private string $id,
private string $name,
private ?string $ownerId,
private int $created,
private ?int $locked,
private int $comments,
) {}
2023-07-15 23:58:17 +00:00
2024-02-07 00:04:45 +00:00
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),
);
2023-07-15 23:58:17 +00:00
}
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 {
2023-07-15 23:58:17 +00:00
if($this->ownerId === null)
return false;
if($user instanceof UserInfo)
$user = $user->getId();
2023-07-15 23:58:17 +00:00
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;
}
}