misuzu/src/Comments/CommentsCategoryInfo.php

73 lines
1.8 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 {
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(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;
}
}