misuzu/src/Changelog/ChangeInfo.php

89 lines
2.1 KiB
PHP
Raw Normal View History

2023-07-15 02:05:49 +00:00
<?php
namespace Misuzu\Changelog;
use Index\DateTime;
use Index\Data\IDbResult;
class ChangeInfo {
private string $id;
private ?string $userId;
private int $action;
private int $created;
private string $summary;
private string $body;
private array $tags;
public function __construct(IDbResult $result, array $tags = []) {
$this->id = (string)$result->getInteger(0);
$this->userId = $result->isNull(1) ? null : (string)$result->getInteger(1);
$this->action = $result->getInteger(2);
$this->created = $result->getInteger(3);
$this->summary = $result->getString(4);
$this->body = $result->getString(5);
$this->tags = $tags;
}
public function getId(): string {
return $this->id;
}
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());
}
public function getTags(): array {
return $this->tags;
}
public function getTagIds(): array {
$ids = [];
foreach($this->tags as $tagInfo)
$ids[] = $tagInfo->getId();
return $ids;
}
public function hasTag(ChangeTagInfo|string $infoOrId): bool {
return in_array($infoOrId, $this->tags);
}
}