| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace internship\bo;
- use n2n\reflection\ObjectAdapter;
- use n2n\persistence\orm\attribute\ManyToOne;
- use n2n\persistence\orm\CascadeType;
- use n2n\web\http\controller\impl\HttpData;
- use n2n\web\http\StatusException;
- class Article extends ObjectAdapter implements \JsonSerializable {
- private int $id;
- private string $categoryName;
- private string $text;
- private string $title;
- #[ManyToOne(cascade: CascadeType::PERSIST)]
- private ?ArticleGroup $articleGroup;
- function __construct(?string $categoryName = null, ?string $text = null, ?string $title = null) {
- if ($categoryName !== null) {
- $this->categoryName = $categoryName;
- }
- if ($text !== null) {
- $this->text = $text;
- }
- if ($title !== null) {
- $this->title = $title;
- }
- }
- /**
- * @throws StatusException
- */
- static function fromHttpData(HttpData $httpData): Article {
- return new Article($httpData->reqString('title'), $httpData->reqString('text'),
- $httpData->reqEnum('categoryName', ['sport']))
- }
- /**
- * @return int
- */
- public function getId(): int {
- return $this->id;
- }
- /**
- * @param int $id
- */
- public function setId(int $id): void {
- $this->id = $id;
- }
- /**
- * @return string
- */
- public function getCategoryName(): string {
- return $this->categoryName;
- }
- /**
- * @param string $categoryName
- */
- public function setCategoryName(string $categoryName): void {
- $this->categoryName = $categoryName;
- }
- /**
- * @return string
- */
- public function getText(): string {
- return $this->text;
- }
- /**
- * @param string $text
- */
- public function setText(string $text): void {
- $this->text = $text;
- }
- /**
- * @return string
- */
- public function getTitle(): string {
- return $this->title;
- }
- /**
- * @param string $title
- */
- public function setTitle(string $title): void {
- $this->title = $title;
- }
- /**
- * @return ArticleGroup
- */
- public function getArticleGroup(): ArticleGroup {
- return $this->articleGroup;
- }
- /**
- * @param ArticleGroup|null $articleGroup
- */
- public function setArticleGroup(ArticleGroup|null $articleGroup): void {
- $this->articleGroup = $articleGroup;
- }
- function jsonSerialize(): mixed {
- return [
- 'id' => $this->id,
- 'title' => $this->title,
- 'categoryName' => $this->categoryName,
- 'text' => $this->text,
- 'articleGroupId' => $this->articleGroup?->getId(),
- ];
- }
- }
|