src/Entity/Advertisement.php line 24

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use App\Repository\AdvertisementRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ApiResource(
  12.     operations: [
  13.         new GetCollection(
  14.             normalizationContext: ['groups' => ['advertisement:list']]
  15.         ),
  16.         new Get()
  17.     ],
  18.     normalizationContext: ['groups' => ['advertisement:list''advertisement:view']]
  19. )]
  20. #[ORM\Entity(repositoryClassAdvertisementRepository::class)]
  21. class Advertisement
  22. {
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column]
  26.     #[Groups(['advertisement:list'])]
  27.     private ?int $id null;
  28.     #[ORM\Column(length255)]
  29.     #[Groups(['advertisement:list'])]
  30.     private ?string $title null;
  31.     #[ORM\OneToMany(mappedBy'advertisement'targetEntityAdvertisementAttachment::class, orphanRemovaltrue)]
  32.     private Collection $attachments;
  33.     #[ORM\ManyToOne(inversedBy'advertisements')]
  34.     #[ORM\JoinColumn(nullablefalse)]
  35.     private ?Establishment $establishment null;
  36.     public function __construct()
  37.     {
  38.         $this->attachments = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getTitle(): ?string
  45.     {
  46.         return $this->title;
  47.     }
  48.     public function setTitle(string $title): static
  49.     {
  50.         $this->title $title;
  51.         return $this;
  52.     }
  53.     /**
  54.      * @return Collection<int, AdvertisementAttachment>
  55.      */
  56.     public function getAttachments(): Collection
  57.     {
  58.         return $this->attachments;
  59.     }
  60.     public function addAttachment(AdvertisementAttachment $attachment): static
  61.     {
  62.         if (!$this->attachments->contains($attachment)) {
  63.             $this->attachments->add($attachment);
  64.             $attachment->setAdvertisement($this);
  65.         }
  66.         return $this;
  67.     }
  68.     public function removeAttachment(AdvertisementAttachment $attachment): static
  69.     {
  70.         if ($this->attachments->removeElement($attachment)) {
  71.             // set the owning side to null (unless already changed)
  72.             if ($attachment->getAdvertisement() === $this) {
  73.                 $attachment->setAdvertisement(null);
  74.             }
  75.         }
  76.         return $this;
  77.     }
  78.     public function getEstablishment(): ?Establishment
  79.     {
  80.         return $this->establishment;
  81.     }
  82.     public function setEstablishment(?Establishment $establishment): static
  83.     {
  84.         $this->establishment $establishment;
  85.         return $this;
  86.     }
  87. }