2023-07-15 23:58:17 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu\Comments;
|
|
|
|
|
2024-08-04 21:37:12 +00:00
|
|
|
use Carbon\CarbonImmutable;
|
2024-10-05 02:40:29 +00:00
|
|
|
use Index\Db\DbResult;
|
2023-07-15 23:58:17 +00:00
|
|
|
|
|
|
|
class CommentsPostInfo {
|
|
|
|
public function __construct(
|
2024-11-30 04:09:29 +00:00
|
|
|
public private(set) string $id,
|
|
|
|
public private(set) string $categoryId,
|
|
|
|
public private(set) ?string $userId,
|
|
|
|
public private(set) ?string $replyingTo,
|
|
|
|
public private(set) string $body,
|
|
|
|
public private(set) int $createdTime,
|
|
|
|
public private(set) ?int $pinnedTime,
|
|
|
|
public private(set) ?int $updatedTime,
|
|
|
|
public private(set) ?int $deletedTime,
|
|
|
|
public private(set) int $repliesCount,
|
|
|
|
public private(set) int $votesCount,
|
|
|
|
public private(set) int $votesPositive,
|
|
|
|
public private(set) int $votesNegative,
|
2024-02-07 00:04:45 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
public static function fromResult(
|
2024-10-05 03:36:53 +00:00
|
|
|
DbResult $result,
|
2023-07-15 23:58:17 +00:00
|
|
|
bool $includeRepliesCount = false,
|
|
|
|
bool $includeVotesCount = false
|
2024-02-07 00:04:45 +00:00
|
|
|
): CommentsPostInfo {
|
|
|
|
$args = [];
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
$args[] = $result->getString($count); // id
|
|
|
|
$args[] = $result->getString(++$count); // categoryId
|
|
|
|
$args[] = $result->getStringOrNull(++$count); // userId
|
|
|
|
$args[] = $result->getStringOrNull(++$count); // replyingTo
|
|
|
|
$args[] = $result->getString(++$count); // body
|
2024-11-30 04:09:29 +00:00
|
|
|
$args[] = $result->getInteger(++$count); // createdTime
|
|
|
|
$args[] = $result->getIntegerOrNull(++$count); // pinnedTime
|
|
|
|
$args[] = $result->getIntegerOrNull(++$count); // updatedTime
|
|
|
|
$args[] = $result->getIntegerOrNull(++$count); // deletedTime
|
2024-02-07 00:04:45 +00:00
|
|
|
|
|
|
|
$args[] = $includeRepliesCount ? $result->getInteger(++$count) : 0;
|
2023-07-15 23:58:17 +00:00
|
|
|
|
|
|
|
if($includeVotesCount) {
|
2024-11-30 04:09:29 +00:00
|
|
|
$args[] = $result->getInteger(++$count); // votesCount
|
2024-02-07 00:04:45 +00:00
|
|
|
$args[] = $result->getInteger(++$count); // votesPositive
|
|
|
|
$args[] = $result->getInteger(++$count); // votesNegative
|
2023-07-15 23:58:17 +00:00
|
|
|
} else {
|
2024-02-07 00:04:45 +00:00
|
|
|
$args[] = 0;
|
|
|
|
$args[] = 0;
|
|
|
|
$args[] = 0;
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
2024-02-07 00:04:45 +00:00
|
|
|
|
|
|
|
return new CommentsPostInfo(...$args);
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public bool $isReply {
|
|
|
|
get => $this->replyingTo !== null;
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public CarbonImmutable $createdAt {
|
|
|
|
get => CarbonImmutable::createFromTimestampUTC($this->createdTime);
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public ?CarbonImmutable $pinnedAt {
|
|
|
|
get => $this->pinnedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->pinnedTime);
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public bool $pinned {
|
|
|
|
get => $this->pinnedTime !== null;
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public ?CarbonImmutable $updatedAt {
|
|
|
|
get => $this->updatedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->updatedTime);
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public bool $edited {
|
|
|
|
get => $this->updatedTime !== null;
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public ?CarbonImmutable $deletedAt {
|
|
|
|
get => $this->deletedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->deletedTime);
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
public bool $deleted {
|
|
|
|
get => $this->deletedTime !== null;
|
2023-07-15 23:58:17 +00:00
|
|
|
}
|
|
|
|
}
|