69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
|
<?php
|
||
|
namespace Misuzu\Users;
|
||
|
|
||
|
use Index\DateTime;
|
||
|
use Index\Data\IDbResult;
|
||
|
|
||
|
class ModNoteInfo {
|
||
|
private string $noteId;
|
||
|
private string $userId;
|
||
|
private ?string $authorId;
|
||
|
private int $created;
|
||
|
private string $title;
|
||
|
private string $body;
|
||
|
|
||
|
public function __construct(IDbResult $result) {
|
||
|
$this->noteId = (string)$result->getInteger(0);
|
||
|
$this->userId = (string)$result->getInteger(1);
|
||
|
$this->authorId = $result->isNull(2) ? null : (string)$result->getInteger(2);
|
||
|
$this->created = $result->getInteger(3);
|
||
|
$this->title = $result->getString(4);
|
||
|
$this->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;
|
||
|
}
|
||
|
}
|