Article.php 830 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace internship\bo;
  3. use n2n\reflection\ObjectAdapter;
  4. use n2n\persistence\orm\attribute\ManyToMany;
  5. use n2n\persistence\orm\attribute\ManyToOne;
  6. class Article extends ObjectAdapter implements \JsonSerializable {
  7. public int $id;
  8. public string $categoryName;
  9. public string $text;
  10. public string $title;
  11. #[ManyToMany(Category::class, 'articles')]
  12. public \ArrayObject $categories;
  13. /* #[ManyToOne(Comment::class, 'articles')] */
  14. // public \ArrayObject $comments;
  15. function basicJsonSerialize() {
  16. return [
  17. 'id' => $this->id,
  18. 'title' => $this->title,
  19. 'text' => $this->text
  20. ];
  21. }
  22. function jsonSerialize(): mixed {
  23. $basicJson = $this->basicJsonSerialize();
  24. $basicJson['categoryName'] = $this->categoryName;
  25. $basicJson['categories'] = $this->categories;
  26. return $basicJson;
  27. }
  28. }