NetworkOrganization.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Network;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Annotation\DateTimeConstraintAware;
  6. use App\Entity\Organization\Organization;
  7. use App\Repository\Network\NetworkOrganizationRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. /**
  11. * Fait le lien entre une Organization et un Network
  12. */
  13. #[ApiResource(
  14. collectionOperations: [
  15. "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW')"]
  16. ],
  17. itemOperations: [
  18. 'get' => [
  19. 'security' => 'is_granted("ROLE_ORGANIZATION_VIEW" and object.getOrganization().getId() == user.getOrganization().getId()'
  20. ]
  21. ],
  22. attributes: ["security" => "is_granted('ROLE_ORGANIZATION')"],
  23. normalizationContext: [
  24. 'groups' => ['network'],
  25. ]
  26. )]
  27. #[ORM\Entity(repositoryClass: NetworkOrganizationRepository::class)]
  28. #[DateTimeConstraintAware(startDateFieldName: "startDate", endDateFieldName: "endDate")]
  29. class NetworkOrganization
  30. {
  31. #[ORM\Id]
  32. #[ORM\Column]
  33. #[ORM\GeneratedValue]
  34. #[Groups("network")]
  35. private ?int $id = null;
  36. #[ORM\ManyToOne]
  37. #[ORM\JoinColumn(nullable: true)]
  38. #[Groups("network")]
  39. private Network $network;
  40. #[ORM\ManyToOne(inversedBy: 'networkOrganizations')]
  41. #[ORM\JoinColumn(nullable: true)]
  42. private Organization $organization;
  43. #[ORM\ManyToOne(inversedBy: 'networkOrganizationChildren')]
  44. private ?Organization $parent;
  45. #[ORM\Column(length: 255, nullable: true)]
  46. private ?string $leadingCause = null;
  47. #[ORM\Column(type: 'date', nullable: true)]
  48. #[Groups("network")]
  49. private ?\DateTimeInterface $startDate = null;
  50. #[ORM\Column(type: 'date', nullable: true)]
  51. private ?\DateTimeInterface $endDate = null;
  52. public function getId(): ?int
  53. {
  54. return $this->id;
  55. }
  56. public function getNetwork(): ?Network
  57. {
  58. return $this->network;
  59. }
  60. public function setNetwork(?Network $network): self
  61. {
  62. $this->network = $network;
  63. return $this;
  64. }
  65. public function getOrganization(): ?Organization
  66. {
  67. return $this->organization;
  68. }
  69. public function setOrganization(?Organization $organization): self
  70. {
  71. $this->organization = $organization;
  72. return $this;
  73. }
  74. public function getParent(): ?Organization
  75. {
  76. return $this->parent;
  77. }
  78. public function setParent(?Organization $parent): self
  79. {
  80. $this->parent = $parent;
  81. return $this;
  82. }
  83. public function getLeadingCause(): ?string
  84. {
  85. return $this->leadingCause;
  86. }
  87. public function setLeadingCause(?string $leadingCause): self
  88. {
  89. $this->leadingCause = $leadingCause;
  90. return $this;
  91. }
  92. public function getStartDate(): ?\DateTimeInterface {
  93. return $this->startDate;
  94. }
  95. public function setStartDate(?\DateTime $startDate = null): self {
  96. if($startDate == null) $startDate = new \DateTime();
  97. $this->startDate = $startDate;
  98. return $this;
  99. }
  100. public function getEndDate(): ?\DateTimeInterface {
  101. return $this->endDate;
  102. }
  103. public function setEndDate(?\DateTime $endDate = null) :self {
  104. $this->endDate = $endDate;
  105. return $this;
  106. }
  107. }