OrganizationAddressPostal.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Organization;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Core\AddressPostal;
  6. use App\Repository\Organization\OrganizationAddressPostalRepository;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ApiResource(
  11. collectionOperations: [
  12. "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW')"],
  13. "post"
  14. ],
  15. itemOperations: [
  16. "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW') and object.getOrganization().getId() == user.getOrganization().getId()"],
  17. "put" => ["security" => "object.getOrganization().getId() == user.getOrganization().getId()"],
  18. "delete" => ["security" => "object.getOrganization().getId() == user.getOrganization().getId()"],
  19. ],
  20. attributes: ["security" => "is_granted('ROLE_ORGANIZATION')"],
  21. denormalizationContext: [
  22. 'groups' => ['address'],
  23. ],
  24. normalizationContext: [
  25. 'groups' => ['address'],
  26. ],
  27. )]
  28. #[ORM\Entity(repositoryClass: OrganizationAddressPostalRepository::class)]
  29. class OrganizationAddressPostal
  30. {
  31. #[ORM\Id]
  32. #[ORM\Column]
  33. #[ORM\GeneratedValue]
  34. #[Groups("address")]
  35. private ?int $id = null;
  36. #[ORM\ManyToOne(inversedBy: 'organizationAddressPostals')]
  37. #[ORM\JoinColumn(nullable: false)]
  38. private Organization $organization;
  39. #[ORM\OneToOne(inversedBy: 'organizationAddressPostal', cascade: ['persist', 'remove'])]
  40. #[ORM\JoinColumn(nullable: false)]
  41. #[Groups("address")]
  42. private AddressPostal $addressPostal;
  43. #[ORM\Column(length: 255)]
  44. #[Assert\Choice(callback: ['\App\Enum\Organization\AddressPostalOrganizationTypeEnum', 'toArray'], message: 'invalid-address-postal-type')]
  45. #[Groups("address")]
  46. private string $type;
  47. public function getId(): ?int
  48. {
  49. return $this->id;
  50. }
  51. public function getOrganization(): ?Organization
  52. {
  53. return $this->organization;
  54. }
  55. public function setOrganization(Organization $organization): self
  56. {
  57. $this->organization = $organization;
  58. return $this;
  59. }
  60. public function getAddressPostal(): ?AddressPostal
  61. {
  62. return $this->addressPostal;
  63. }
  64. public function setAddressPostal(AddressPostal $addressPostal): self
  65. {
  66. $this->addressPostal = $addressPostal;
  67. return $this;
  68. }
  69. public function getType(): string
  70. {
  71. return $this->type;
  72. }
  73. public function setType(string $type): self
  74. {
  75. $this->type = $type;
  76. return $this;
  77. }
  78. }