vendor/roothirsch/core-bundle/Entity/Group.php line 18

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\CoreBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Roothirsch\CoreBundle\Entity\Traits\TimetrackedTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9. * Role.
  10. *
  11. * @ORM\Entity(repositoryClass="Roothirsch\CoreBundle\Repository\GroupRepository")
  12. * @ORM\Table(name="groups")
  13. * @ApiResource
  14. */
  15. class Group
  16. {
  17. use TimetrackedTrait;
  18. /**
  19. * @var integer
  20. * @ORM\Id
  21. * @ORM\GeneratedValue
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @var string
  27. *
  28. * @ORM\Column(name="name", type="string", length=191, unique=true)
  29. */
  30. private $name;
  31. /**
  32. * @ORM\Column(type="string", length=255)
  33. */
  34. private $title;
  35. /**
  36. * @var bool
  37. *
  38. * @ORM\Column(name="active", type="boolean")
  39. */
  40. private $active = true;
  41. /**
  42. * @ORM\Column(type="string", length=255)
  43. */
  44. private $type;
  45. /**
  46. * @ORM\ManyToMany(targetEntity=User::class, mappedBy="groups")
  47. */
  48. private $users;
  49. /**
  50. * @ORM\ManyToMany(targetEntity=Company::class, mappedBy="groups")
  51. */
  52. private $companies;
  53. public function __construct()
  54. {
  55. $this->users = new ArrayCollection();
  56. $this->companies = new ArrayCollection();
  57. }
  58. public function __toString()
  59. {
  60. return $this->title;
  61. }
  62. /**
  63. * Get id.
  64. *
  65. * @return string
  66. */
  67. public function getId()
  68. {
  69. return $this->id;
  70. }
  71. /**
  72. * Set name.
  73. *
  74. * @param string $name
  75. *
  76. * @return Group
  77. */
  78. public function setName($name)
  79. {
  80. $this->name = $name;
  81. return $this;
  82. }
  83. /**
  84. * Get name.
  85. *
  86. * @return string
  87. */
  88. public function getName()
  89. {
  90. return $this->name;
  91. }
  92. /**
  93. * Set active.
  94. *
  95. * @param bool $active
  96. *
  97. * @return Group
  98. */
  99. public function setActive($active)
  100. {
  101. $this->active = $active;
  102. return $this;
  103. }
  104. /**
  105. * Get active.
  106. *
  107. * @return bool
  108. */
  109. public function getActive()
  110. {
  111. return $this->active;
  112. }
  113. public function getType(): ?string
  114. {
  115. return $this->type;
  116. }
  117. public function setType(string $type): self
  118. {
  119. $this->type = $type;
  120. return $this;
  121. }
  122. /**
  123. * @return Collection|User[]
  124. */
  125. public function getUsers(): Collection
  126. {
  127. return $this->users;
  128. }
  129. public function addUser(User $user): self
  130. {
  131. if (!$this->users->contains($user)) {
  132. $this->users[] = $user;
  133. $user->addRole($this);
  134. }
  135. return $this;
  136. }
  137. public function removeUser(User $user): self
  138. {
  139. if ($this->users->removeElement($user)) {
  140. $user->removeRole($this);
  141. }
  142. return $this;
  143. }
  144. public function getTitle(): ?string
  145. {
  146. return $this->title;
  147. }
  148. public function setTitle(string $title): self
  149. {
  150. $this->title = $title;
  151. return $this;
  152. }
  153. /**
  154. * @return Collection|Company[]
  155. */
  156. public function getCompanies(): Collection
  157. {
  158. return $this->companies;
  159. }
  160. public function addCompany(Company $company): self
  161. {
  162. if (!$this->companies->contains($company)) {
  163. $this->companies[] = $company;
  164. $company->addGroup($this);
  165. }
  166. return $this;
  167. }
  168. public function removeCompany(Company $company): self
  169. {
  170. if ($this->companies->removeElement($company)) {
  171. $company->removeGroup($this);
  172. }
  173. return $this;
  174. }
  175. }