2023-07-15 02:05:49 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu\Changelog;
|
|
|
|
|
|
|
|
use Index\DateTime;
|
|
|
|
use Index\Data\IDbResult;
|
|
|
|
|
|
|
|
class ChangeInfo {
|
2024-02-07 00:04:45 +00:00
|
|
|
public function __construct(
|
|
|
|
private string $id,
|
|
|
|
private ?string $userId,
|
|
|
|
private int $action,
|
|
|
|
private int $created,
|
|
|
|
private string $summary,
|
|
|
|
private string $body,
|
|
|
|
) {}
|
2023-07-15 02:05:49 +00:00
|
|
|
|
2024-02-07 00:04:45 +00:00
|
|
|
public static function fromResult(IDbResult $result): ChangeInfo {
|
|
|
|
return new ChangeInfo(
|
|
|
|
id: $result->getString(0),
|
|
|
|
userId: $result->getStringOrNull(1),
|
|
|
|
action: $result->getInteger(2),
|
|
|
|
created: $result->getInteger(3),
|
|
|
|
summary: $result->getString(4),
|
|
|
|
body: $result->getString(5),
|
|
|
|
);
|
2023-07-15 02:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getId(): string {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2023-09-06 13:50:19 +00:00
|
|
|
public function hasUserId(): bool {
|
|
|
|
return $this->userId !== null;
|
|
|
|
}
|
|
|
|
|
2023-07-15 02:05:49 +00:00
|
|
|
public function getUserId(): ?string {
|
|
|
|
return $this->userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getActionId(): int {
|
|
|
|
return $this->action;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAction(): string {
|
|
|
|
return Changelog::convertFromActionId($this->action);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getActionText(): string {
|
|
|
|
return Changelog::actionText($this->action);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCreatedTime(): int {
|
|
|
|
return $this->created;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCreatedAt(): DateTime {
|
|
|
|
return DateTime::fromUnixTimeSeconds($this->created);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDate(): string {
|
|
|
|
return gmdate('Y-m-d', $this->created);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummary(): string {
|
|
|
|
return $this->summary;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasBody(): bool {
|
|
|
|
return !empty($this->body);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBody(): string {
|
|
|
|
return $this->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommentsCategoryName(): string {
|
|
|
|
return sprintf('changelog-date-%s', $this->getDate());
|
|
|
|
}
|
|
|
|
}
|