OrganizationAddressPostal.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Entity\Organization;
  4. use ApiPlatform\Metadata\Post;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Delete;
  7. use ApiPlatform\Metadata\Put;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\ApiResource;
  10. use App\Attribute\OrganizationDefaultValue;
  11. use App\Entity\Core\AddressPostal;
  12. use App\Repository\Organization\OrganizationAddressPostalRepository;
  13. //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use App\Validator\Organization as OpentalentAssert;
  18. #[ApiResource(
  19. operations: [
  20. new Get(
  21. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\') and object.getOrganization().getId() == user.getOrganization().getId()'
  22. ),
  23. new Put(
  24. security: 'object.getOrganization().getId() == user.getOrganization().getId()'
  25. ),
  26. new Delete(
  27. security: 'object.getOrganization().getId() == user.getOrganization().getId()'
  28. ),
  29. new GetCollection(
  30. security: 'is_granted(\'ROLE_ORGANIZATION_VIEW\')'
  31. ),
  32. new Post()
  33. ],
  34. normalizationContext: ['groups' => ['address']],
  35. denormalizationContext: ['groups' => ['address']],
  36. security: 'is_granted(\'ROLE_ORGANIZATION\')'
  37. )]
  38. //#[Auditable]
  39. #[ORM\Entity(repositoryClass: OrganizationAddressPostalRepository::class)]
  40. #[OrganizationDefaultValue(fieldName: "organization")]
  41. #[OpentalentAssert\OrganizationAddressPostal]
  42. class OrganizationAddressPostal
  43. {
  44. #[ORM\Id]
  45. #[ORM\Column]
  46. #[ORM\GeneratedValue]
  47. #[Groups("address")]
  48. private ?int $id = null;
  49. #[ORM\ManyToOne(inversedBy: 'organizationAddressPostals')]
  50. #[ORM\JoinColumn(nullable: false)]
  51. private Organization $organization;
  52. #[ORM\OneToOne(inversedBy: 'organizationAddressPostal', cascade: ['persist', 'remove'])]
  53. #[ORM\JoinColumn(nullable: false)]
  54. #[Assert\Valid]
  55. #[Groups("address")]
  56. private AddressPostal $addressPostal;
  57. #[ORM\Column(length: 255)]
  58. #[Assert\Choice(callback: ['\\App\\Enum\\Organization\\AddressPostalOrganizationTypeEnum', 'toArray'], message: 'invalid-address-postal-type')]
  59. #[Groups("address")]
  60. private string $type;
  61. public function getId(): ?int
  62. {
  63. return $this->id;
  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 getAddressPostal(): ?AddressPostal
  75. {
  76. return $this->addressPostal;
  77. }
  78. public function setAddressPostal(AddressPostal $addressPostal): self
  79. {
  80. $this->addressPostal = $addressPostal;
  81. return $this;
  82. }
  83. public function getType(): string
  84. {
  85. return $this->type;
  86. }
  87. public function setType(string $type): self
  88. {
  89. $this->type = $type;
  90. return $this;
  91. }
  92. }