src/Entity/Regate.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RegateRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use JMS\Serializer\Annotation\Expose;
  9. use JMS\Serializer\Annotation\Groups;
  10. /**
  11. * @ORM\Entity(repositoryClass=RegateRepository::class)
  12. *
  13. * @Serializer\ExclusionPolicy("ALL")
  14. */
  15. class Regate
  16. {
  17. /**
  18. * @ORM\Id
  19. * @ORM\GeneratedValue
  20. * @ORM\Column(type="integer")
  21. *
  22. * @Expose
  23. * @Groups ({
  24. * "regate:id",
  25. * "regate",
  26. * "regate-list",
  27. * "export_user_datatable",
  28. * "export_regate_datatable"
  29. * })
  30. */
  31. private ?int $id = NULL;
  32. /**
  33. * @ORM\Column(type="string", length=64)
  34. *
  35. * @Expose
  36. * @Groups ({
  37. * "regate:name",
  38. * "regate",
  39. * "user",
  40. * "regate-list",
  41. * "export_regate_datatable"
  42. * })
  43. */
  44. private ?string $name = NULL;
  45. /**
  46. * @ORM\ManyToOne(targetEntity=Regate::class, inversedBy="childs")
  47. * @ORM\JoinColumn(onDelete="CASCADE")
  48. *
  49. * @Expose
  50. * @Groups ({
  51. * "regate",
  52. * "regate-list",
  53. * "export_regate_datatable"
  54. * })
  55. */
  56. private ?Regate $parent = NULL;
  57. /**
  58. * @ORM\OneToMany(targetEntity=Regate::class, mappedBy="parent", cascade={"remove"})
  59. *
  60. * @Expose
  61. * @Groups ({
  62. * "regate:childs",
  63. * "regate",
  64. * "regate-list"
  65. * })
  66. */
  67. private Collection $childs;
  68. /**
  69. * @ORM\Column(type="text")
  70. *
  71. * @Expose
  72. * @Groups ({
  73. * "regate:affectation",
  74. * "regate",
  75. * "user",
  76. * "regate-list",
  77. * "export_user_datatable",
  78. * "export_regate_datatable"
  79. * })
  80. */
  81. private ?string $affectation = NULL;
  82. /**
  83. * @ORM\Column(type="string", length=64)
  84. *
  85. * @Expose
  86. * @Groups ({
  87. * "regate:level",
  88. * "regate",
  89. * "user",
  90. * "regate-list",
  91. * "export_regate_datatable"})
  92. */
  93. private ?string $level = NULL;
  94. /**
  95. * @ORM\OneToMany(targetEntity=User::class, mappedBy="regate")
  96. *
  97. * @Expose
  98. * @Groups ({
  99. * "regate:members",
  100. * "regate-list"
  101. * })
  102. */
  103. private Collection $members;
  104. /**
  105. * @ORM\OneToOne(targetEntity=User::class, mappedBy="responsableRegate", cascade={"persist", "remove"})
  106. */
  107. private ?User $responsable = NULL;
  108. public function __construct()
  109. {
  110. $this->childs = new ArrayCollection();
  111. $this->members = new ArrayCollection();
  112. }
  113. public function __toString()
  114. {
  115. return $this->getLevel().' : '.$this->name.' '.$this->affectation;
  116. }
  117. public function getLevel(): ?string
  118. {
  119. return $this->level;
  120. }
  121. public function setLevel(string $level): self
  122. {
  123. $this->level = $level;
  124. return $this;
  125. }
  126. /**
  127. * Permet de retourner un array avec les différents lvl attribués à la régate
  128. *
  129. * @return false|string[]
  130. */
  131. public function getLevels()
  132. {
  133. return explode(';', $this->level);
  134. }
  135. public function setLevels(array $levels): self
  136. {
  137. $this->level = implode(';', $levels);
  138. return $this;
  139. }
  140. public function getId(): ?int
  141. {
  142. return $this->id;
  143. }
  144. public function getName(): ?string
  145. {
  146. return $this->name;
  147. }
  148. public function setName(string $name): self
  149. {
  150. $this->name = $name;
  151. return $this;
  152. }
  153. /**
  154. * @return Collection|self[]
  155. */
  156. public function getChilds(): Collection
  157. {
  158. return $this->childs;
  159. }
  160. public function addChild(self $child): self
  161. {
  162. if (!$this->childs->contains($child)) {
  163. $this->childs[] = $child;
  164. $child->setParent($this);
  165. }
  166. return $this;
  167. }
  168. public function removeChild(self $child): self
  169. {
  170. if ($this->childs->removeElement($child)) {
  171. // set the owning side to null (unless already changed)
  172. if ($child->getParent() === $this) {
  173. $child->setParent(NULL);
  174. }
  175. }
  176. return $this;
  177. }
  178. public function getParent(): ?self
  179. {
  180. return $this->parent;
  181. }
  182. public function setParent(?self $parent): self
  183. {
  184. $this->parent = $parent;
  185. return $this;
  186. }
  187. public function getAffectation(): ?string
  188. {
  189. return $this->affectation;
  190. }
  191. public function setAffectation(string $affectation): self
  192. {
  193. $this->affectation = $affectation;
  194. return $this;
  195. }
  196. /**
  197. * @return Collection|User[]
  198. */
  199. public function getMembers(): Collection
  200. {
  201. return $this->members;
  202. }
  203. public function addMember(User $member): self
  204. {
  205. if (!$this->members->contains($member)) {
  206. $this->members[] = $member;
  207. $member->setRegate($this);
  208. }
  209. return $this;
  210. }
  211. public function removeMember(User $member): self
  212. {
  213. if ($this->members->removeElement($member)) {
  214. // set the owning side to null (unless already changed)
  215. if ($member->getRegate() === $this) {
  216. $member->setRegate(NULL);
  217. }
  218. }
  219. return $this;
  220. }
  221. /**
  222. * @Serializer\VirtualProperty()
  223. * @Serializer\SerializedName("get_first_parent_affectation")
  224. * @return string|null
  225. *
  226. * @Expose()
  227. * @Groups ({
  228. * "regate:get_first_parent_affectation",
  229. * "regate",
  230. * "regate-list",
  231. * "export_regate_datatable"
  232. * })
  233. */
  234. public function getFirstParentAffectation()
  235. {
  236. return $this->parent ? $this->parent->getAffectation() : '';
  237. }
  238. public function getResponsable(): ?User
  239. {
  240. return $this->responsable;
  241. }
  242. public function setResponsable(?User $responsable): self
  243. {
  244. // unset the owning side of the relation if necessary
  245. if ($responsable === NULL && $this->responsable !== NULL) {
  246. $this->responsable->setResponsableRegate(NULL);
  247. }
  248. // set the owning side of the relation if necessary
  249. if ($responsable !== NULL && $responsable->getResponsableRegate() !== $this) {
  250. $responsable->setResponsableRegate($this);
  251. }
  252. $this->responsable = $responsable;
  253. return $this;
  254. }
  255. }