Article.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace internship\bo;
  3. use n2n\persistence\orm\annotation\AnnoManyToOne;
  4. use n2n\persistence\orm\annotation\AnnoOneToMany;
  5. use n2n\persistence\orm\attribute\ManyToOne;
  6. use n2n\reflection\annotation\AnnoInit;
  7. use n2n\reflection\ObjectAdapter;
  8. class Article extends ObjectAdapter implements \JsonSerializable {
  9. private static function _annos(AnnoInit $ai): void{
  10. $ai->p('category', new AnnoManyToOne(Category::getClass()));
  11. }
  12. private int $id;
  13. private Category $category;
  14. private string $text;
  15. private string $title;
  16. /**
  17. * @return int
  18. */
  19. public function getId(): int {
  20. return $this->id;
  21. }
  22. /**
  23. * @param int $id
  24. */
  25. public function setId(int $id): void {
  26. $this->id = $id;
  27. }
  28. /**
  29. * @return Category
  30. */
  31. public function getCategory(): Category
  32. {
  33. return $this->category;
  34. }
  35. /**
  36. * @param Category $category
  37. */
  38. public function setCategory(Category $category): void
  39. {
  40. $this->category = $category;
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function getText(): string {
  46. return $this->text;
  47. }
  48. /**
  49. * @param string $text
  50. */
  51. public function setText(string $text): void {
  52. $this->text = $text;
  53. }
  54. /**
  55. * @return string
  56. */
  57. public function getTitle(): string {
  58. return $this->title;
  59. }
  60. /**
  61. * @param string $title
  62. */
  63. public function setTitle(string $title): void {
  64. $this->title = $title;
  65. }
  66. function jsonSerialize(): mixed {
  67. return [
  68. 'id' => $this->id,
  69. 'title' => $this->title,
  70. 'categoryName' => $this->category->getName(),
  71. 'text' => $this->text
  72. ];
  73. }
  74. }