OrganizationAddressPostal.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #[Assert\Valid]
  46. #[Groups("address")]
  47. private AddressPostal $addressPostal;
  48. #[ORM\Column(length: 255)]
  49. #[Assert\Choice(callback: ['\App\Enum\Organization\AddressPostalOrganizationTypeEnum', 'toArray'], message: 'invalid-address-postal-type')]
  50. #[Groups("address")]
  51. private string $type;
  52. public function getId(): ?int
  53. {
  54. return $this->id;
  55. }
  56. public function getOrganization(): ?Organization
  57. {
  58. return $this->organization;
  59. }
  60. public function setOrganization(Organization $organization): self
  61. {
  62. $this->organization = $organization;
  63. return $this;
  64. }
  65. public function getAddressPostal(): ?AddressPostal
  66. {
  67. return $this->addressPostal;
  68. }
  69. public function setAddressPostal(AddressPostal $addressPostal): self
  70. {
  71. $this->addressPostal = $addressPostal;
  72. return $this;
  73. }
  74. public function getType(): string
  75. {
  76. return $this->type;
  77. }
  78. public function setType(string $type): self
  79. {
  80. $this->type = $type;
  81. return $this;
  82. }
  83. }