You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.5KB

  1. <?php
  2. namespace Lc\SovBundle\Model\Newsletter;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. #[ORM\MappedSuperclass]
  9. abstract class NewsletterModel extends AbstractFullEntity implements NewsletterInterface
  10. {
  11. #[ORM\ManyToMany(targetEntity:"Lc\SovBundle\Model\User\UserInterface", mappedBy:"newsletters")]
  12. protected $users;
  13. #[ORM\Column(type:"boolean", nullable:true)]
  14. protected $isMain;
  15. public function __toString()
  16. {
  17. return $this->getTitle();
  18. }
  19. public function __construct()
  20. {
  21. $this->users = new ArrayCollection();
  22. }
  23. /**
  24. * @return Collection|UserInterface[]
  25. */
  26. public function getUsers(): Collection
  27. {
  28. return $this->users;
  29. }
  30. public function addUser(UserInterface $user): self
  31. {
  32. if (!$this->users->contains($user)) {
  33. $this->users[] = $user;
  34. $user->addNewsletter($this);
  35. }
  36. return $this;
  37. }
  38. public function removeUser(UserInterface $user): self
  39. {
  40. if ($this->users->contains($user)) {
  41. $this->users->removeElement($user);
  42. $user->removeNewsletter($this);
  43. }
  44. return $this;
  45. }
  46. public function getIsMain(): ?bool
  47. {
  48. return $this->isMain;
  49. }
  50. public function setIsMain(?bool $isMain): self
  51. {
  52. $this->isMain = $isMain;
  53. return $this;
  54. }
  55. }