src/Entity/Announcement.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AnnouncementRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Entity\Traits\TimeStampable;
  6. use App\Entity\Image;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. /**
  10. * @ORM\Entity(repositoryClass=AnnouncementRepository::class)
  11. */
  12. class Announcement
  13. {
  14. use TimeStampable;
  15. public const NUM_ITEMS_PER_PAGE = 20;
  16. /**
  17. * @ORM\Id
  18. * @ORM\GeneratedValue
  19. * @ORM\Column(type="integer")
  20. */
  21. private $id;
  22. /**
  23. * @ORM\Column(type="string", length=255)
  24. */
  25. private $title;
  26. /**
  27. * @var string
  28. *
  29. * @ORM\Column(name="content", type="text", nullable=true)
  30. */
  31. private $content;
  32. /**
  33. * @ORM\Column(type="string", length=255, nullable=true)
  34. */
  35. private ?string $image;
  36. /**
  37. * @ORM\ManyToOne(targetEntity=User::class)
  38. * @ORM\JoinColumn(nullable=true)
  39. */
  40. private $author;
  41. /**
  42. * @ORM\OneToMany(targetEntity=Image::class, mappedBy="announcement", cascade={"persist", "remove"})
  43. */
  44. private $images;
  45. public function __construct()
  46. {
  47. $this->createdAt = new \DateTime();
  48. $this->updatedAt = new \DateTime();
  49. $this->images = new ArrayCollection();
  50. }
  51. /**
  52. * @return Collection|Image[]
  53. */
  54. public function getImages(): Collection
  55. {
  56. return $this->images;
  57. }
  58. public function getId(): ?int
  59. {
  60. return $this->id;
  61. }
  62. public function getTitle(): ?string
  63. {
  64. return $this->title;
  65. }
  66. public function setTitle(string $title): self
  67. {
  68. $this->title = $title;
  69. return $this;
  70. }
  71. public function getContent(): ?string
  72. {
  73. return $this->content;
  74. }
  75. public function setContent(string $content): self
  76. {
  77. $this->content = $content;
  78. return $this;
  79. }
  80. public function getAuthor(): ?User
  81. {
  82. return $this->author;
  83. }
  84. public function setAuthor(?User $author): static
  85. {
  86. $this->author = $author;
  87. return $this;
  88. }
  89. public function addImage(Image $image): self
  90. {
  91. if (!$this->images->contains($image)) {
  92. $this->images[] = $image;
  93. $image->setAnnouncement($this);
  94. }
  95. return $this;
  96. }
  97. public function removeImage(Image $image): self
  98. {
  99. if ($this->images->removeElement($image)) {
  100. // set the owning side to null
  101. if ($image->getAnnouncement() === $this) {
  102. $image->setAnnouncement(null);
  103. }
  104. }
  105. return $this;
  106. }
  107. }