Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

94 lines
2.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Newsletter;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  6. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  7. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  8. use Lc\SovBundle\Model\User\UserInterface;
  9. /**
  10. * @ORM\MappedSuperclass()
  11. */
  12. abstract class NewsletterModel extends AbstractFullEntity implements FilterMerchantInterface
  13. {
  14. /**
  15. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="newsletters")
  16. */
  17. protected $merchant;
  18. /**
  19. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\User\UserInterface", mappedBy="newsletters")
  20. */
  21. protected $users;
  22. /**
  23. * @ORM\Column(type="boolean", nullable=true)
  24. */
  25. protected $isMain;
  26. public function __toString()
  27. {
  28. return $this->getTitle();
  29. }
  30. public function __construct()
  31. {
  32. $this->users = new ArrayCollection();
  33. }
  34. public function getMerchant(): ?MerchantInterface
  35. {
  36. return $this->merchant;
  37. }
  38. public function setMerchant(?MerchantInterface $merchant): self
  39. {
  40. $this->merchant = $merchant;
  41. return $this;
  42. }
  43. /**
  44. * @return Collection|UserInterface[]
  45. */
  46. public function getUsers(): Collection
  47. {
  48. return $this->users;
  49. }
  50. public function addUser(UserInterface $user): self
  51. {
  52. if (!$this->users->contains($user)) {
  53. $this->users[] = $user;
  54. $user->addNewsletter($this);
  55. }
  56. return $this;
  57. }
  58. public function removeUser(UserInterface $user): self
  59. {
  60. if ($this->users->contains($user)) {
  61. $this->users->removeElement($user);
  62. $user->removeNewsletter($this);
  63. }
  64. return $this;
  65. }
  66. public function getIsMain(): ?bool
  67. {
  68. return $this->isMain;
  69. }
  70. public function setIsMain(?bool $isMain): self
  71. {
  72. $this->isMain = $isMain;
  73. return $this;
  74. }
  75. }