Organization.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Organization;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Network\NetworkOrganization;
  6. use App\Repository\Organization\OrganizationRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11. * Structure, organisation
  12. *
  13. * @ApiResource(
  14. * collectionOperations={
  15. * "get"={"security"="is_granted('ROLE_ORGANIZATION')"},
  16. * "post"={"security"="is_granted('ROLE_ORGANIZATION_CREATE')"}
  17. * },
  18. * itemOperations={
  19. * "get"={"security"="is_granted('ROLE_ORGANIZATION_EDIT') and object.getId() == user.organization.getId()"},
  20. * "put"={"security"="is_granted('ROLE_ORGANIZATION_EDIT')"}
  21. * }
  22. * )
  23. * @ORM\Entity(repositoryClass=OrganizationRepository::class)
  24. */
  25. class Organization
  26. {
  27. /**
  28. * @ORM\Id
  29. * @ORM\GeneratedValue
  30. * @ORM\Column(type="integer")
  31. */
  32. private $id;
  33. /**
  34. * @ORM\Column(type="string", length=128)
  35. */
  36. private $name;
  37. /**
  38. * @ORM\Column(type="string", length=128)
  39. */
  40. private $identifier;
  41. /**
  42. * @ORM\Column(type="string", length=255, nullable=true)
  43. */
  44. private $legalStatus;
  45. /**
  46. * @ORM\Column(type="string", length=255, nullable=true)
  47. */
  48. private $principalType;
  49. /**
  50. * @ORM\OneToOne(targetEntity=Settings::class, mappedBy="organization", cascade={"persist", "remove"})
  51. */
  52. private $settings;
  53. /**
  54. * @ORM\OneToMany(targetEntity=NetworkOrganization::class, mappedBy="organization", orphanRemoval=true)
  55. */
  56. private $networkOrganizations;
  57. /**
  58. * @ORM\OneToMany(targetEntity=NetworkOrganization::class, mappedBy="parent")
  59. */
  60. private $networkOrganizationChildren;
  61. /**
  62. * @ORM\OneToOne(targetEntity=Parameters::class, cascade={"persist", "remove"})
  63. * @ORM\JoinColumn(nullable=false)
  64. */
  65. private $parameters;
  66. public function __construct()
  67. {
  68. $this->networkOrganizations = new ArrayCollection();
  69. $this->networkOrganizationChildren = new ArrayCollection();
  70. }
  71. public function getId(): ?int
  72. {
  73. return $this->id;
  74. }
  75. public function getName(): ?string
  76. {
  77. return $this->name;
  78. }
  79. public function setName(string $name): self
  80. {
  81. $this->name = $name;
  82. return $this;
  83. }
  84. public function getIdentifier(): ?string
  85. {
  86. return $this->identifier;
  87. }
  88. public function setIdentifier(string $identifier): self
  89. {
  90. $this->identifier = $identifier;
  91. return $this;
  92. }
  93. public function getLegalStatus(): ?string
  94. {
  95. return $this->legalStatus;
  96. }
  97. public function setLegalStatus(?string $legalStatus): self
  98. {
  99. $this->legalStatus = $legalStatus;
  100. return $this;
  101. }
  102. public function getPrincipalType(): ?string
  103. {
  104. return $this->principalType;
  105. }
  106. public function setPrincipalType(?string $principalType): self
  107. {
  108. $this->principalType = $principalType;
  109. return $this;
  110. }
  111. public function getSettings(): ?Settings
  112. {
  113. return $this->settings;
  114. }
  115. public function setSettings(Settings $settings): self
  116. {
  117. // set the owning side of the relation if necessary
  118. if ($settings->getOrganization() !== $this) {
  119. $settings->setOrganization($this);
  120. }
  121. $this->settings = $settings;
  122. return $this;
  123. }
  124. /**
  125. * @return Collection|NetworkOrganization[]
  126. */
  127. public function getNetworkOrganizations(): Collection
  128. {
  129. return $this->networkOrganizations;
  130. }
  131. public function addNetworkOrganization(NetworkOrganization $networkOrganization): self
  132. {
  133. if (!$this->networkOrganizations->contains($networkOrganization)) {
  134. $this->networkOrganizations[] = $networkOrganization;
  135. $networkOrganization->setOrganization($this);
  136. }
  137. return $this;
  138. }
  139. public function removeNetworkOrganization(NetworkOrganization $networkOrganization): self
  140. {
  141. if ($this->networkOrganizations->removeElement($networkOrganization)) {
  142. // set the owning side to null (unless already changed)
  143. if ($networkOrganization->getOrganization() === $this) {
  144. $networkOrganization->setOrganization(null);
  145. }
  146. }
  147. return $this;
  148. }
  149. /**
  150. * @return Collection|NetworkOrganization[]
  151. */
  152. public function getNetworkOrganizationChildren(): Collection
  153. {
  154. return $this->networkOrganizationChildren;
  155. }
  156. public function addNetworkOrganizationChild(NetworkOrganization $networkOrganizationChild): self
  157. {
  158. if (!$this->networkOrganizationChildren->contains($networkOrganizationChild)) {
  159. $this->networkOrganizationChildren[] = $networkOrganizationChild;
  160. $networkOrganizationChild->setParent($this);
  161. }
  162. return $this;
  163. }
  164. public function removeNetworkOrganizationChild(NetworkOrganization $networkOrganizationChild): self
  165. {
  166. if ($this->networkOrganizationChildren->removeElement($networkOrganizationChild)) {
  167. // set the owning side to null (unless already changed)
  168. if ($networkOrganizationChild->getParent() === $this) {
  169. $networkOrganizationChild->setParent(null);
  170. }
  171. }
  172. return $this;
  173. }
  174. public function getParameters(): ?Parameters
  175. {
  176. return $this->parameters;
  177. }
  178. public function setParameters(Parameters $parameters): self
  179. {
  180. $this->parameters = $parameters;
  181. return $this;
  182. }
  183. }