32 lines
947 B
PHP
32 lines
947 B
PHP
<?php
|
|
|
|
namespace Core\Objects\DatabaseEntity;
|
|
|
|
use Core\API\Parameter\Parameter;
|
|
use Core\Driver\SQL\Expression\CurrentTimeStamp;
|
|
use Core\Objects\DatabaseEntity\Attribute\DefaultValue;
|
|
use Core\Objects\DatabaseEntity\Attribute\MaxLength;
|
|
use Core\Objects\DatabaseEntity\Controller\DatabaseEntity;
|
|
|
|
class News extends DatabaseEntity {
|
|
|
|
public User $publishedBy;
|
|
#[DefaultValue(CurrentTimeStamp::class)] private \DateTime $publishedAt;
|
|
#[MaxLength(128)] public string $title;
|
|
#[MaxLength(1024)] public string $text;
|
|
|
|
public function __construct(?int $id = null) {
|
|
parent::__construct($id);
|
|
$this->publishedAt = new \DateTime();
|
|
}
|
|
|
|
public function jsonSerialize(): array {
|
|
return [
|
|
"id" => $this->getId(),
|
|
"publishedBy" => $this->publishedBy->jsonSerialize(),
|
|
"publishedAt" => $this->publishedAt->format(Parameter::DATE_TIME_FORMAT),
|
|
"title" => $this->title,
|
|
"text" => $this->text
|
|
];
|
|
}
|
|
} |