77 lines
1.9KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\Hub;
  4. use App\Entity\User;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Lc\ShopBundle\Context\FilterMerchantInterface;
  9. /**
  10. * @ORM\MappedSuperclass()
  11. */
  12. abstract class Newsletter extends AbstractDocumentEntity implements FilterMerchantInterface
  13. {
  14. /**
  15. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="newsletters")
  16. */
  17. protected $merchant;
  18. /**
  19. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\UserInterface", mappedBy="newsletters")
  20. */
  21. protected $users;
  22. public function __toString()
  23. {
  24. return $this->getTitle() ;
  25. }
  26. public function __construct()
  27. {
  28. $this->users = new ArrayCollection();
  29. }
  30. public function getMerchant(): ?Hub
  31. {
  32. return $this->merchant;
  33. }
  34. public function setMerchant(?Hub $merchant): self
  35. {
  36. $this->merchant = $merchant;
  37. return $this;
  38. }
  39. /**
  40. * @return Collection|User[]
  41. */
  42. public function getUsers(): Collection
  43. {
  44. return $this->users;
  45. }
  46. public function addUser(User $user): self
  47. {
  48. if (!$this->users->contains($user)) {
  49. $this->users[] = $user;
  50. $user->addNewsletter($this);
  51. }
  52. return $this;
  53. }
  54. public function removeUser(User $user): self
  55. {
  56. if ($this->users->contains($user)) {
  57. $this->users->removeElement($user);
  58. $user->removeNewsletter($this);
  59. }
  60. return $this;
  61. }
  62. }