OrganizationAddressPostal.php 2.7 KB

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