<?phpnamespace App\Entity;use App\Repository\AnnouncementRepository;use Doctrine\ORM\Mapping as ORM;use App\Entity\Traits\TimeStampable;use App\Entity\Image;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;/** * @ORM\Entity(repositoryClass=AnnouncementRepository::class) */class Announcement{ use TimeStampable; public const NUM_ITEMS_PER_PAGE = 20; /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $title; /** * @var string * * @ORM\Column(name="content", type="text", nullable=true) */ private $content; /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $image; /** * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=true) */ private $author; /** * @ORM\OneToMany(targetEntity=Image::class, mappedBy="announcement", cascade={"persist", "remove"}) */ private $images; public function __construct() { $this->createdAt = new \DateTime(); $this->updatedAt = new \DateTime(); $this->images = new ArrayCollection(); } /** * @return Collection|Image[] */ public function getImages(): Collection { return $this->images; } public function getId(): ?int { return $this->id; } public function getTitle(): ?string { return $this->title; } public function setTitle(string $title): self { $this->title = $title; return $this; } public function getContent(): ?string { return $this->content; } public function setContent(string $content): self { $this->content = $content; return $this; } public function getAuthor(): ?User { return $this->author; } public function setAuthor(?User $author): static { $this->author = $author; return $this; } public function addImage(Image $image): self { if (!$this->images->contains($image)) { $this->images[] = $image; $image->setAnnouncement($this); } return $this; } public function removeImage(Image $image): self { if ($this->images->removeElement($image)) { // set the owning side to null if ($image->getAnnouncement() === $this) { $image->setAnnouncement(null); } } return $this; }}