OrganizationAddressPostal.php 2.8 KB

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