Network.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Network;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Entity\Core\File;
  6. use App\Repository\Network\NetworkRepository;
  7. // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use JetBrains\PhpStorm\Pure;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. /**
  14. * Enum des différents réseaux auxquels peut appartenir une Organization.
  15. */
  16. #[ApiResource(operations: [])]
  17. // #[Auditable]
  18. #[ORM\Entity(repositoryClass: NetworkRepository::class)]
  19. class Network
  20. {
  21. #[ORM\Id]
  22. #[ORM\Column]
  23. #[ORM\GeneratedValue]
  24. #[Groups('network')]
  25. private ?int $id = null;
  26. #[ORM\Column(length: 255)]
  27. #[Groups('network')]
  28. private string $name;
  29. #[ORM\Column(length: 255, nullable: true)]
  30. private ?string $logo = null;
  31. #[ORM\Column(length: 255, nullable: true)]
  32. private ?string $url = null;
  33. #[ORM\OneToMany(mappedBy: 'network', targetEntity: NetworkOrganization::class, orphanRemoval: true)]
  34. private Collection $organizations;
  35. #[ORM\ManyToOne(targetEntity: File::class, cascade: [], inversedBy: 'networks')]
  36. protected File $image;
  37. #[Pure]
  38. public function __construct()
  39. {
  40. $this->organizations = new ArrayCollection();
  41. }
  42. public function setId(int $id): self
  43. {
  44. $this->id = $id;
  45. return $this;
  46. }
  47. public function getId(): ?int
  48. {
  49. return $this->id;
  50. }
  51. public function getName(): string
  52. {
  53. return $this->name;
  54. }
  55. public function setName(string $name): self
  56. {
  57. $this->name = $name;
  58. return $this;
  59. }
  60. public function getLogo(): ?string
  61. {
  62. return $this->logo;
  63. }
  64. public function setLogo(?string $logo): self
  65. {
  66. $this->logo = $logo;
  67. return $this;
  68. }
  69. public function getUrl(): ?string
  70. {
  71. return $this->url;
  72. }
  73. public function setUrl(?string $url): self
  74. {
  75. $this->url = $url;
  76. return $this;
  77. }
  78. /**
  79. * @return Collection<int, NetworkOrganization>
  80. */
  81. public function getOrganizations(): Collection
  82. {
  83. return $this->organizations;
  84. }
  85. public function addOrganization(NetworkOrganization $organization): self
  86. {
  87. if (!$this->organizations->contains($organization)) {
  88. $this->organizations[] = $organization;
  89. $organization->setNetwork($this);
  90. }
  91. return $this;
  92. }
  93. public function removeOrganization(NetworkOrganization $organization): self
  94. {
  95. if ($this->organizations->removeElement($organization)) {
  96. // set the owning side to null (unless already changed)
  97. if ($organization->getNetwork() === $this) {
  98. $organization->setNetwork(null);
  99. }
  100. }
  101. return $this;
  102. }
  103. public function getImage(): File
  104. {
  105. return $this->image;
  106. }
  107. public function setImage(File $image): self
  108. {
  109. $this->image = $image;
  110. return $this;
  111. }
  112. }