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.

GroupUserModel.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }