Category.php 1.6 KB

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