src/Entity/NewsletterSubscriber.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\NewsletterSubscriberRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. #[UniqueEntity(['email'])]
  9. #[ORM\Entity(repositoryClassNewsletterSubscriberRepository::class)]
  10. class NewsletterSubscriber
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $email null;
  18.     #[ORM\Column]
  19.     private ?bool $active null;
  20.     #[ORM\ManyToMany(targetEntityNewsletter::class, mappedBy'newsletterSubscribers')]
  21.     private Collection $newsletters;
  22.     public function __construct()
  23.     {
  24.         $this->newsletters = new ArrayCollection();
  25.     }
  26.     public function getId(): ?int
  27.     {
  28.         return $this->id;
  29.     }
  30.     public function getEmail(): ?string
  31.     {
  32.         return $this->email;
  33.     }
  34.     public function setEmail(string $email): static
  35.     {
  36.         $this->email $email;
  37.         return $this;
  38.     }
  39.     public function isActive(): ?bool
  40.     {
  41.         return $this->active;
  42.     }
  43.     public function setActive(bool $active): static
  44.     {
  45.         $this->active $active;
  46.         return $this;
  47.     }
  48.     /**
  49.      * @return Collection<int, Newsletter>
  50.      */
  51.     public function getNewsletters(): Collection
  52.     {
  53.         return $this->newsletters;
  54.     }
  55.     public function addNewsletter(Newsletter $newsletter): static
  56.     {
  57.         if (!$this->newsletters->contains($newsletter)) {
  58.             $this->newsletters->add($newsletter);
  59.             $newsletter->addNewsletterSubscriber($this);
  60.         }
  61.         return $this;
  62.     }
  63.     public function removeNewsletter(Newsletter $newsletter): static
  64.     {
  65.         if ($this->newsletters->removeElement($newsletter)) {
  66.             $newsletter->removeNewsletterSubscriber($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function __toString(): string
  71.     {
  72.         return $this->email;
  73.     }
  74. }