misuzu/src/Comments/CommentsCategoryInfo.php

73 lines
1.8 KiB
PHP

<?php
namespace Misuzu\Comments;
use Index\DateTime;
use Index\Data\IDbResult;
use Misuzu\Users\User;
class CommentsCategoryInfo {
private string $id;
private string $name;
private ?string $ownerId;
private int $created;
private ?int $locked;
private int $comments;
public function __construct(IDbResult $result) {
$this->id = (string)$result->getInteger(0);
$this->name = $result->getString(1);
$this->ownerId = $result->isNull(2) ? null : (string)$result->getInteger(2);
$this->created = $result->getInteger(3);
$this->locked = $result->isNull(4) ? null : $result->getInteger(4);
$this->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(User|string $user): bool {
if($this->ownerId === null)
return false;
if($user instanceof User)
$user = (string)$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;
}
}