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.

80 lines
1.5KB

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