73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
namespace Misuzu\Users;
|
|
|
|
use Index\DateTime;
|
|
use Index\Data\IDbResult;
|
|
|
|
class ModNoteInfo {
|
|
public function __construct(
|
|
private string $noteId,
|
|
private string $userId,
|
|
private ?string $authorId,
|
|
private int $created,
|
|
private string $title,
|
|
private string $body,
|
|
) {}
|
|
|
|
public static function fromResult(IDbResult $result): ModNoteInfo {
|
|
return new ModNoteInfo(
|
|
noteId: $result->getString(0),
|
|
userId: $result->getString(1),
|
|
authorId: $result->getIntegerOrNull(2),
|
|
created: $result->getInteger(3),
|
|
title: $result->getString(4),
|
|
body: $result->getString(5)
|
|
);
|
|
}
|
|
|
|
public function getId(): string {
|
|
return $this->noteId;
|
|
}
|
|
|
|
public function getUserId(): string {
|
|
return $this->userId;
|
|
}
|
|
|
|
public function hasAuthorId(): bool {
|
|
return $this->authorId !== null;
|
|
}
|
|
|
|
public function getAuthorId(): ?string {
|
|
return $this->authorId;
|
|
}
|
|
|
|
public function getCreatedTime(): int {
|
|
return $this->created;
|
|
}
|
|
|
|
public function getCreatedAt(): DateTime {
|
|
return DateTime::fromUnixTimeSeconds($this->created);
|
|
}
|
|
|
|
public function getTitle(): string {
|
|
return $this->title;
|
|
}
|
|
|
|
public function hasBody(): bool {
|
|
return trim($this->body) !== '';
|
|
}
|
|
|
|
public function getBody(): string {
|
|
return $this->body;
|
|
}
|
|
|
|
public function getFirstParagraph(): string {
|
|
$index = mb_strpos($this->body, "\n");
|
|
return $index === false ? $this->body : mb_substr($this->body, 0, $index);
|
|
}
|
|
|
|
public function hasMoreParagraphs(): bool {
|
|
return mb_strpos($this->body, "\n") !== false;
|
|
}
|
|
}
|