91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
namespace Misuzu\Forum;
|
|
|
|
use Misuzu\Parsers\Parser;
|
|
use Carbon\CarbonImmutable;
|
|
use Index\XDateTime;
|
|
use Index\Db\DbResult;
|
|
|
|
class ForumPostInfo {
|
|
public function __construct(
|
|
public private(set) string $id,
|
|
public private(set) string $topicId,
|
|
public private(set) string $categoryId,
|
|
public private(set) ?string $userId,
|
|
public private(set) string $remoteAddress,
|
|
public private(set) string $body,
|
|
public private(set) int $parser,
|
|
public private(set) bool $shouldDisplaySignature,
|
|
public private(set) int $createdTime,
|
|
public private(set) ?int $editedTime,
|
|
public private(set) ?int $deletedTime,
|
|
) {}
|
|
|
|
public static function fromResult(DbResult $result): ForumPostInfo {
|
|
return new ForumPostInfo(
|
|
id: $result->getString(0),
|
|
topicId: $result->getString(1),
|
|
categoryId: $result->getString(2),
|
|
userId: $result->getStringOrNull(3),
|
|
remoteAddress: $result->getString(4),
|
|
body: $result->getString(5),
|
|
parser: $result->getInteger(6),
|
|
shouldDisplaySignature: $result->getBoolean(7),
|
|
createdTime: $result->getInteger(8),
|
|
editedTime: $result->getIntegerOrNull(9),
|
|
deletedTime: $result->getIntegerOrNull(10),
|
|
);
|
|
}
|
|
|
|
public bool $isBodyPlain {
|
|
get => $this->parser === Parser::PLAIN;
|
|
}
|
|
|
|
public bool $isBodyBBCode {
|
|
get => $this->parser === Parser::BBCODE;
|
|
}
|
|
|
|
public bool $isBodyMarkdown {
|
|
get => $this->parser === Parser::MARKDOWN;
|
|
}
|
|
|
|
public CarbonImmutable $createdAt {
|
|
get => CarbonImmutable::createFromTimestampUTC($this->createdTime);
|
|
}
|
|
|
|
private static ?CarbonImmutable $markAsEditedThreshold = null;
|
|
|
|
public bool $shouldMarkAsEdited {
|
|
get {
|
|
self::$markAsEditedThreshold ??= new CarbonImmutable('-5 minutes');
|
|
|
|
return XDateTime::compare($this->createdAt, self::$markAsEditedThreshold) < 0;
|
|
}
|
|
}
|
|
|
|
public bool $edited {
|
|
get => $this->editedTime !== null;
|
|
}
|
|
|
|
public ?CarbonImmutable $editedAt {
|
|
get => $this->editedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->editedTime);
|
|
}
|
|
|
|
private static ?CarbonImmutable $canBeDeletedThreshold = null;
|
|
|
|
public bool $canBeDeleted {
|
|
get {
|
|
self::$canBeDeletedThreshold ??= new CarbonImmutable('-1 week');
|
|
|
|
return XDateTime::compare($this->createdAt, self::$canBeDeletedThreshold) >= 0;
|
|
}
|
|
}
|
|
|
|
public bool $deleted {
|
|
get => $this->deletedTime !== null;
|
|
}
|
|
|
|
public ?CarbonImmutable $deletedAt {
|
|
get => $this->deletedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->deletedTime);
|
|
}
|
|
}
|