NewsItem.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace internship\bo;
  3. use n2n\reflection\ObjectAdapter;
  4. use internship\bo\NewsCategory;
  5. use n2n\reflection\annotation\AnnoInit;
  6. use n2n\persistence\orm\annotation\AnnoManyToOne;
  7. use n2n\persistence\orm\annotation\AnnoManyToMany;
  8. use n2n\persistence\orm\annotation\AnnoManagedFile;
  9. use n2n\persistence\orm\CascadeType;
  10. class NewsItem extends ObjectAdapter {
  11. private static function _annos(AnnoInit $ai) {
  12. $ai->p('category', new AnnoManyToOne(NewsCategory::getClass(), CascadeType::MERGE|CascadeType::PERSIST));
  13. $ai->p('tags', new AnnoManyToMany(NewsTag::getClass()));
  14. //$ai->p('imageFile', new AnnoManagedFile());
  15. }
  16. private int $id;
  17. private string $title;
  18. private string $lead;
  19. private string $content;
  20. private ?string $imageFile;
  21. private string $urlPart;
  22. private NewsCategory $category;
  23. private \ArrayObject $tags;
  24. function __construct() {
  25. $this->tags = new \ArrayObject();
  26. }
  27. /**
  28. * @return int
  29. */
  30. public function getId(): int {
  31. return $this->id;
  32. }
  33. /**
  34. * @return NewsCategory
  35. */
  36. public function getCategory(): NewsCategory {
  37. return $this->category;
  38. }
  39. /**
  40. * @param NewsCategory $category
  41. */
  42. public function setCategory($category): void {
  43. $this->category = $category;
  44. }
  45. /**
  46. * @return \ArrayObject
  47. */
  48. public function getTags(): \ArrayObject {
  49. return $this->tags;
  50. }
  51. /**
  52. * @param \ArrayObject $tags
  53. */
  54. public function setTags(\ArrayObject $tags): void {
  55. $this->tags = $tags;
  56. }
  57. /**
  58. * @return string
  59. */
  60. public function getTitle(): string {
  61. return $this->title;
  62. }
  63. /**
  64. * @param string $title
  65. */
  66. public function setTitle(string $title): void {
  67. $this->title = $title;
  68. }
  69. /**
  70. * @return string
  71. */
  72. public function getLead(): string {
  73. return $this->lead;
  74. }
  75. /**
  76. * @param string $lead
  77. */
  78. public function setLead(string $lead): void {
  79. $this->lead = $lead;
  80. }
  81. /**
  82. * @return string
  83. */
  84. public function getContent(): string {
  85. return $this->content;
  86. }
  87. /**
  88. * @param string $content
  89. */
  90. public function setContent(string $content): void {
  91. $this->content = $content;
  92. }
  93. /**
  94. * @return string
  95. */
  96. public function getImageFile(): string {
  97. return $this->imageFile;
  98. }
  99. /**
  100. * @param string $imageFile
  101. */
  102. public function setImageFile(?string $imageFile): void {
  103. $this->imageFile = $imageFile;
  104. }
  105. /**
  106. * @return string
  107. */
  108. public function getUrlPart() {
  109. return $this->urlPart;
  110. }
  111. /**
  112. * @param string $urlPart
  113. */
  114. public function setUrlPart($urlPart) {
  115. $this->urlPart = $urlPart;
  116. }
  117. public function equals(NewsItem $newsItem) {
  118. return $this->id == $newsItem->getId();
  119. }
  120. }