選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

NewsletterModel.php 1.6KB

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